       Re: Global Fitting multiple equations to

• To: mathgroup at smc.vnet.net
• Subject: [mg84665] Re: Global Fitting multiple equations to
• From: dh <dh at metrohm.ch>
• Date: Tue, 8 Jan 2008 06:43:13 -0500 (EST)
• References: <flv5kb\$28v\$1@smc.vnet.net>

```
Hi Michael,

here is an example that shows the pitfalls.

We first are creating 2 datasets using given functions, each

representing a component of a 2 dim. vector function. For convenience we

then interpolate this data to get a vector valued function.

Second, we make an Ansatz with parameters that we want to fit.

Third, we calculate the error function.

Forth, we make the fit:

f1[t_]:=t^2; f2[t_]=2+3t; (*searched functions*)

ndat=10;

dat1=Table[{t,f1[t]},{t,ndat}];dat2=Table[{t,f2[t]},{t,ndat}];(*data

points*)

fundat[t_]={Interpolation[dat1][t],Interpolation[dat2][t]};(*interpolated

data function, vector valued*)

funcalc[t_]={c10+c11  t+c12 t^2,c20+c21 t+ c22 t^2};(*Ansatz*)

err[t_]=Total[ (funcalc[t]-fundat[t])^2];

newdat=Table[{t,0},{t,10}];(*new data with y=0*)

res=FindFit[newdat,err[t],{c10,c11,c12,c20,c21,c22},t];

Table[err[t]/.res,{t,10}]

You will note that this fit does not converge. This is because our

multidimensional error "surface" has many dips and it is difficult to

find the global minimum. What we can do is to help Mathematica a bit by

giving some starting values for parameters. E.g. if we start c10 with

0.5, convergence will be achieved:

res=FindFit[newdat,err[t],{{c10,0.5},c11,c12,c20,c21,c22},t]

Another pitfall to watch out is that the function for the different

components are sufficiently independent, otherwise there are many

solution that minimze our error.

hope this helps, Daniel

Michael Parker Latham wrote:

> Hi Daniel,

> Thanks for your reply.  I understand your suggestion to get the variables out by fitting/minimizing a target error function.  Seeing as I am a newbie at this, do you have any suggestions on how exactly this would be done.

> Thanks,

> Mike

>

> Michael Latham

> Department of Chemistry and Biochemistry

> Phone: 303-492-8085

> Fax: 303-492-2439

>

>

> ---- Original message ----

>> Date: Mon, 07 Jan 2008 13:12:15 +0100

>> From: dh <dh at metrohm.ch>  Hi

>> Subject: Re: Global Fitting multiple equations to multiple

>> To: Michael Parker Latham <Michael.Latham at Colorado.EDU>

>>

>> Hi Michael,

>> you want to fit a vector valued function but FindFit can only deal with

>> scalar valued functions. Well, all you have to do is to help FindFit a

>> bit. If we consider the norm of the error we have a scalar function that

>> we may fit to the zero function.

>> Say we have data yi[tj] where yi are the vector components and tj the

>> discrete time. Further yic[t] is the theortical expression for the

>> component i. Then

>> err=Sum( (yic[tj]-yi[tj])^2 ) where the sum is over i and j

>> is the norm square of the error (you may even take another norm).

>> You may now fit err againste the data: {{t1,0},{t2,0}...} to get the

>> parameters.

>> hope this helps, Daniel

>>

>> Michael Parker Latham wrote:

>>> Hi,

>>> I have collected a time dependent data set.  At each time point there is four observables (IntDiagBo, IntDiagFr, IntCrossFrBo and IntCrossBoFr) which can be described by four equations (ibb, iff, ifb, ibf).  These four equations are related and depend on six variables (ib, if, rb, rf, kbf, kfb).  I would like to globally fit the four data sets to the four equations to extract the six variable.  What I have done so far is below

>>>

>>> In:= << "NonlinearRegression`"

>>>

>>> Setup Equations

>>>

>>> In:= a11 = rb + kbf;

>>> a12 = -kfb;

>>> a21 = -kbf;

>>> a22 = rf + kfb;

>>> \[Lambda]1 = 1/2*((a11 + a22) + Sqrt[(a11 - a22)^2 + 4*kfb*kbf]);

>>> \[Lambda]2 = 1/2*((a11 + a22) - Sqrt[(a11 - a22)^2 + 4*kfb*kbf]);

>>>

>>> Diagonal Peaks Equations

>>>

>>> In:= ibb = ib*((\[Lambda]1 - a11) Exp[-\[Lambda]2*x1] - (\[Lambda]2 - a11)

>>>        Exp[-\[Lambda]1*x1])/(\[Lambda]1 - \[Lambda]2);

>>> iff = if*((\[Lambda]1 - a22) Exp[-\[Lambda]2*x1] - (\[Lambda]2 - a22)

>>>        Exp[-\[Lambda]1*x1])/(\[Lambda]1 - \[Lambda]2);

>>>

>>> Cross Peaks Equations

>>>

>>> In:= ibf = ib*(a21*Exp[-\[Lambda]1*x1] -

>>>       a21*Exp[-\[Lambda]2*x1])/(\[Lambda]1 - \[Lambda]2);

>>> ifb = if*(a12*Exp[-\[Lambda]1*x1] -

>>>       a12*Exp[-\[Lambda]2*x1])/(\[Lambda]1 - \[Lambda]2);

>>>

>>> Data for 1 set of peaks

>>>

>>> In:= IntDiagBo = {{0.01938, 5111831}, {0.03673, 3996563}, {0.03673, 4073294}, {0.05409, 3057033}, {0.07144, 2487152}, {0.08879, 1967903}, {0.10615, 1588128}, {0.10615, 1500203}, {0.1235, 1222629} , {0.14086, 1046551}};

>>> IntDiagFr = {{0.01938 , 13757210}, {0.03673, 11098630}, {0.03673, 11044150}, {0.05409, 9100536}, {0.07144, 7166819}, {0.08879, 6045878}, {0.10615, 4976833}, {0.10615, 5150198}, {0.1235, 4106922}, {0.14086, 3583284}};

>>> IntCrossFrBo = {{0.01938, 418536.5}, {0.03673, 607315.1}, {0.03673, 647085.9}, {0.05409, 663520.1}, {0.07144, 653818.1}, {0.08879, 643523.8}, {0.10615, 577511.9}, {0.10615, 647762.6}, {0.1235, 626453.3}, {0.14086, 564194.7}};

>>> IntCrossBoFr = {{0.01938, 450925.1}, {0.03673, 623400.1}, {0.03673, 719430.4}, {0.05409, 782262.1}, {0.07144, 796733.9}, {0.08879, 730650.5}, {0.10615, 709815.9}, {0.10615, 707971.9}, {0.1235, 754398.6}, {0.14086, 645057.8}};

>>>

>>> Restrain Exchange Rates with Kd

>>>

>>> In:= 0.002 == kfb/kbf;

>>>

>>> I can use FindFit to fit each data set to its respective equation, but I would like to globally, simultaneously fit the four equations to the four data sets to get "better" values for the six variables.

>>>

>>> Any help with this would be greatly appreciated.  Please let me know if there is any other information that can be supplied.

>>> Mike

>>>

>>>

>>> Michael Latham

>>> Department of Chemistry and Biochemistry

>>> Phone: 303-492-8085

>>> Fax: 303-492-2439

>>>

>

```

• Prev by Date: Re: Module Behavior
• Next by Date: Re: Dynamic stochastic general equilibrium models
• Previous by thread: Re: Global Fitting multiple equations to
• Next by thread: Module Behavior