# Numerical integration of NDSolve solution

Linking to what is discussed here, writing the following code:

m := 1.52
g := 9.81
us := 0.30
uk := 0.20
k := 10.12
F := 1.00
xi := 2.20
vi := 0.00

sol = NDSolve[{

F - k x[t] - Sign[x'[t]] uk m g == m x''[t],
x == xi,
x' == vi,

WhenEvent[
x'[t] == 0 && us m g >= Abs[F - k x[t]],
tmax = t; "StopIntegration"]

}, x, {t, 0, 10^4}];


and recalling the theorem of work and kinetic energy: the work done by all the forces acting on a body is equal to the variation of its kinetic energy, that is $\sum_j W_j = K_f - K_i$, I calculated:

NIntegrate[Sign[x'[t]] F - k x[t] - uk m g /. sol[], {t, 0, tmax}] // Chop


-19.3941

1/2 m x'[tmax]^2 - 1/2 m x'^2 /. sol[] // Chop


0

I don't understand why work is not zero as the kinetic energy variation! Ideas?

Writing:

NIntegrate[m x''[t] x'[t] /. sol[], {t, 0, tmax}] // Chop


you have perfect match!

• "the work done by all the forces acting on a body is equal to the variation of its kinetic energy":NIntegrate[Sign[x'[t]] F - k x[t] - uk m g /. sol[], {t, 0, tmax}] // Chop  does not calculate the work but Intergates the force over time (work is force integrated over distance). Aug 14, 2017 at 16:48
• This is a one dimensional problem; the force is constrained to point along or against the direction of x. I suspect you'll have more luck with: $W=\int\, dx\, F = \int \,dt\, x' F$. I recommend warming up by using the same code on simple harmonic oscillator, then Damped SHO, then Driven Damped SHO, etc. Debugging where you have complete analytic control. Aug 14, 2017 at 17:22