Matlab generating parametric curves


by roam
Tags: curves, generating, matlab, parametric
roam
roam is offline
#1
Jan14-10, 05:04 PM
P: 884
I want to graph the following parametric curve using matlab:

x = 31cos(t)-7cos(31/7)t
y = 31sin(t)-7sin(31/7)t

0 ≤ t ≤ 14π

This is the code I used:

syms t
t=[0:1:19*pi]
x=31*cos(t)-7*cos(31/7)*t;
y=31*sin(t)-7*sin(31/7)*t;
plot(t,y,t,x)
But the graph which Matlab generated is very different from what it's supposed to look like. Is there a problem with my codes? How do we graph this parametric curve (it's a complex curve)? Thanks.
Phys.Org News Partner Science news on Phys.org
NASA's space station Robonaut finally getting legs
Free the seed: OSSI nurtures growing plants without patent barriers
Going nuts? Turkey looks to pistachios to heat new eco-city
MATLABdude
MATLABdude is offline
#2
Jan15-10, 04:07 AM
Sci Advisor
P: 1,724
When you use a (2D) parametric equation, you don't express x or y in terms of each other, you do it in terms of a third variable (as you've done). However, at the end of the day, you should still have a set of X-Y coordinates.

Instead of plotting x as a function of t, and then plotting y as a function of t (as you're doing), just plot y as a function of x:
>> plot(x, y)
roam
roam is offline
#3
Jan15-10, 02:13 PM
P: 884
Well, the curve I'm trying to produce is supposed to look like this:



But when I even use this code:

syms t
t=[0:1:19*pi]
x=31*cos(t)-7*cos(31/7)*t;
y=31*sin(t)-7*sin(31/7)*t;
plot(x, y)
I get this graph:



I can't see the problem.

MATLABdude
MATLABdude is offline
#4
Jan15-10, 02:27 PM
Sci Advisor
P: 1,724

Matlab generating parametric curves


Quote Quote by roam View Post
Well, the curve I'm trying to produce is supposed to look like this:



But when I even use this code:

syms t
t=[0:1:19*pi]
x=31*cos(t)-7*cos(31/7)*t;
y=31*sin(t)-7*sin(31/7)*t;
plot(x, y)
I get this graph:



I can't see the problem.
Are you sure of your equations? I Googled for parametric spirograph equation and got the following webpage:
http://linuxgazette.net/133/luana.html

You may want to try again with:
x=31*cos(t) - 7*cos((31/7)*t);
y=31*sin(t) - 7*sin((31/7)*t);

I don't know if you know about the MATLAB axis command, but you can use it (or rather 'axis square') to have equal scaling on both axes:
http://www.mathworks.com/access/help.../ref/axis.html

EDIT: You may also wish to use a smaller step size for t, say 0.1 or 0.01 instead of 1, as you currently have it.
shoehorn
shoehorn is offline
#5
Jan15-10, 03:25 PM
P: 448
Quote Quote by roam View Post
I can't see the problem.
As MatlabDude has already pointed out, the problem lies with the parametric equations you're using. For example, the following equivalent Mathematica code

x[t_] := 31 Cos[t] - 7 Cos[31/7] t;
y[t_] := 31 Sin[t] - 7 Sin[31/7] t;
ParametricPlot[{x[t], y[t]}, {t, 0, 19 \[Pi]}]
gives the parametric plot




On the other hand, the modified parametric equations

x[t_] := 31 Cos[t] - 7 Cos[31 t/7];
y[t_] := 31 Sin[t] - 7 Sin[31 t/7];
ParametricPlot[{x[t], y[t]}, {t, 0, 19 \[Pi]}]
give you the desired plot:

roam
roam is offline
#6
Jan15-10, 05:22 PM
P: 884
Okay thanks A LOT guys. :)
roam
roam is offline
#7
Jan15-10, 07:02 PM
P: 884
By the way, when you are ploting this in Mathematica, what is the code for changing the color of the plot?


Register to reply

Related Discussions
Parametric curves Calculus & Beyond Homework 13
Parametric curves applications Calculus & Beyond Homework 5
Parametric Curves Calculus 0
Parametric Curves..HELP!!! Introductory Physics Homework 2