How can I draw this ellipse on MatLab

50 views (last 30 days)
I need to draw this ellipse on Matlab and i can't. My problem seems to be with the plus-minus symbol.
I don't know how to set my axis to get my ellipse right in the middle of my graph !?
It need to be in :
Y = (0:10)
X = (0:8)
This is what i've done so far :
x=0:0.001:8;
y= (((5*(4+-sqrt(8*x-x.^2)))/4));
plot(x,y);
grid on;
I'm using Matlab R2013a
From a student who need your help please !!!!!!
PS : sorry for the silly mistakes, i'm not an anglophone !!
  1 Comment
per isakson
per isakson on 15 Feb 2014
Edited: per isakson on 15 Feb 2014
Your code produces half an ellipse.
Matlab doesn't interpret +-sqrt the way you intend.
You can make it two cases and finally concatenate them.

Sign in to comment.

Accepted Answer

Roger Stafford
Roger Stafford on 15 Feb 2014
It's easiest to generate an ellipse parametrically. I deduce from your equation for y that the ellipse's equation is:
(x-4)^2/4^2 + (y-5)^2/5^2 = 1
This can be represented parametrically using the parameter t by:
t = linspace(0,2*pi);
x = 4 + 4*cos(t);
y = 5 + 5*sin(t);
plot(x,y)
axis equal
  1 Comment
Image Analyst
Image Analyst on 16 Feb 2014
Mathieu, see the FAQ : http://matlab.wikia.com/wiki/FAQ#How_do_I_create_an_ellipse.3F (essentially the same as Roger's code, but there's other good stuff in there that you may like to see and you may benefit from).

Sign in to comment.

More Answers (1)

Mathieu Bouchard
Mathieu Bouchard on 16 Feb 2014
Thank you Roger Stafford !!!!
This is exactly what I needed !
Isakson : that was my problem but i'm new on matlab and I don't know all the function of it and how to dot it !

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!