linspace error while trying to plot

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

采纳的回答

Walter Roberson
Walter Roberson 2017-11-30
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 个评论
fartash2020
fartash2020 2017-11-30
编辑:Walter Roberson 2017-11-30
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 2017-11-30
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by