-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimulateForSP.m
38 lines (31 loc) · 1007 Bytes
/
simulateForSP.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 varargout = simulateForSP(model, tout, phi, kappa, scale)
% Simulate model
if(nargout<2)
options_simu.sensi = 0;
sol = model(tout,phi,kappa,options_simu);
else
options_simu.sensi = 1;
sol = model(tout,phi,kappa,options_simu);
end
% Switch for the scale of the simulation
switch scale
case 'log'
varargout{1} = log(sol.y + 1e-16);
if (nargout>1)
varargout{2} = bsxfun(@times, sol.sy, 1./(sol.y + 1e-16));
end
case 'log10'
varargout{1} = log10(sol.y + 1e-16);
if (nargout>1)
varargout{2} = bsxfun(@times, sol.sy, 1 ./ (log(10)*(sol.y + 1e-16)));
end
case 'lin'
varargout{1} = sol.y;
if (nargout>1)
varargout{2} = sol.sy;
end
end
if sol.status < 0
error('Integration error in simulateForSP.m.')
end
end