Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
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);

Réponse acceptée

Rik
Rik le 22 Avr 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 commentaires
Star Strider
Star Strider le 22 Avr 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 le 22 Avr 2020
Modifié(e) : vipul kumar le 22 Avr 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by