Clear Filters
Clear Filters

am trying to plot P and Q but the matrix dimensions seems to disagree with me.

1 view (last 30 days)
clc
clf
qmod = @(a) abs((k*exp(-2*(-(a + k)*(a - k))^(1/2))*(a/k - ((-(a + k)*(a - k))^(1/2)*1i)/k)*1i)/(exp(-2*(-(a + k)*(a - k))^(1/2))*(-(a + k)*(a - k))^(1/2) + exp(2*(-(a + k)*(a - k))^(1/2))*(-(a + k)*(a - k))^(1/2) + a*exp(-2*(-(a + k)*(a - k))^(1/2))*1i - a*exp(2*(-(a + k)*(a - k))^(1/2))*1i) + (k*exp(2*(-(a + k)*(a - k))^(1/2))*(a/k + ((-(a + k)*(a - k))^(1/2)*1i)/k))/(exp(-2*(-(a + k)*(a - k))^(1/2))*(-(a + k)*(a - k))^(1/2)*1i + exp(2*(-(a + k)*(a - k))^(1/2))*(-(a + k)*(a - k))^(1/2)*1i - a*exp(-2*(-(a + k)*(a - k))^(1/2)) + a*exp(2*(-(a + k)*(a - k))^(1/2))))^2/abs((k*exp(-2*(-(a + k)*(a - k))^(1/2))*1i)/(exp(-2*(-(a + k)*(a - k))^(1/2))*(-(a + k)*(a - k))^(1/2) + exp(2*(-(a + k)*(a - k))^(1/2))*(-(a + k)*(a - k))^(1/2) + a*exp(-2*(-(a + k)*(a - k))^(1/2))*1i - a*exp(2*(-(a + k)*(a - k))^(1/2))*1i) + (k*exp(2*(-(a + k)*(a - k))^(1/2)))/(a*exp(2*(-(a + k)*(a - k))^(1/2)) - a*exp(-2*(-(a + k)*(a - k))^(1/2)) + exp(-2*(-(a + k)*(a - k))^(1/2))*(-(a + k)*(a - k))^(1/2)*1i + exp(2*(-(a + k)*(a - k))^(1/2))*(-(a + k)*(a - k))^(1/2)*1i))^2
normwave = @(a) 1/(1+(2.*a./31400))
a=linspace(0.1,1);
P=normwave(a);
Q=qmod(a);

Accepted Answer

Rik
Rik on 22 Apr 2020
Somewhere in that humongous anonymous function you have made a mistake.
In this case the mistake is that you didn't use array operations, so all those products, powers and divisions are matrix operations.
Try to split qmod over multiple lines is segments that make sense. You could even consider writing the parts as separate anonymous functions. Then make sure to change matrix operations to array operations (replace * by .* etc).
  10 Comments
Star Strider
Star Strider on 22 Apr 2020
It defines the function handle for you. (Run those lines and then look at the results in your Command Window.) You only need to provide all the arguments.
Is there still a problelm in the functions produced by matlabFunction? (It specifies array operations, not matrix operations.) If so, it may be necessary to edit those functions to do matrix operations if those are what you want to do. That simply involves removing the dot operators from those operations, so multiplication becomes * rather than .*. You also need to be certain that the matrix sizes are conformable to the operations you want to do.
vipul kumar
vipul kumar on 22 Apr 2020
Edited: vipul kumar on 22 Apr 2020
Yes that editing i did by replacing all '*' by '.*' and rik provided a much shorter method. But i could not obtain a plot P vs Q (ref is in the comments). P.S total noobie to programming.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!