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

1 次查看(过去 30 天)
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);

采纳的回答

Rik
Rik 2020-4-22
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 个评论
Star Strider
Star Strider 2020-4-22
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 2020-4-22
编辑:vipul kumar 2020-4-22
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Assumptions 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by