0

I have tried to simulate a mass pendulum on my own to train my matlab skills. I have coded a function that shows no errors, but however it does not do what it is supposed to do.

I wanted to iterate it for every time step. My idea was to calculate the current forces and the resulting acceleration. The velocity and the position s would be the sum of all previous accelerations. But somehow its ignoring the spring and the friction.

The results for the following parameters pendel(80,10,0.2,0.2,2)

function pendel (m,te,k,c,s0)
t = linspace(1,te,100*te);
g = 9.81;
s = zeros(1,length(t));
v = zeros(1,length(t));
a = zeros(1,length(t));

for i = 1:length(t)
    f1 = -m*g;
    f2 = -k*s(i);
    f3 = -v(i)*c;
    a(i) = (f1+f2+f3)/m;
    v(i) = sum(a(1:i));
    s(i) = sum(v(1:i))+s0;
end

subplot(3,1,1);
plot (t,s)
title('Ortsdiagramm')

subplot(3,1,2);
plot(t,v)
title('Geschwindigkeitsdiagramm')

subplot(3,1,3);
plot(t,a)
title('Beschleunigungsdiagramm')

end
  • You might want to multiply with the time step at some places. Also check out the Euler method for a more efficient computation of what you did here. Then contemplate using higher order methods. Also read up on the difference between a spring and a pendulum. – Lutz Lehmann Jan 08 '22 at 06:49

1 Answers1

0

I got it right now, for every iteration I used the current values of v(i) and s(i), which are zero, because they get their new value after the iteration. I adapted it so that the i-1 entry is used to calculate the friction and spring force.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 08 '22 at 09:00