Filter löschen
Filter löschen

implementation of an ODE system, not the expected output

2 Ansichten (letzte 30 Tage)
Sylvain Bart
Sylvain Bart am 19 Sep. 2019
Kommentiert: Sylvain Bart am 20 Sep. 2019
Hello,
I don’t get what I would like with my ODE systems and I don’t understand why, if someone could help me it would be great (thank you to any readers)
I have 6 variables input: S DwA DwB Dw TH and K and several constant parameters
Here is my function:
y=[1 0 0 0 0 0]
function dy = deri(t,y,par,cA,cB)
%% Unpack states
S = y(1);
DwA = y(2);
DwB = y(3);
Dw = y(4);
TH =y(5);
K =y(6);
%% Unpack parameters values
kdA = par(1);
mwA = par(2);
bwA = par(3);
hbA = par(4);
kdB = par(5);
mwB = par(6);
bwB = par(7);
hbB = par(8);
hb = max(hbA,hbB);
%% Calculate the model output
dDwA = kdA * (cA - DwA);
dDwB = kdB * (cB - DwB);
dDw=dDwA +dDwB; % Dw(t)= DwA(t) + DwB(t)
% until here I get everything I expect (the expected values) for the three above variables
% here are the issues
dTH=(mwA*(dDwA/dDw)) + (mwB*(dDwB/dDw)); % for TH I don’t get the expected values, and I don’t know why
% at each time point it should be: TH(t)=(mwA*(DwA(t)/Dw(t))) + (mwB*(DwB(t)/Dw(t))), TH should decrease over time
dK=(bwA*(dDwA/dDw)) + (bwB*(dDwB/dDw))
% I have the same issue for K (same equation but with the constants bwA and bwB)
% For the following I don't know as TH and K are not calculate as expected
h = K * max(0,Dw-TH); % calculate h
dS = -(h + hb)* S; %change in survival probability
dy = [dS;dDwA;dDwB;dDw;dTH;dK]; % collect derivatives in one vector
Many thanks in advance for any answers
Sylvain
  2 Kommentare
Are Mjaavatten
Are Mjaavatten am 19 Sep. 2019
Have you tried using the debugger to stop execution at, say, line 30 (the first non-comment line after the expression for dK)? Then you can play around with your expressions in the command window and try to figure out why their values are not as expected.
If you are new to Matlab and not yet familiar with the debugger: It is quite straight-forward. In the editor, set a breakpoint by clicking on the hyphen in the grey field next to the line. A red dot should appear. Then try running your code. Execution will stop before the marked statement and all variables calculated up to this point will be available
Sylvain Bart
Sylvain Bart am 20 Sep. 2019
Thank you for your reply, it was useful to know this and I will use it in the futur.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by