I need help with some graphs

조회 수: 8 (최근 30일)
Francisco Ramirez
Francisco Ramirez 2019년 9월 18일
댓글: Francisco Ramirez 2019년 9월 20일
Hello!, I need help to graph this ecuations and nothing that i've found so far has helped me, any help would mean a lot
0=x^2/2 + y^2/2 + z -12.5
1 = x^2/10 + y^210 + (z-9)^2
1 = x^2/2 + y^2/2-(z-5)^2/15
1 = x^2/25 + y^2/25 + z^2/2
Thanks in advance!

답변 (1개)

David K.
David K. 2019년 9월 18일
Since you need to plot in 3 dimensions I will be using the surf function.
What I would first do is solve all of these equations in terms of z.
The first one becomes:
z = 12.5 - (x.^2)./2 - (y.^2)./2;
When you are plotting y = f(x), x is a vector, for z = f(x,y) x and y are matrices.
These can be created as such
v = linspace(-10,10,1000); % The range you wish to plot over
[x,y] = meshgrid(v);
Then, you plug in one of your z equations and plot it:
z = 12.5 - (x.^2)./2 - (y.^2)./2;
surf(x,y,z,'EdgeColor','none') % edgecolor is turned off because the meshgrid size would make it near black
When it comes to the ones where z is squared it gets a little harder. For example the second one becomes
z = sqrt(1-(x.^2)./10-(y.^2)./10)+9;
which can result in complex numbers which surf cannot plot. If you wish to ignore imaginary numbers then you can do this before you plot:
z(arrayfun(@(x) imag(x)~=0,z)) = NaN;
This will remove all elements where z has an imaginary part.
Another feature of taking the square root is that there are also negative parts if you want them calculated and plotted as such:
z = sqrt(1-(x.^2)./10-(y.^2)./10)+9;
z(arrayfun(@(x) imag(x)~=0,z)) = NaN;
surf(x,y,z,'EdgeColor','none')
hold on
z = -sqrt(1-(x.^2)./10-(y.^2)./10)+9;
z(arrayfun(@(x) imag(x)~=0,z)) = NaN;
surf(x,y,z,'EdgeColor','none')
This results in a full sphere of possible x, y and z values as such:
complex.png
  댓글 수: 1
Francisco Ramirez
Francisco Ramirez 2019년 9월 20일
Ok ok... let me try and ill let you know, thank you for the answer!

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

카테고리

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