I'd like to plot f(u,v) = (u,v,sqrt(1-u^2-v^2)) whereas u^2+v^2 <1;
I thought of using plot3 and defining
[u,v] = deal(linspace(-2,2,200));
Thing is, I got to incorporate the implicit condition somehow. Fimplicit3 doesn't help here. I could probalby solve for one of the variables and substitute but that's getting already complex in my head. Is there a handy solution?

 채택된 답변

DGM
DGM 2021년 4월 27일

2 개 추천

Maybe something like this?
n = 50;
u = linspace(-2,2,n);
v = linspace(-2,2,n)';
f = u.^2 - v.^2; % the function
dm = (u.^2 + v.^2)<1; % the domain mask
f(~dm) = NaN; % NaN values don't plot
mesh(u,v,f)
axis equal
colormap(1-ccmap)
title('Math Pringle')

댓글 수: 5

Niklas Kurz
Niklas Kurz 2021년 4월 28일
편집: Niklas Kurz 2021년 4월 28일
Intersting looking graph, but I wonder how u plottet it with me mistakening the function: it's f = (u,v,sqrt(1-u^2-v^2)). Following your steps I'm also getting a wrong result: Z must be a matrix:
u = linspace(-2,2,50);
v = linspace(-2,2,50);
w = sqrt((1-u.^2-v.^2));
dm = (u.^2-v.^2)<1;
w(~dm) = NaN
mesh(u,v,w)
Error using mesh.
Therefore
plot3(u,v,w)
Gives surprisingly an idea of how it should actually look like. Sadly it just plots a line and not a surface.
DGM
DGM 2021년 4월 28일
n = 50;
u = linspace(-2,2,n);
v = linspace(-2,2,n)';
f = 1 - u.^2 - v.^2; % the function
dm = (u.^2 - v.^2)<1; % the domain mask
f(~dm) = NaN; % NaN values don't plot
mesh(u,v,f)
In order for that to work, the u,v vectors need to be orthogonal (note that v is transposed). It's also possible to use meshgrid to do the same thing:
n = 50;
u = linspace(-2,2,n);
v = linspace(-2,2,n)';
[u v] = meshgrid(u,v);
f = 1 - u.^2 - v.^2; % the function
dm = (u.^2 - v.^2)<1; % the domain mask
f(~dm) = NaN; % NaN values don't plot
mesh(u,v,f)
Niklas Kurz
Niklas Kurz 2021년 4월 28일
편집: Niklas Kurz 2021년 4월 28일
Thanks, this leads to the right solution (That transpose sign really is sneaky). Additionally it's
f = real(sqrt(1-u.^2-v.^2))
in order to receive a beautiful hemisphere. Well, u made the principle clear.
While I reconsider: why actually that transposing/ orthogonal condition? I never had to for plotting 3d-surfaces
DGM
DGM 2021년 4월 28일
편집: DGM 2021년 4월 28일
It's easier to understand once you realize what the results from meshgrid look like. Two orthogonal vectors contain the same information that two 2D grids do. The grids are just replicated vectors.
Another way to think of it is to consider what happens when the vectors aren't orthogonal:
x = linspace(-1,1,10);
y = linspace(-1,1,10);
z1 = x.^2 + y.^2; % this is a vector
z2 = x.^2 + y'.^2; % this is a 2D array (due to implicit array expansion)
These two results are related, but it all depends what the goal is. Both z1 and z2 describe a paraboloid. z2 describes the paraboloid over the entire rectangular domain from [-1,-1] to [1,1]. z1 only describes the paraboloid on the diagonal line between said points. One is a surface, where the other is only a curve on said surface.
Niklas Kurz
Niklas Kurz 2021년 4월 29일
편집: Niklas Kurz 2021년 5월 2일
that illustration was beautiful

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

태그

질문:

2021년 4월 27일

편집:

2021년 5월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by