How to correct matrix dimension disagree error
Show older comments
figure
clear;
clc;
v = 1.0;
n=[0.00 0.10 0.12 0.18];
u = linspace(0,2);
%%
for i = 1:length(n)
sigma = ((1i.*u-1-v.^2)./(v.^2-u.^2 +1-2i.*u)).*(1./(v.^2 +1));
sigmapri = n*((1i.*u-1-v.^2)./((1+n).^2 +v.^2).*(v.^2-u.^2 +1-2i.*u)).*(1-(v./(v.^2 +1)));
w = sigma + sigmapri;
plot(u, real(w))
end
%%
xlabel('\omega*\tau')
ylabel('\sigma(\omega)/\sigma_o')
4 Comments
David Hill
on 28 Mar 2020
What is 1i and 2i? You will need to make the size of n and the size of u the same. Can n be linspace(0,.18)?
the cyclist
on 28 Mar 2020
1i and 2i are just the imaginary constants sqrt(-1) and 2*sqrt(-1), so should not be problematic here.
Samuel Suakye
on 28 Mar 2020
Samuel Suakye
on 28 Mar 2020
Accepted Answer
More Answers (1)
the cyclist
on 28 Mar 2020
You are effectively trying to do this operation in your code:
n * u
where n is a 1x4 matrix, and u is a 1x100 matrix.
That won't work, as either a matrix multiplication or as an element-by-element multiplication. What do you expect from that?
1 Comment
Samuel Suakye
on 28 Mar 2020
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!