MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

NonLinear "Fitting" to an Interpolating Function


  • To: mathgroup@smc.vnet.net
  • Subject: [mg11467] NonLinear "Fitting" to an Interpolating Function
  • From: "Tom Marchioro" <tlm@u.washington.edu>
  • Date: Thu, 12 Mar 1998 01:34:41 -0500
  • Organization: University of Washington


Is it possible to use NonlinearFit (or some other combination of
functions in Mathematica) to make a fit from some data to a function
which is defined numerically once its parameters are given?  That is, I
have a differential equation which cannot be solved numerically, but is
straightforward to integrate with NDSolve once values are given for a
couple of parameters, with the result that is returned being an
InterpolatingFunction object.

Is it possible for this numerically defined function to be used as the
"model" in NonlinearFit or
FindMiinimum to get back a "best guess" as to what values of the
parameters best fit the data?

To give a somehat specific example, here is a module which integrates a
specific differential equation for given parameters (this is just a
test case, the actual diff eq. will generally be much harder)

ndsol[x_, a_, b_] :=
  Module[{f, y}, fun[y_] =
     f[y] /.
      Flatten[NDSolve[{Derivative[1][f][
           y] == -b*f[y], f[0] == a}, f[y], {y, 0, 5}]];
       fun[x]
    ]


We also have some data (which in general will be from experiment, not
generated analytically)

data=Table[{x, 2 E^(-2.2 x)}, {x, 1, 4, .25}];

and I want to do something like

NonlinearFit[data, ndsol[x,a,b], x, {a,b}]

which does not work. I **can** put in the model a*E^(-b*X) and get the
exact answer.  Alternatively, I can define the root mean square error

rmserror[a_,b_]:=Sqrt[Apply[Plus,
   (whys-ndsol[exes,a,b])^2]]

and then use FindMinimum to minimize the error between the data and the
numerical function

{exes, whys}=Transpose[Table[{x, 1.3 E^(-3.2 x)}, {x, 1, 4, .25}]];

FindMinimum[rmserror[a,b],
 {a, {1, 3}}, {b, {.1, 3}}]

{1.429919514422274*^-7, {a -> 1.300033428167226, b ->
3.200038604006857}}

which is "okay", but really I want the information you get from doing a
full regression on the data.

I've tried various combinations of "Evaluate" and "Hold" on the
arguments to NonlinearFit and do not seem to be getting anywhere.

Suggestions?

Thanks in advance --- Tom


--
Dr. Thomas L. Marchioro II
Department of Chemistry
University of Washington
206-323-9599
http://borg.chem.washington.edu/~tlm





  • Prev by Date: Bug in Product
  • Next by Date: Plotting points in 3D
  • Prev by thread: Bug in Product
  • Next by thread: Re: NonLinear "Fitting" to an Interpolating Function