From: Phuah on 21 Jul 2010 11:25 Hi, I do have one problem with kinetic modeling. Let's say a reaction occurs in such a way A <------> B (reversible way) where k1 is a constant for A change to B and k2 is a constant for B change to A so I used ODE solver to solve the problem mentioned and successfully get a graph. However, I do not know how to fit my experimental data into the graph and get the reaction constant k1 and k2 using matlab. Anyone can help? How to use matlab nonlinear regression by least square? Thanks in advance. function dxdt=matlab(t,x) global k1 k2 k1=0.1; k2=0.01; dxdt=[-k1*x(1)+k2*x(2);k1*x(1)-k2*x(2)]; [t,x]=ode45{@matlab,[0 50],[0.1 1]} plot{t,x} Thanks, Matlab newbie
From: Torsten Hennig on 21 Jul 2010 22:37 > Hi, > I do have one problem with kinetic modeling. Let's > say a reaction occurs in such a way > A <------> B (reversible way) > where k1 is a constant for A change to B > and k2 is a constant for B change to A > > so I used ODE solver to solve the problem mentioned > and successfully get a graph. However, I do not know > how to fit my experimental data into the graph and > get the reaction constant k1 and k2 using matlab. > Anyone can help? How to use matlab nonlinear > regression by least square? Thanks in advance. > > function dxdt=matlab(t,x) > global k1 k2 > k1=0.1; k2=0.01; > dxdt=[-k1*x(1)+k2*x(2);k1*x(1)-k2*x(2)]; > > [t,x]=ode45{@matlab,[0 50],[0.1 1]} > plot{t,x} > > Thanks, > Matlab newbie By solving your two ODEs analytically, you get explicit formulae for the concentrations of the two species A and B which depend on t, k1 and k2. Now you can use lsqcurvefit or lsqnonlin in the usual way. Best wishes Torsten.
From: Michael on 26 Jul 2010 12:23 You are almost there. A possible way to do this is to write a function which simulates the system, e.g. function [t,x] = sim(k) dx = @(x)( [-k(1)*x(1)+k(2)*x(2);k(1)*x(1)-k(2)*x(2)]); [t,x] = ode45(dx, ... ) end and a having a function which uses the result from simulation for given k1,k2 to compute the x values at specified time instances, e.g. where you have the measurements function [xt] = xdata( k, tvals ) [t,x] = sim( k ); xt = interp1( t,x,tvals ); Now you can use the function xdata for the nonlinear least square regression in k1,k2 with lsqcurvefit. However, you should specify a reasonably tight tolerance in ode and/or enlarge the number of output points (see odeset -> Refine ) since you are going to interpolate after simulating. This should work. But I must warn you, this is probably not the best way to do this and certainly not the fastest. Since your system is linear, there might be faster/better solutions, which I don't know. Regards, Michael
|
Pages: 1 Prev: Urgent! Help in 'nprtool' and 'svm' Next: Urgent! Help in 'nprtool' and 'svm' |