Modelling consecutive chemical reaction (ode45, lsqcurvefit)

3 views (last 30 days)
Hello community
I want to model some experimental data with the ode's of the unimolecular consecutive chemical reaction to get the values of the kinetic konstants (k). The odes are:
I have experimental data to fit for I. To do so, I adopted the code from Star Strider in this post to my needs:
ydata = [1;5;5;2.5;3.96;2.37]; % Experimental data for I
xdata = [0;49.8000000000000;100.200000000000;150;199.800000000000;250.200000000000]; % time
B0 = [0.2 0.8];
lb = [0 0]
[B,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat] = lsqcurvefit(@MonodKinetics2,B0,xdata,ydata,lb);
% Plot
a= MonodKinetics2(B, xdata)
plot(xdata, ydata,'bo')
hold on
plot(xdata,a,'ro')
hold off
function S = MonodKinetics2(B, t);
% k1 = B(1), k2 =(B2)
% A = x(1), I = x(2), P = x(3)
x0 = [1 1 0];
[T,Sv] = ode45(@DifEq, t, x0);
function dS = DifEq(t, x);
xdot = zeros(2,1);
xdot(1) = -B(1) .* x(1);
xdot(2) = B(1) .* x(1) - B(2) .* x(2);
xdot(3) = B(2) .* x(2);
dS = xdot;
end
S = Sv(:,1);
end
It is obvious that something is wrong, because the calculated values for I are always 1 and for the k's nearly 0. Can somebody help me?
  2 Comments
Torsten
Torsten on 21 Nov 2018
If you have data for I, you'll have to set S = Sv(:,2) instead of S = Sv(:,1).
Marco Knobloch
Marco Knobloch on 21 Nov 2018
Oh that's it!! It is more obvious than I thought. Thank you Torsten

Sign in to comment.

Answers (0)

Categories

Find more on Chemistry in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!