MATLAB: I really want to draw the precession of mercury

geometry

clc;clear all;
a=10;
b=5;
lambda=.5;
v1=1/20;
v2=3;
t=0:.1:40;
x(t)=a.^2+b.^2 +a*cos(2*pi*v1*t)*cos(2*pi*v2*t)-lambda*b*sin(2*pi*v1*t)*sin(2*pi*v2*t);
y(t)=a.^2+b.^2 +a*sin(2*pi*v1*t)*cos(2*pi*v2*t)-lambda.*b*cos(2*pi*v1*t)*sin(2*pi*v2*t);
plot(x(t),y(t))
This is my program. but it's not running cause there is a dimension mismatch. can anybody tell me what did i do wrong?

Best Answer

As the error message says
x(t)
is only valid if t is a real positive integer.
The simplest way to solve your problem is to get rid of the indexing of x and y which is completely meaningless
x = a^2 + b^2 + a*cos(2*pi*v1*t) .* cos(2*pi*v2*t) - ...
y = a^2 + b^2 + ...
plot(x, y)
Related Question