Plotting ellipses with parametric curves
293 views (last 30 days)
Show older comments
Szabolcs Simon-Guth
on 9 Nov 2021
Commented: Szabolcs Simon-Guth
on 9 Nov 2021
Hi all!
I need to plot the following ellipses on the same plot:
Ellips 1:
Ellipse 2:
I have substituted the formula for the second ellipse by u and v:
u =
v =
Ellipse 2:
I have used the following parametrisation:
For an ellipse with the general fomula
the parametrization: and
So, I have rearranged the equation of both ellipses to fit the general formula and then calculated a and b according the get the parametrization above. I was supposed to get the following plot:
Instead I have got this:
I have written the following code:
% First ellipse
t = linspace(0,2*pi,200);
a = sqrt(2);
b = sqrt(2/3);
x = a.*cos(t);
y = b.*sin(t);
plot(((1/2)*(x.^2)), ((3/2).*(y.^2)), '-k', 'LineWidth', 1.5)
axis equal
hold on
% Second ellipse
t = linspace(0,2*pi,200);
a = 2;
b = 1;
x = (-a/3).*(cos(t)+((-2*b/3).*sin(t)));
y = (((2*a/3).*cos(t))+((7*b/3).*sin(t)));
u = x-(2.*y);
v = (2.*x)+y;
plot(((1/4).*(u.^2)), ((v.^2)), '-k', 'LineWidth', 1.5)
axis equal
hold off
What is it that I'm doing wrong? I am very thankful for all the help in advance!
0 Comments
Accepted Answer
Chunru
on 9 Nov 2021
% First ellipse
t = linspace(0,2*pi,200);
a = sqrt(2);
b = sqrt(2/3);
x = a.*cos(t);
y = b.*sin(t);
%plot(((1/2)*(x.^2)), ((3/2).*(y.^2)), '-k', 'LineWidth', 1.5)
plot(x, y, '-k', 'LineWidth', 1.5)
axis equal
hold on
% Second ellipse
t = linspace(0,2*pi,200);
a = 2;
b = 1;
u = a.*cos(t);
v = b.*sin(t);
xy= ([1 -2; 2 1])\[u; v]; % since [u; v] = [1 -2; 2 1][x; y]
x = xy(1, :);
y = xy(2, :);
%plot(((1/4).*(u.^2)), ((v.^2)), '-g', 'LineWidth', 1.5)
plot(x, y, '-g', 'LineWidth', 1.5)
axis equal
hold off
More Answers (0)
See Also
Categories
Find more on Annotations 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!