How to plot a quadratic equation?
49 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Loris Chavée
el 9 de Feb. de 2017
Comentada: Loris Chavée
el 10 de Feb. de 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 comentarios
Respuesta aceptada
John Chilleri
el 9 de Feb. de 2017
Editada: John Chilleri
el 9 de Feb. de 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 comentarios
John Chilleri
el 9 de Feb. de 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.
Más respuestas (1)
John D'Errico
el 9 de Feb. de 2017
Editada: John D'Errico
el 9 de Feb. de 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 comentarios
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!