1
votes

I am using the following equation in Matlab:

k=10e-10:0.01:1.5;
Ck2=(0.5*((i*k+0.135)*(i*k+0.651)))./((i*k+0.0965)*(i*k+0.4555));
plot(k,imag(Ck2));
plot(k,real(Ck2));

I did not define "i" so MATLAB assumes is an imaginary number in my equation as expected. I am trying to plot the real & imaginary parts of the equation against the range of k.

I am getting an error saying: Inner matrix dimensions must agree. I already tried to use the "." operator before the multiplication operator to multiply each element but I didn't succeed. Any help would be appreciated it.

Thank you in advanced.

1
You should try .*? - fileyfood500
I tried that and did not work. It says "Unexpected MATLAB operator" - Jesus
Hmm I will test, are you putting it where I put it in the solution? - fileyfood500
It is working correctly for me, have you written it as I have below? - fileyfood500
@fileyfood500 It works now! Thank you. I will accept the solution :) - Jesus

1 Answers

1
votes

Since k is a vector, when you multiply k * k, you are multiply 2 vectors using matrix multiplication. With matrix multiplication, you multiply an j x k size matrix by a k x l size matrix, and get a j x l result.

But here you are multiplying 1 x 150 by 1 x 150, so the dimensions don't line up for proper matrix multiplication. Instead, using .* will perform pairwise multiplication between each of the elements.

Try this:

k = 10e-10:0.01:1.5;  % 1 x 150 length vector
Ck2= (0.5*((i*k+0.135) .* (i*k+0.651))) ./ ((i*k+0.0965) .* (i*k+0.4555));