- #1
user123897
- 3
- 0
Hi, I am trying to analyze the an harmonic oscillator using kinematics.
first i calculate the force applied by the spring (f = (-x)*k)
then i calculate the acceleration (a = f/m)
then speed (v= v0 + v0t + 0.5*a*t^2)
and finally update x (x = x0+vt)
this is a simplfied loop of my program (written in java, all values are initialized to 0 expect x = 10)
{
x = x + v * dt + 0.5 * a * Math.pow(dt, 2);
f = k * (-x);
a = ((f / m) + a) / 2;
v = v + a * dt;
a = f / m;
}
this loop runs evry dt milliseconds.
the values of x,v,a,f increase rapidly and aims to infinitey
can someone understand where i got it wrong?
thanks for your time :)
first i calculate the force applied by the spring (f = (-x)*k)
then i calculate the acceleration (a = f/m)
then speed (v= v0 + v0t + 0.5*a*t^2)
and finally update x (x = x0+vt)
this is a simplfied loop of my program (written in java, all values are initialized to 0 expect x = 10)
{
x = x + v * dt + 0.5 * a * Math.pow(dt, 2);
f = k * (-x);
a = ((f / m) + a) / 2;
v = v + a * dt;
a = f / m;
}
this loop runs evry dt milliseconds.
the values of x,v,a,f increase rapidly and aims to infinitey
can someone understand where i got it wrong?
thanks for your time :)