MathGroup Archive 2006

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

Search the Archive

Re: Nonlinear Fit of Complex functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg64741] Re: [mg64646] Nonlinear Fit of Complex functions
  • From: Darren Glosemeyer <darreng at wolfram.com>
  • Date: Thu, 2 Mar 2006 06:47:25 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

At 02:53 AM 2/25/2006 -0500, Laura Borgese wrote:
>Hello,
>I am Laura and I have a problem fitting impedance data. in the "MathGroup 
>Archive:March 2000 [00255] I found very useful suggestions about my 
>problem, but finally the NonlineaRegress doesn't work, because it's not 
>able to evaluate a partial derivative. I tried also with FindMinimum but 
>it doesn't evaluate even in a numerical way! How can I try? Maybe the 
>problem is that I work with a version of the software too old: Mathematica 
>4.2? Thanks to anyone who has a suggest!
>Laura
>
>Laura Borgese: Laura.Borgese at guest.unimi.it
>Departement of Phisical Chemistry and Electrochemistry
>University of Milan- Italy


In version 4.2, NonlinearRegress needs symbolic derivatives of the model to 
perform the fitting.  In versions 5.0 and later, NonlinearRegress can fit a 
model without symbolic derivatives.

In version 4.2, using FindMinimum to minimize a sum of squared errors 
should work if two starting values are given for each parameter and the 
error sum of squares is real-valued.  I believe the MathGroup post you 
mentioned turned the complex-valued value model into a real-valued model, 
so I will assume the sum of squares in question is real-valued.

Here is an example in version 4.2 of minimizing a sum of squared errors for 
a real-valued function that is not symbolically differentiated and of 
"teaching" NonlinearRegress about the derivatives if a symbolic form can be 
given in particular case of interest.  Hopefully, this will be useful in 
your application.

Mathematica 4.2 for Microsoft Windows
Copyright 1988-2002 Wolfram Research, Inc.
  -- Terminal graphics initialized --

(* First, define some random data. *)

In[1]:= data = Table[{x, Abs[x + Random[Real, {-.1, .1}]]}, {x, -5, 5}];


(* The model will be an absolute value. *)

In[2]:= model[a_, b_, x_] := Abs[a*x + b]

In[3]:= << Statistics`


(* NonlinearRegress fails because a symbolic derivative cannot be obtained. *)

In[4]:= NonlinearRegress[data, model[a, b, x], x, {a, b}]

NonlinearRegress::unevldr:
    One or more derivatives of the model with respect to parameters did not 
evaluate.

Out[4]= NonlinearRegress[{{-5, 4.94091}, {-4, 3.95618}, {-3, 2.98012}, {-2, 
1.91337},

 >     {-1, 0.907183}, {0, 0.00951304}, {1, 1.08091}, {2, 1.99099}, {3, 
3.04511},

 >     {4, 4.04938}, {5, 4.94037}}, Abs[b + a x], x, {a, b}]


(* Defining the sum of square errors and using FindMinimum with two 
starting values gives a good result. *)

In[5]:= ssq = Apply[Plus, Map[(model[a, b, #[[1]]] - #[[2]])^2 &, data]];

In[6]:= FindMinimum[ssq, {a, 1, 2}, {b, 1, 2}]

Out[6]= {0.0163105, {a -> 0.993647, b -> 0.0380455}}


(* In this case, the derivatives can be expressed in terms of the Sign 
function. Mathematica can be taught the derivatives of model as follows. *)

In[7]:= Unprotect[D];

In[8]:= D[model[a_, b_, x_], a_] = x Sign[b + a x];

In[9]:= D[model[a_, b_, x_], b_] = Sign[b + a x];

In[10]:= Protect[D];


(* Now that symbolic derivatives for model are known, NonlinearRegress can 
fit the model. Note that FitCurvatureTable fails because it needs symbolic 
second partial derivatives. *)

In[11]:= NonlinearRegress[data, model[a, b, x], x, {a, b}]

Out[11]= {BestFitParameters -> {a -> 0.993647, b -> 0.0380455},

 >    ParameterCITable ->     Estimate    Asymptotic 
SE   CI                     ,
                          a   0.993647    0.00405898      {0.984465, 1.00283}

                          b   0.0380455   0.0128356       {0.00900933, 
0.0670817}

 >    EstimatedVariance -> 0.00181228,

 >    ANOVATable ->                     DF   SumOfSq     MeanSq    ,
                    Model               2    108.623     54.3114

                    Error               9    0.0163105   0.00181228

                    Uncorrected Total   11   108.639

                    Corrected Total     10   27.832

 >    AsymptoticCorrelationMatrix ->                           -17,
                                     1.              1.95159 10

                                               -17
                                     1.95159 10      1.

 >    FitCurvatureTable -> $Failed}



Darren Glosemeyer
Wolfram Research



  • Prev by Date: Re: Lists of all values of a two-variable function
  • Next by Date: Re: Lists of all values of a two-variable function
  • Previous by thread: Rayica and LensLab for Mathematica now available
  • Next by thread: Digital Electronics using Mathematica