% H/harj5teht1a.m
% 14.3.04

function harj5teht1a


opt=odeset('events',@tapahtumat);
tspan=[0 1000]; y0=[4;0];
[t,y,tloppu,yloppu]=ode45(@f,tspan,y0,opt);
format compact
tloppu
yloppu

'Tarkistus:'
g=9.81;
loppuaika=sqrt(8/g)


function yp=f(t,y)
g=9.81;
yp=[y(2);-g];


function [arvo,lopeta,suunta]=tapahtumat(t,y)
arvo=y(1);  % Maanpinnalla paikka (y(1)) on 0.
lopeta=1;
suunta=-1;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Ajo
%>> harj5teht1a
%tloppu =
%   0.90304728197149
%yloppu =
%  -0.00000000000025  -8.85889383614031
%ans =
%Tarkistus:
%loppuaika =
%   0.90304728197146
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
