-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcwm1.m
37 lines (32 loc) · 1.02 KB
/
cwm1.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
function C = cwm1(dt, params, init_cond)
%% CWM1-MATLAB - HANDLING FUNCTION
% CWM1 Initialize and run the ODE solver.
%
% Model parameters are passed as a vector to maximize compatibility with
% MATLAB Coder for mex building.
%
% Usage:
%
% C = CWM1(dt,params,init_cond)
%
% Input:
% - dt: final time
% - params: vector of model parameters. See parameters.m file.
% - init_cond: matrix [Nx16], where N is the number of instances
% and 16 is the number of components of the CWM1 model
%
% Output:
% - C: Concentration matrix [Nx16] at the last integration step t = dt
%
% (c) Matteo M. 2022
% Function handle system of equation
ode_eqn = @(t,C) cwm1_odesystem(t,C,params);
C = zeros(size(init_cond)); % Initialize concentration matrix
tspan = [0 dt]; % Time span
for i = 1:size(init_cond,1)
% Solve (ode23 solver is faster than ode45, with acceptable accuracy)
[~,Ctmp] = ode23(ode_eqn, tspan, init_cond(i,:));
% Only save the final concentration at t = dt
C(i,:) = Ctmp(end,:);
end
end