필터 지우기
필터 지우기

linspace error while trying to plot

조회 수: 3 (최근 30일)
fartash2020
fartash2020 2017년 11월 30일
댓글: Walter Roberson 2017년 11월 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