How to plot a quadratic equation?

조회 수: 53 (최근 30일)
Loris Chavée
Loris Chavée 2017년 2월 9일
댓글: Loris Chavée 2017년 2월 10일
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