Effacer les filtres
Effacer les filtres

linspace error while trying to plot

3 vues (au cours des 30 derniers jours)
fartash2020
fartash2020 le 30 Nov 2017
Commenté : Walter Roberson le 30 Nov 2017
Dear all,
I have written a code for linspace I want a 3D plot of it:
% First we set the constants:
kd=6;
lambda= 0.01;
Delta_E=0.02;
% Then we write down the Formulas:
z=linspace(-1,1,200);
kappa=linspace(0,1,200);
q=((Delta_E)+(lambda.*z)+(((sqrt((1+z)./2)).*exp(-(kd.*(sqrt(2.*lambda'.*(1+z))))))).*(kappa.*(sqrt((1-z)./(1+z)))-(sqrt((1+z)./(1-z )))));
% Now we plot q(Z,kappa) vs Z and kappa :
figure(1)
mesh(z,kappa,q)
% title('kd=6');
xlabel('Z');
ylabel('lambda');
zlabel('q)');
I think that my "q" must have 200*200 matrix, but it is not. Its gives just 1*200.
I would highly appreciate if you help me.
Thanks,

Réponse acceptée

Walter Roberson
Walter Roberson le 30 Nov 2017
Change
z=linspace(-1,1,200);
kappa=linspace(0,1,200);
to
Z = linspace(-1,1,200);
KAPPA = linspace(0,1,200);
[z, kappa] = meshgrid(Z, KAPPA);
Note: you have
ylabel('lambda');
which is not correct. Your lambda is a constant. Your y axes is kappa, not lambda.
  2 commentaires
fartash2020
fartash2020 le 30 Nov 2017
Modifié(e) : Walter Roberson le 30 Nov 2017
Dear Walter,
Thank you very much for your answer. Also, I want to plot Z vs kappa for the time that q=0. in 2D of course.
Best Regards,
Walter Roberson
Walter Roberson le 30 Nov 2017
contour(z, kappa, q, [0 0])
the [0 0] is a trick that has to be used when you are only asking for one contour value; if you were to try to pass in the scalar 0 at that point, it would try to interpret the scalar 0 as the number of contour levels to draw.

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