Re: nonlinear programming with differential-algebraic constraints (2)
- To: mathgroup at smc.vnet.net
- Subject: [mg52136] Re: nonlinear programming with differential-algebraic constraints (2)
- From: Joerg Schaber <schaber at molgen.mpg.de>
- Date: Fri, 12 Nov 2004 02:13:49 -0500 (EST)
- References: <cmsok4$b72$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Thanks for your replies. Indeed, the problem was that I have to define a function or module to be called in NMinimize that gets evaluated every time with the new parameter. I solved it now by defining a module, but the solutions using functions are also very elegant, I think. Thanks, joerg Joerg Schaber wrote: > 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 >