Trying To Plot a 3D shape

조회 수: 9 (최근 30일)
Lucas Clark
Lucas Clark 2019년 3월 11일
댓글: Star Strider 2019년 3월 11일
I want to create the above 3D shape using the given integral bounds. I want to use the bounds to create the shape in matlab.
I've already written a few lines and created the figure below. I don't know why it's showing me just a line.
What other peice of information am I missing?
Thank you.
clear, clc
x = [0:.01:1];
xx = meshgrid(x);
zz = 1 - xx.^2;
yy = 1 - xx;
surf(xx,yy,zz)

채택된 답변

Star Strider
Star Strider 2019년 3월 11일
You need a second output from meshgrid in order to plot ‘yy’ correctly.
Try this:
x = 0:0.01:1;
[xx1,xx2] = meshgrid(x);
zz = 1 - xx1.^2;
yy = 1 - xx2;
zzc = zz.*(xx1 <= xx2);
mesh(xx1, yy, zzc)
xlabel('X')
ylabel('Y')
view(125, 30)
producing:
Experiment to get the result you want.
  댓글 수: 2
Lucas Clark
Lucas Clark 2019년 3월 11일
Thank you for the help!!
I'll tinker with it some more, I need a better understanding of mesh grid.
What is the reasoning behind this line of code? (5th line down):
zzc = zz.*(xx1 <= xx2)
Thank you again.
Star Strider
Star Strider 2019년 3월 11일
As always, my pleasure!
The ‘zzc’ assignment is a way of forcing the linear relation of ‘yy’.
An alternative is:
x = 0:0.01:1;
[xx1,xx2] = ndgrid(x);
zz = 1 - xx1.^2;
yy = 1 - xx1;
zzc = zz.*(yy >= xx2);
mesh(xx2, yy, zzc)
xlabel('Y')
ylabel('X')
view(25, 30)
with the axis labels reversed because ndgrid produces different results than meshgrid.
This actually makes more sense. (It took a while to get as far as I did, since your assignment and the meshgrid output are not compatible. The ndgrid result and the calculations using it are more logical.) The plot is essentially the same, so I am not re-posting it here.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by