Plotting ellipses with parametric curves
83 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Szabolcs Simon-Guth
le 9 Nov 2021
Commenté : Szabolcs Simon-Guth
le 9 Nov 2021
Hi all!
I need to plot the following ellipses on the same plot:
Ellips 1: ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/795159/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/795159/image.png)
Ellipse 2: ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/795164/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/795164/image.png)
I have substituted the formula for the second ellipse by u and v:
u = ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/795169/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/795169/image.png)
v = ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/795174/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/795174/image.png)
Ellipse 2: ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/795179/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/795179/image.png)
I have used the following parametrisation:
For an ellipse with the general fomula ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/795184/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/795184/image.png)
the parametrization:
and ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/795194/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/795189/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/795194/image.png)
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/795199/image.png)
Instead I have got this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/795204/image.png)
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 commentaires
Réponse acceptée
Chunru
le 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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!