Trying To Plot a 3D shape

8 Ansichten (letzte 30 Tage)
Lucas Clark
Lucas Clark am 11 Mär. 2019
Kommentiert: Star Strider am 11 Mär. 2019
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)

Akzeptierte Antwort

Star Strider
Star Strider am 11 Mär. 2019
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 Kommentare
Lucas Clark
Lucas Clark am 11 Mär. 2019
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 am 11 Mär. 2019
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by