Plotting a parametric curve in Matlab..(Dimension error)
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Youngrok Lee
am 29 Mai 2020
Bearbeitet: Star Strider
am 29 Mai 2020
Hey all, i'm trying to plot the contours of constant e=0, 0.1, 0.2, 0.3 and 0.4 using the parametric expression of
x=e*cos(theta)/sqrt(4/3+4/3*cos(theta)*sin(theta) , y=e*sin(theta)/sqrt(4/3+4/3*cos(theta)*sin(theta))
---------------------------------------------------------------------------------------------------------------------------------------
I tried it like this, but got errors on dimension.
When i tried on ,for example, e=0.1 case,
theta=0:0.1:(2*pi);
e=0.1;
x=e*cos(theta)/sqrt(4/3+4/3*cos(theta)*sin(theta));
y=e*sin(theta)/sqrt(4/3+4/3*cos(theta)*sin(theta));
plot(x,y)
then, i got error message about dimension errors in matrix multiplication. Could you help me on this ?
and my last question is, Is there a way to change only the e-values and show them all in one picture?
Thank you
0 Kommentare
Akzeptierte Antwort
Star Strider
am 29 Mai 2020
Bearbeitet: Star Strider
am 29 Mai 2020
Use element-wise operations (the ‘dot operator’):
x=e*cos(theta)./sqrt(4/3+4/3*cos(theta).*sin(theta));
y=e*sin(theta)./sqrt(4/3+4/3*cos(theta).*sin(theta));
That worked when I ran it.
EDIT —
You can plot them all at the same time (without loops) by using matrix operations as well as element-wise (array) operations:
theta=0:0.1:(2*pi);
e=[0.1; 0.2; 0.3; 0.4];
x=e*cos(theta)./sqrt(4/3+4/3*cos(theta).*sin(theta));
y=e*sin(theta)./sqrt(4/3+4/3*cos(theta).*sin(theta));
plot(x.',y.')
.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!