I need help with some graphs

7 ビュー (過去 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 Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by