Matlab generating parametric curves

In summary, the parametric curve generated by the code you have provided is not what it is supposed to look like. You may want to try using different equations or different step sizes when graphing the data.
  • #1
roam
1,271
12
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:

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(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.
 
Physics news on Phys.org
  • #2
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)
 
  • #3
Well, the curve I'm trying to produce is supposed to look like this:

http://img42.imageshack.us/img42/6738/81320578.jpg

But when I even use this code:

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:

http://img192.imageshack.us/img192/258/34220467.jpg

I can't see the problem. :confused:
 
Last edited by a moderator:
  • #4
roam said:
Well, the curve I'm trying to produce is supposed to look like this:

http://img42.imageshack.us/img42/6738/81320578.jpg

But when I even use this code:

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:

http://img192.imageshack.us/img192/258/34220467.jpg

I can't see the problem. :confused:

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/helpdesk/help/techdoc/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.
 
Last edited by a moderator:
  • #5
roam said:
I can't see the problem. :confused:

As MatlabDude has already pointed out, the problem lies with the parametric equations you're using. For example, the following equivalent Mathematica code

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


http://img704.imageshack.us/img704/9525/35090886.jpg

On the other hand, the modified parametric equations

Code:
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:

http://img63.imageshack.us/img63/5083/26807336.jpg
 
Last edited by a moderator:
  • #6
Okay thanks A LOT guys. :)
 
  • #7
By the way, when you are ploting this in Mathematica, what is the code for changing the color of the plot?
 

1. What is Matlab and how is it used to generate parametric curves?

Matlab is a numerical computing software commonly used in scientific and engineering fields. It allows users to perform various mathematical operations, plot graphs and generate data visualizations. To generate parametric curves in Matlab, users can input equations that define the x and y coordinates of the curve based on a given parameter. The software then generates a plot of the curve based on the specified parameter range.

2. Can Matlab generate different types of parametric curves?

Yes, Matlab has the capability to generate various types of parametric curves such as circles, ellipses, spirals, and more complex curves. Users can input different equations and parameters to create the desired type of curve.

3. How accurate are the parametric curves generated by Matlab?

The accuracy of the parametric curves generated by Matlab depends on the precision of the input equations and parameters. If the equations are defined accurately and the parameters are chosen carefully, the generated curves can be highly accurate. However, rounding errors or imprecise equations can affect the accuracy of the curves.

4. Is it possible to animate parametric curves in Matlab?

Yes, it is possible to animate parametric curves in Matlab. Users can specify a range of values for the parameter and use a loop to update the curve at each step, creating the illusion of movement. This can be useful for visualizing dynamic systems or illustrating mathematical concepts.

5. Can Matlab generate 3D parametric curves?

Yes, Matlab has the capability to generate 3D parametric curves. Users can input equations that define the x, y, and z coordinates of the curve based on a given parameter. The software then generates a 3D plot of the curve based on the specified parameter range. This can be useful for visualizing complex surfaces or trajectories in 3D space.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
993
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
Back
Top