
Trying To Plot a 3D shape
8 ビュー (過去 30 日間)
古いコメントを表示

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)

0 件のコメント
採用された回答
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 件のコメント
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!