Re: how make function of solution by NDSolve depending

• To: mathgroup at smc.vnet.net
• Subject: [mg75129] Re: [mg75096] how make function of solution by NDSolve depending
• From: Murray Eisenberg <murray at math.umass.edu>
• Date: Wed, 18 Apr 2007 04:58:47 -0400 (EDT)
• Organization: Mathematics & Statistics, Univ. of Mass./Amherst
• References: <200704170020.UAA08810@smc.vnet.net> <3679818D-BB41-453E-8F1E-F5A507A55FEA@mimuw.edu.pl>
• Reply-to: murray at math.umass.edu

```Actually, according to the Mathematica 5.2 "Advanced Documentation" for
NMinimize, I think the syntax I used is OK even though all the examples
there show the {var, minvalue, maxvalue} argument itself nested inside a
list.

But the syntax I used is not correct for the semantics I intended.  I
really wanted a constraint 0.1<=k<=1 rather than an initial search
region, so what I intended was indeed:

NMinimize[{Evaluate[y[t] /. soln[k]] /. t -> 0.5, 0.1<=k<=1}, k]

That works -- but only after creating the function f as you instructed.

Thank you!

Andrzej Kozlowski wrote:
>
> On 17 Apr 2007, at 09:20, Murray Eisenberg wrote:
>
>> I have an initial-value problem that depends upon a parameter k.  I want
>> to feed the result from NDSolve for it into a function of k and then
>> operate upon that function, say to find a minimum with respect to k.
>>
>> As a toy example:
>>
>>    soln[k_]:=NDSolve[{y'[t] ==(k y[t]+Exp[-t])/(1+y[t]),
>>                y[0]==1},y[t],{t,0,1}]
>>
>> I want to do something like this:
>>
>>    NMinimize[Evaluate[y[t] /. soln[k]] /. t -> 0.5, {k, 0.1, 1}]
>>
>> That generates errors about non-numerical values.  Yet I can get a
>> result from, for example:
>>
>>   Table[Evaluate[y[t] /. soln[k]] /. t -> 0.5, {k, 0, 1}]
>>
>> So how can I create the function of k I want to feed into NMinimize?  I
>> presume the issue is when NDSolve gets called, but I'm not sure how to
>> resolve this issue.
>
>
> The syntax you are trying to use for NMinimize is quite wrong; have you
> looked at the documentation:
>
> ?NMinimize
>
> You could do this:
>
> f[k_?NumericQ] := Block[{y}, First[y /. NDSolve[{y'[t] == (k y[t] +
> Exp[-t])/(1 + y[t]),y[0] == 1}, y, {t, 0, 1}]]]
>
>
> In[2]:=
> NMinimize[{f[k][0.5], 0 <= k <= 1}, k]
>
> Out[2]=
> {1.1879073663327735, {k -> 1.5474783566024743*^-8}}
>
>
> Andrzej Kozlowski
>
>

--
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305

```

• Prev by Date: Re: LegendreP Evaluation Mystery
• Next by Date: Re: question about Protect
• Previous by thread: Re: how make function of solution by NDSolve depending on parameter?
• Next by thread: Re: how make function of solution by NDSolve depending on parameter?