Re: [Q] Nonlinear Fitting in symbolic Integration ..?

• To: mathgroup at smc.vnet.net
• Subject: [mg82909] Re: [mg82842] [Q] Nonlinear Fitting in symbolic Integration ..?
• From: Darren Glosemeyer <darreng at wolfram.com>
• Date: Sat, 3 Nov 2007 03:22:56 -0500 (EST)
• References: <200711011012.FAA07488@smc.vnet.net>

```hwoarang wrote:
>  Dear Mathgroup,
>
>  I have experiment data and am trying to fit data to convoluted equation.
>  The equation contains UnitStep and symbolic Integrate function.
>  I think that these functions have some compolited problems according to searching
>  about related problems in archives.
>  But still, I have no idea whether the problem is in UnitStep, symbolic Integrate or NonlinearRegress.. -_-.
>  Does anybody out there have any ideas for this ?
>  Any help would be appreciated.
>
>  I pasted math code.
>
>  Sincerely, yours
>  Hwoarang.
>
>  Math Code :
>  -----------------------------------------------------------------------------
>  Remove["Global`*"];
>  << "Statistics`NonlinearFit`"
>  k0 = 1; k1 =. ; k2 =. ; tau1 =. ; tau2 =. ;
>  response[t_, x_] := (UnitStep[t - x]*{k2*(1 - E^(-((t - x)/tau2))) +
>  (k1*(1 - E^(-((t - x)/tau1))))/E^((t - x)/tau2)})/E^(x^2/(2*0.1^2))
>  convol[t_] = Integrate[(k0*response[t, x])/(2*Pi*0.1^0.5), {x, -1, 0},
>  Assumptions -> {{t, k1, k2, tau1, tau2} ¡ô Reals && t > 0 && tau1 > 0 &&
>  tau2 > 0 && k1 > 0 && k2 > 0}, GenerateConditions -> False] +
>  Integrate[(k0*response[t, x])/(2*Pi*0.1^0.5), {x, 0, 20},
>  Assumptions -> {{t, k1, k2, tau1, tau2} ¡ô Reals && t > 0 && tau1 > 0 &&
>  tau2 > 0 && k1 > 0 && k2 > 0}, GenerateConditions -> False]
>  dat = Import["Reflsmooth.txt", "Table"];
>  ListPlot[dat];
>  NonlinearRegress[dat, convol, t, {{k1, 0.4, 0.35, 0.45},
>  {k2, 0.04, 0.035, 0.045}, {tau1, 0.35, 0.3, 0.4}, {tau2, 0.25, 0.2, 0.3}},
>  ShowProgress -> True]
>
> --------------------------------------------------------------------------
> Jiwan Kim, Ph. D. Candidate,
> Dept. of Physics and Center for Nanospinics of Spintronic Materials,
> KAIST 373-1, Guseong-dong, Yuseong-gu, Daejeon, 305-701, Republic of Korea
> Tel: +82-42-869-8163
> Cel: +82-16-870-7419
> Fax: +82-42-869-8162
> E-mail: hwoarang at kaist.ac.kr
>
>

Without your data, I can't comment on exactly what you are seeing, but I
can make a few comments on the code that might solve the problem.

In the definition of response there is a set of curly brackets {} that
should be parentheses (). In the symbolic integrals it would be better
to use exact numbers instead of floating point numbers.  In the
NonlinearRegress call, convol should be convol[t] instead.

An example with some simulated data is below.

In[1]:= << "Statistics`NonlinearFit`"

In[2]:= k0 = 1;

In[3]:= response[t_, x_] := (UnitStep[t - x]*(k2*(1 -
E^(-((t - x)/tau2))) + (k1*(1 - E^(-((t -
x)/tau1))))/
E^((t - x)/tau2)))/E^(x^2/(2*(1/10)^2))

In[4]:= convol[t_] =
Integrate[(k0*response[t, x])/(2*Pi*(1/10)^(1/2)), {x, -1, 0},
Assumptions -> {t > 0 && tau1 > 0 && tau2 > 0 && k1 > 0
&& k2 > 0},
GenerateConditions -> False] +
Integrate[(k0*response[t, x])/(2*Pi*(1/10)^(1/2)), {x, 0,
20},
Assumptions -> {t > 0 && tau1 > 0 && tau2 > 0 && k1 > 0
&& k2 > 0},
GenerateConditions -> False];

In[5]:= dat = Table[
Flatten[{t, convol[t]*(1 + Random[Real, {-.005,
.005}])}], {t, 0,
1, .01}] /. {k1 -> .41, k2 -> .37, tau1 -> .31, tau2
-> .28};

In[6]:= NonlinearRegress[dat,
convol[t], t, {{k1, 0.4, 0.35, 0.45}, {k2, 0.04, 0.035,
0.045}, {tau1, 0.35,
0.3, 0.4}, {tau2, 0.25, 0.2, 0.3}}]

Out[6]= {BestFitParameters ->

>     {k1 -> 0.416736, k2 -> 0.369518, tau1 -> 0.310294, tau2 ->
0.285446},

>    ParameterCITable ->        Estimate   Asymptotic SE
CI                    ,
k1     0.416736   0.0774913       {0.262937,
0.570535}

k2     0.369518   0.00137785      {0.366783,
0.372252}

tau1   0.310294   0.250587        {-0.187052,
0.807639}

tau2   0.285446   0.180313        {-0.0724248,
0.643317}

-8
>    EstimatedVariance -> 1.1668 10  ,

>    ANOVATable ->                     DF    SumOfSq        MeanSq     ,
Model               4     0.170563       0.0426407

-6            -8
Error               97    1.13179 10     1.1668 10

Uncorrected Total   101   0.170564

Corrected Total     100   0.0110745

>    AsymptoticCorrelationMatrix -> 1.          0.951971    0.99865
-0.997248,

0.951971    1.          0.96587
-0.970739

0.99865     0.96587     1.
-0.999742

-0.997248   -0.970739   -0.999742   1.

>    FitCurvatureTable ->                           Curvature}
Max Intrinsic             0.33271

Max Parameter-Effects     1132.36

95. % Confidence Region   0.636868

In several trials with different simulated data sets, I found that
convergence is sometimes a problem. I think this is due, at least in
part, to interdependency of the parameters in the model; note that the
entries in the correlation matrix are all nearly 1 or -1.

Darren Glosemeyer
Wolfram Research

```

• Prev by Date: Re: Converting notebooks to use Mathematica Player
• Next by Date: How to solve coupled ODEs and PDEs(2ode+2pde) with NDSolve
• Previous by thread: [Q] Nonlinear Fitting in symbolic Integration ..?
• Next by thread: Re: [Q] Nonlinear Fitting in symbolic Integration ..?