MATLAB: ODE use : how to integrate a very short action in the model

chemistrykineticMATLABode

Hello,
I am not new to Matlab : I was using it for year but some time ago (it was version 4). I am back with the last version : I am impress by the new possibility of this software.
But that not the purpose of my question !
I have the following kinetic model
function dc = Modele( t, c )
%MODELE Summary of this function goes here
% Detailed explanation goes here
r = 0.1 * c(1);
dc(1) = -r;
dc(2) = r;
dc = dc';
end
Which is integrated with this code :
c0 = [100, 0, 0.002, 5, 0, 0,0];
tspan = [0, 20];
ode = @(t,c)Modele(t,c);
[t,y] = ode45(ode, tspan, c0);
That perfect for a continuous process. I am able to perform action occurring during a time laps, for example addition of one reagent during one hour.
But how can I perform additions which are done at precise moment like addition of 1 gramme of a catalyst at 1, 2, 5 hours ?
I am expecting to be clear enough…
Jean-Marie

Best Answer

  • Hello Jean-Marie, the most robust and accurate approach is to integrate in intervals, say from [0 1] , [1 2] , [2 5] , etc. See https://www.mathworks.com/matlabcentral/answers/84749#answer_94392 for more details.