How to plot a quadratic equation?
26 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Loris Chavée
le 9 Fév 2017
Commenté : Loris Chavée
le 10 Fév 2017
Hello everybody!
I've been struggling with this for a while and I don't know how to do that..
I would like to plot this: x²+y²+z²-2xy-4x+4y-1=0
thanks for your help!
0 commentaires
Réponse acceptée
John Chilleri
le 9 Fév 2017
Modifié(e) : John Chilleri
le 9 Fév 2017
Hello,
fimplicit3(@(x,y,z) x.^2+y.^2+z.^2-2*x.*y-4*x+4*y-1)
which will default to plotting on the interval [-5,5] (for all axes) but you can change this interval with the second input argument.
Hope this helps!
3 commentaires
John Chilleri
le 9 Fév 2017
Noted - I don't have R2016b, so I wasn't able to test it, but thank you, I'll change my answer!
Also, I just remembered how I learned of this - you can see a similar question and answer here provided by Benjamin Kraus.
Plus de réponses (1)
John D'Errico
le 9 Fév 2017
Modifié(e) : John D'Errico
le 9 Fév 2017
It is not a quadratic equation in the classic use of that phrase. It is the implicit equation of a conic form in 3 three dimensions. The only thing quadratic about it is that there are squares of the variables in it.
I'll give you a hint though;
Can you isolate z easily?
z^2 = -x^2 - y^2 + 2*x*y + 4*x - 4*y + 1
If you take the sqrt, then there are TWO solutions. So, use meshgrid to generate a set (grid) of values for x and y.
Then compute the TWO possible values for z. for ANY value of x and y. For some of those combinations of x and y, there may be no real solution of course. But that is ok.
Use surf to plot the two surfaces created from those two branches of the sqrt. (Use hold on in between the calls to surf, to overlay the two surfaces in one plot.)
Really pretty easy. Looks like 6 lines of code. If you want to be more intelligent about it, you can use a little high school math to determine the intrinsic shape of that conic form in advance. That might give you a set of intelligent limits on x and y to put into meshgrid.
If you wanted to be REALLY lazy, you might see how the isosurface tool would give you the desired manifold directly. Well, it would take some work with meshgrid again.
0 commentaires
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!