% PIX_1.m
% particle drop on a spring 
% analytical solution

clear; clc; close all

g = 9.81; % gravitational acceleration (m/s^2)
m = 10; % mass (kg)
fprintf('mass m = %6.3f (kg)\n',m)

k = 294e3; % spring constant (N/m)
fprintf('spring constant k = %6.3e (N/m)\n',k)

h = 1; % drop height (m)
v0 = sqrt(2*g*h); % initial velocity (m/s)
fprintf('initial velocity v0 = %6.3f (m/s)\n',v0)

w = sqrt(k/m);
x = -g/w^2 - ...
   sqrt(g^2/w^4 + v0^2/w^2) *...
   cos(w*pi/w - w*atan(v0*w/g)/w + atan(v0*w/g));
t2 = 2*pi/w - 2*atan(v0*w/g)/w;
lam = g/w^2 + sqrt(g^2/w^4 + v0^2/w^2);
dv = 2*v0;
Pemax = k*lam;

fprintf('total time t2 = %6.3e (s)\n',t2)
fprintf('relative displacement  = %6.3e (m)\n',lam)
fprintf('velocity jump = %6.3f (m/s)\n',dv)
fprintf('max elastic force = %6.3f (N)\n',Pemax)


%%

% mass m = 10.000 (kg)
% spring constant k = 2.940e+05 (N/m)
% initial velocity v0 =  4.429 (m/s)
% total time t2 = 1.847e-02 (s)
% relative displacement  = 2.617e-02 (m)
% velocity jump =  8.859 (m/s)
% max elastic force = 7693.653 (N)



