Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*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 2004

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

Search the Archive

Re: Problem with order of evaluation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg50004] Re: Problem with order of evaluation
  • From: "Peter Pein" <petsie at arcor.de>
  • Date: Wed, 11 Aug 2004 05:52:58 -0400 (EDT)
  • References: <cf223r$7pc$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

"Max Ulbrich" <ulbrich at biochem.mpg.de> schrieb im Newsbeitrag
news:cf223r$7pc$1 at smc.vnet.net...
> Hi,
>
> I want to find a minimum in dependence of an initial
> condition of a differential eqaution. I can define a
> function f[y]:
>
> L=3.*^-9;
>
g[y_]=NDSolve[{p''[x]==-1.*^9(43418E^(-38p[x])-43418E^(38p[x])),p[0]==-0.13,
p'[0]==y},p[x],{x,0,L}]
> f[y_]:=((p[x]/.g[y]/.x->L)[[1]])^2
>
> which evaluates properly:
>
> f[0.22*^8]
>
> However, Mathematica doesn't evaluate it properly when I try
>   NMimimize, FindRoot or whatever:
>
> <<NumericalMath`NMinimize`
> NMinimize[f[y],{y,0.1*^8,0.3*^8}]
>
>
> How do I have to define f[y] that this works?
> Thanks a lot,
>
> Max
>
Hi Max,

try:
   L = 3.*^-9;
   g[y_] := Block[{x}, (*make x local to g*)
         NDSolve[{p''[x] == 86836*^9Sinh[38p[x]], p[0] == -0.13, p'[0] ==
y},
        p, {x, 0, L}]];
and evaluate f only for numeric arguments:
 f[y_?NumericQ] := First[p[L] /. g[y]]^2;

f[0.22*^8]
0.00619955

and for example:

FindRoot[f[x] == .01, {x, 1.*^7, 2.*^7}]
{x -> 1.59037*^7}

will work fine.

Peter
-- 
Peter Pein, Berlin
to write to me, start the subject with [




  • Prev by Date: x-ArcSin[Sin[x]]
  • Next by Date: how to graphically fill the tails of a normal distribution
  • Previous by thread: Problem with order of evaluation
  • Next by thread: Executing commands with shortcuts?