Fitting more than one set of data to system of ODEs
Show older comments
Hello! I tried to solve a kinetic model by fitting experimental data to obtain the kinetic parameters. The system consists of four time-depending variables cA, cB, cC and cD, and four ODEs containing four parameters (k1, k2, k3, k4). I want to find out the parameters k1-k4, which fit best to experimental data, consisting of several independent data sets (t1, cA1, cB1,...,t2, cA2,cB2,...).
For this purpose, I defined the ODEs:
function dc=odeFolgeParallel1(k, t, c)
dc=zeros(4,1); k=zeros(4,1);
dc(1)=-k(1)*c(1)-k(4)*c(1);
dc(2)=k(1)*c(1)-k(2)*c(2);
dc(3)=k(2)*c(2)-k(3)*c(3);
dc(4)=k(3)*c(3)+k(4)*c(1);
dc=[dc(1);dc(2);dc(3);dc(4)];
and determined the objective function using ode45
function SSE=objectiveFolgeParallel1(td, cd, k, c0)
f=@(t,c)odeFolgeParallel1(k, t, c);
[ts,cs]=ode45(f,td,c0);
err=cd-cs;
SSE=sum(err.^2);
After importing the experimental data
cd=[0.7 0.65 0.6;0.05 0.04 0.045;0.05 0.06 0.055;0.2 0.25 0.3]
td=[8 8.3 7.9];
and setting the initial values c0=[1;0;0;0]; k0=[0.1;0.1;0.1;0.1];
I tried to optimize my parameters ksolve using
ksolve=fminsearch(@(k)objectiveFolgeParallel1(td,cd,k,c0),k0)
getting this error
Error using odearguments (line 84)
The entries in tspan must strictly increase or decrease.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in objectiveFolgeParallel1 (line 3)
[ts,cs]=ode45(f,td,c0); %Lösung der Diff.glg.
Error in @(k)objectiveFolgeParallel1(td,cd,k,c0)
Error in fminsearch (line 189)
fv(:,1) = funfcn(x,varargin{:});
which makes sense to me because tspan has to be a timeSPAN, not specific values for the time. But how can I fix this problem, optimizing the parameters in regard of this time points? I am really stuck here and would be really grateful for some help.
Accepted Answer
More Answers (1)
Torsten
on 9 May 2016
err=cd'-cs;
Best wishes
Torsten.
16 Comments
Teresa Schubert
on 10 May 2016
Torsten
on 10 May 2016
SSE=sum((err()).^2);
Best wishes
Torsten.
Teresa Schubert
on 10 May 2016
Torsten
on 11 May 2016
Could you include the complete code you are using at the moment ?
Best wishes
Torsten.
Teresa Schubert
on 11 May 2016
Edited: Teresa Schubert
on 11 May 2016
Please check the dimensions of cd and cs after the call to ode45:
[m1,n1]=size(cs);
[m2,n2]=size(cd);
Is m1 = m2 and n1 = n2 ?
Best wishes
Torsten.
Teresa Schubert
on 17 May 2016
Torsten
on 17 May 2016
So ode45 does not calculate a solution for your starting vector k0 ?
If you try
function SSE=objectiveFolgeParallel1(td, cd, k, c0) %objective function
f=@(t,c)odeFolgeParallel1(k, t, c);
[ts,cs]=ode45(f,td,c0);
[m1,n1]=size(cs);
[m2,n2]=size(cd);
m1
n1
m2
n2
pause
you already get a error ?
Best wishes
Torsten.
Teresa Schubert
on 17 May 2016
Could you check the value of SSE in the same way:
function SSE=objectiveFolgeParallel1(td, cd, k, c0) %objective function
f=@(t,c)odeFolgeParallel1(k, t, c);
[ts,cs]=ode45(f,td,c0);
err=cd-cs;
SSE=sum((err()).^2);
SSE
pause
Best wishes
Torsten.
Teresa Schubert
on 17 May 2016
Torsten
on 17 May 2016
I guess your initial conditions
c0=[1 0 0 0]; %Defining starting conditions
refer to time t=0 ?
If this is the case, you will have to set
cd=[1 0 0 0 ; 0.650 0.0500 0.0500 0.2500; 0.6000 0.0400 0.0600 0.3000; 0.6100 0.0420 0.5800 0.2900]; %experimental data
and
td=[0;7.9;8;8.3];
since you want to compare simulation and experiment at the same time instants.
Best wishes
Torsten.
Teresa Schubert
on 17 May 2016
Torsten
on 17 May 2016
Of course, you will have to delete the statement
k=zeros(4,1);
in "odeFolgeParallel1" since you want to evaluate your ODEs with the actual parameters k suggested by fminsearch, not with zeros.
Best wishes
Torsten.
Teresa Schubert
on 17 May 2016
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!