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
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
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!