How to plot a quadratic equation?

49 次查看(过去 30 天)
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!

采纳的回答

John Chilleri
John Chilleri 2017-2-9
编辑:John Chilleri 2017-2-9
Hello,
If you have a newer release of Matlab (I believe R2016b), you can use the new fimplicit3 function,
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 个评论
John Chilleri
John Chilleri 2017-2-9
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.
Loris Chavée
Loris Chavée 2017-2-10
Thanks for your help! It Will probably help me to pass my analytic geometry exam.

请先登录,再进行评论。

更多回答(1 个)

John D'Errico
John D'Errico 2017-2-9
编辑:John D'Errico 2017-2-9
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.

类别

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