BYOM function derivatives.m (the model in ODEs)
Syntax: dX = derivatives(t,X,par,c,glo)
This function calculates the derivatives for the model system. It is linked to the script files byom_my_first.m. As input, it gets:
- t : the time point, provided by the ODE solver
- X : vector with the previous value of the states
- par : the parameter structure
- c : the external concentration (or scenario number)
- glo : the structure with various types of information
Time t and scenario identifier c are handed over as single numbers by call_deri.m (you do not have to use them in this function). Output dX (as vector) provides the differentials for each state at t.
- Author: Tjalling Jager
- Date: November 2021
- Web support: http://www.debtox.info/byom.html
- Back to getting started or byom_my_first.m
Copyright (c) 2012-2021, Tjalling Jager, all rights reserved. This source code is licensed under the MIT-style license found in the LICENSE.txt file in the root directory of BYOM.
Contents
Start
The function statement, and make the global structure glo known here (not used in this function in this demo).
function dX = derivatives(t,X,par,c,glo)
Unpack states
The state variables enter this function in the vector X. Here, we give them a more handy name (in this example, there is only one state).
Ci = X(1); % state 1 is the internal concentration at previous time point
Unpack parameters
The parameters enter this function in the structure par. The names in the structure are the same as those defined in the byom script file. The 1 between parentheses is needed for fitting the model, as each parameter has 4-5 associated values.
Kiw = par.Kiw(1); % bioconcentration factor, L/kg ke = par.ke(1); % elimination rate constant, d-1
Calculate the derivatives
This is the actual model, specified as ODE.
if t>7 % for the depuration phase ... c = 0; % make the external concentration zero end dCi = ke * (Kiw * c - Ci); % first-order bioconcentration dX = [dCi]; % collect derivatives in row vector dX to return to call_deri