Reputation: 1
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
Upvotes: 0
Views: 135
Reputation: 1
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.
Upvotes: 0