Plotting a parametric curve in Matlab..(Dimension error)

4 views (last 30 days)
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

Accepted Answer

Star Strider
Star Strider on 29 May 2020
Edited: Star Strider on 29 May 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.')
.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!