MathGroup Archive 2004

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

Search the Archive

Re: nonlinear programming with differential-algebraic constraints (2)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg52110] Re: nonlinear programming with differential-algebraic constraints (2)
  • From: "Jens-Peer Kuska" <kuska at informatik.uni-leipzig.de>
  • Date: Thu, 11 Nov 2004 04:52:11 -0500 (EST)
  • Organization: Uni Leipzig
  • References: <cmsok4$b72$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

f[t_] := Exp[-0.1*t] + Random[Real, {0, 0.1}];
data = {#, Evaluate[f[#]]} & /@ Table[t, {t, 0, 10, 1}];


model[a_] := model[a]=
y /. NDSolve[{y'[t] == -a*y[t], y[0] == 1} /. a -> 0.05,
y, {t, 0, 10}][[1]];


fun[a_?NumericQ] :=
Module[{ff},
ff = model[a];
Plus @@ ((ff[#[[1]]] - #[[2]])^2 & /@ data)
]



NMinimize[{fun[a], a > 0}, a,
Method -> {"DifferentialEvolution"},
StepMonitor :> Print[squares, a],
WorkingPrecision -> 8]



Regards

  Jens

"Joerg Schaber" <schaber at molgen.mpg.de> schrieb im Newsbeitrag 
news:cmsok4$b72$1 at smc.vnet.net...
>I made a little example to illustrate the problem:
>
> I want to fit a model which is stated as a system of differenttial
> equations to some data.
>
> (* curve to be fitted *)
> f[t_]:=Exp[-0.1*t]+Random[Real,{0,0.1}];
> data={#,Evaluate[f[#]]}&/@Table[t,{t,0,10,1}];
>
> ListPlot[data,PlotStyle\[Rule]{RGBColor[0,0.2,0.8],PointSize[0.02]}];
>
> (* the parameter 0.1 is to be found *)
> (* the model as a differential equations *)
> model:=NDSolve[{y'[t]==-a*y[t],y[0]==1}/.a->0.05,y,{t,0,10}];
>
> (* minimizing sum of squares *)
> NMinimize[{squares=Plus@@Table[(Table[{#,y[t]/.Evaluate[model][[1]]/.t->#}&/@
> Table[t,{t, 0, 10, 1}]][[i, 2]]-data[[i,2]])^2,
> {i, Length[data]}], a > 0}, a,
> Method -> {"DifferentialEvolution"},
> StepMonitor :> Print[squares, a],
> WorkingPrecision -> 8]
>
>
> The main problem seems to be that the differential equation does not get
> evaluated in each step but only once.
>
> So if anybody could make this example work that would be great.
>
> best,
>
> joerg
> 



  • Prev by Date: Re: First question
  • Next by Date: Re: NonlinearFit problem
  • Previous by thread: Re: nonlinear programming with differential-algebraic constraints (2)
  • Next by thread: Re: nonlinear programming with differential-algebraic constraints (2)