-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulate.m
38 lines (31 loc) · 915 Bytes
/
simulate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function [V,t,D] = simulate(Pars, plot)
%simulate - Simulates the take-off process
% Input:
% Pars - relevant parameters (all of them)
% plot -
if(nargin>=2 && plot)
opts=odeset('Events',@(t,V)events(t,V,Pars),'OutputFcn',@odeplot);
else
opts=odeset('Events',@(t,V)events(t,V,Pars));
end
[t,V]=ode45(@(t,V)odefun(t,V,Pars),[0 500],0,opts);
D = trapz(t, V);
end
function [value,isterminal,direction] = events(~,V,Pars)
% Locate the time when submergence passes through zero in a decreasing
% direction and stop integration.
value = depth(V,Pars); % detect h = 0
isterminal = 1; % stop the integration
direction = -1; % negative direction
end
function [acc] = odefun(~,V, Pars)
h = depth(V,Pars);
acc = Horizontal_Acceleration(V, h, Pars);
end
function [h] = depth(V, Pars)
if(V >= Pars.v_TOF)
h = -1e-3;
else
h = fzero(@(h)Vertical_Force(V,h,Pars), 1.001);
end
end