Morge
Morge

Reputation: 17

"Linear Model" of a Pendulum via Euler's Method in MATLAB

In my problem the linear modal is defined as the first term in the series expansion of sin(x) so:

sin(x) = x is the linear modal.

So with this, I then have to write

as a system of x' and y', so:

I tried the linear modal in Euler's method, with initial conditions X(1) = 1 and V(1)=0 (V would be y then following the last equations):

for i = 1:1000
    V(i+1) = V(i)-(1.*s) ;
    X(i+1) = V(i);
end 

Where s is the step size. But apparently I'm supposed to get a circle when I plot V with respect to X which makes sense, but all I get is a straight line.

If I change it to:

for i = 1:1000
    V(i+1) = V(i)-(X(i).*s) ;
    X(i+1) = V(i);
end 

With s=0.8 I get a spiral, which looks like a development but I'm no closer to the circular shape that I am expecting. I think I just need a fresh pair of eyes to see where perhaps an obvious error lies.

Upvotes: 0

Views: 526

Answers (1)

Wrzlprmft
Wrzlprmft

Reputation: 4434

You are coding something drastically different than you wrote down in the equations. If you wrote down the equations with the same order and variable names, you would probably already see your error.

Also, the following things should have tipped you off:

  • The step size does not appear as a linear factor in both equations.
  • In your first attempt, X has no impact on V.

Nonetheless, here is a direct translation of your equations to code (and the Euler method):

for i = 1:1000
    x(i+1) = x(i) + y(i)*s;
    y(i+1) = y(i) + sin(x(i))*s;
end

If you really want to use the linear approximation, just replace sin(x(i)) by x(i). However, the main point of the linear approximation is that it’s nice for analytical solutions and theoretical analysis. Since you are solving the problem numerically, I do not see a need for it.

Finally, note that since you are integrating a Hamiltonian system, you will very quickly see the problems of the Euler method, i.e., you will always get a blatant spiral. Just imagine what would happen if you simulate the motion of the earth around the sun with tangential vectors:

enter image description here

Upvotes: 2

Related Questions