Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1999
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1999

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

Search the Archive

Re: NonlinearRegress and numerical functions...

  • To: mathgroup at smc.vnet.net
  • Subject: [mg20180] Re: [mg20132] NonlinearRegress and numerical functions...
  • From: BobHanlon at aol.com
  • Date: Sun, 3 Oct 1999 21:07:44 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

Larske,

If definition of g, use Evaluate so that you only solve the DE once, rather 
than each time g is called

g[t1_] := 
  Evaluate[y[t] /. DSolve[{y'[t] == -y[t] 3, y[0] == 6}, y[t], t][[1]] /.
t -> t1];

Fit won't be very accurate for four data points, use more

data = {0, 1, 2, 5, 10, 20, 50, 100};

fit = Transpose[{data, g[data]}];

There is no need for a numerical solution (NDSolve) in definition of f. Also, 
use Evaluate as above.

f[t1_, a_, b_] := 
  Evaluate[y[t] /. DSolve[{y'[t] == -y[t] a, y[0] == b}, y[t], t][[1]] /.
t -> t1];

Needs["Statistics`NonlinearFit`"]

You need to fit to "fit" not "data"

BestFitParameters /. NonlinearRegress[fit, f[t, a, 6], {t}, {a}]

{a\[Rule]3.}

BestFitParameters /. NonlinearRegress[fit, f[t, a, b], {t}, {a,b}]

{a\[Rule]3.,b\[Rule]6.}


Bob Hanlon

In a message dated 10/2/1999 8:47:21 AM, loke at ic.chalmers.se writes:

>I've got a big problem making Mathematica realize that my function is
>numerical. The following problem illustrates it in a rather simplified
>way:
>
>g[t1_] := y[t] /. DSolve[{y'[t] == -y[t] 3, y[0] == 6}, y[t], t][[1]] /.
>t -> t1
>
>data = {0, 10, 20, 100};
>
>fit = Transpose[{data, g[data]}];
>
>f[t1_, a_,b_] := (y[t] /.NDSolve[{y'[t] == -y[t] a, y[0] == b}, y[t],
>{t, 0, 100}][[1]]) /.t -> t1
>
>NonlinearRegress[data, f[t, a, 6], {t}, {a, {2.9, 3.2}, 2, 4}]
>
>
>It should be  rather straightforward to solve this, but NonlinearRegress
>seem to evaluate the function 'f' first and the results:
>
>NDSolve::"ndnum": "Encountered non-numerical value for a derivative at
>\
>
>\!\(t\) == \!\(2.680466916142905`*^-274\)."
>
>etc....
>
>I've tried to use Unevaluated and Hold but nothing works!
>


  • Prev by Date: Re: Re: List-Selection
  • Next by Date: Re: Re: List-Selection
  • Previous by thread: Want to do Electrostatic problems in 3D?
  • Next by thread: NonlinearRegress and numerical functions...