NMinimize/FindMinimum and function involving NDSolve

• To: mathgroup at smc.vnet.net
• Subject: [mg46219] NMinimize/FindMinimum and function involving NDSolve
• From: kzhang at flashmail.com (Kezhao Zhang)
• Date: Thu, 12 Feb 2004 07:15:46 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```Hello,

I tried to find the initial condition for a second order ODE by
numerically solving the equation and using NMinize or FindMininum. The
objective to be minimized is defined as a function of c1 and c2, the
initial condition. The problem is that NMimize and FindMinum complain
that NDSolve::"ndinnt": "Initial condition x is not a number or a
rectangular array of numbers". I wonder if  NMinimize and FindMinimum
can take a function involving complex rpocedurals like NDSolve. If
not, is there a workaround?  My code is listed below. Thanks for your
help.

In[]:=objective[c1_, c2_] := Module[{x, t, s, xx}, xx = Linspace[0,
2., 40];
s = NDSolve[{x''[t] - x'[t] + x[t] == 0, x[0] == c1, x'[0] == c2},
x, {t,
0, 2}];
Total[(First[x /. s][#] - Exp[#/2] Cos[Sqrt[3]/2#])^2 & /@ xx]]

In[]:=FindMinimum[objective[x, y], {{x, 1}, {y, 1}}]
or
In[]:=NMinimize[objective[x, y], {x, y}]

gives error message "NDSolve::ndinnt: Initial condition x is not a
number or a rectangular array of numbers."

K. Zhang

```

• Prev by Date: Re: Formatting notebooks for Menu File:New?
• Next by Date: Re: queation exporting quaternions from mathematica 5