Usage:

Run the model first with the standard set-up. Note that e_tot is (nearly) constant. By increasing the relative error, the accuracy can be controlled. Next, have a try with RK4 as the method, and note that the ball is launched by the floor.

Model:

Model source

const G = 9.81;	
t.min = 0;
t.max = 5.0;
t.step= 0.01;
t.sample = 0.01;
t.method = RKV;
t.relerror = 1.0E-5;

real    x(t), 	! position of ball
        v(t), 	! velocity of ball
        a(t), 	! acceleration of ball
        f(t);	! force on ball
real	x0 = 1;
real    v0 = 0;
real  	c = 1000.0;	! stiffness of the floor
real  	m = 1.0;	! mass of the ball
real  	damp = 0.0;	! damping 
real  	bounce = 0.0; 	! damping bouncing
real  	e_kin(t), 	! kinetic energy
        e_pot(t), 	! potential energy (gravity + spring)
        e_tot(t); 	! total energy (should be constant)

module main;
begin
     ! forces on ball: gravity (-G*m) and spring stiffness of wall
     f = -G*m + switch( x < 0.0 ? c*(-x) - bounce*v else 0.0) - damp*v;
     a = f/m;
     v = integ(a, v0);
     x = integ(v, x0);
     e_kin = 0.5*m*v*v;
     e_pot = m*G*x + switch(x < 0.0 ? 0.5*c*x*x else 0.0);
     e_tot = e_kin + e_pot;
end;