I need help with some graphs

8 visualizzazioni (ultimi 30 giorni)
Francisco Ramirez
Francisco Ramirez il 18 Set 2019
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!

Risposte (1)

David K.
David K. il 18 Set 2019
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 Commento
Francisco Ramirez
Francisco Ramirez il 20 Set 2019
Ok ok... let me try and ill let you know, thank you for the answer!

Accedi per commentare.

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by