You are on page 1of 1

Spring mass system,

function [out1, out2, out3] = emsode(t, y, flag, m, c)


if nargin < 4 | isempty(m)
m = 5e3;
end
if nargin < 5 | isempty(c)
c = 4.5e9/150^3;
end
switch flag
case ''
out1 = [y(2); 1/m*(F(t)-c*y(1)) ];
case 'init'
out1 = [0, 30];
out2 = [0; 0];
out3 = odeset('RelTol',1e-4);
end
function f = F(t)
f = 20*t*(t<=5)+20*(10-t)*(t>5 & t<=10);

You might also like