MathGroup Archive 2009

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

Search the Archive

Re: Version problem with FindRoot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg97171] Re: Version problem with FindRoot
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Sat, 7 Mar 2009 02:38:03 -0500 (EST)
  • References: <goqug8$ng0$1@smc.vnet.net>

Hi,

> according to a short note of Alan Hayes, TJM Vol.3, issue 3 (1993 ! )
> there is a 3-liner given for solving boundary problems of ODEs with the=

> help of the so-called shooting method. The subsequent program
>
>     system[x_]={2 w'[n]+f[n]* w[n]==0,w[n]==v'[n],v[n]==f=
'[n],w[0]==x
> ,v[0]==0,f[0]==0 }
>
>   gun:=(soln=NDSolve[system[#],{w,v,f},{n,0,10}])[[1,2,2]][10.]&
>
>   FindRoot[gun[x]==1,{x,1,.5}]  (* should give x->0.332058 *)
>

this works with 5.1, I don't have 5.2 but think it should work there, too=
:

system[x_] = {2 w'[n] + f[
  n]*w[n] == 0, w[n] == v'[n], v[n] == f'[n], w[0] == x,
     v[0] == 0, f[0] == 0}

gun =.

gun[x_?NumericQ] := (soln = NDSolve[system[x], {w, v,
          f}, {n, 0, 10}])=E3=80=9A1, 2, 2=E3=80=9B[10.]

FindRoot[gun[x] == 1, {x, 1, .5}]


it gives 0.332057 on my machine, though. As the warning message tries to
tell, the problem is the common FAQ that FindRoot first tries an
evaluation with symbolic x, which causes NDSolve to give the warnings.
Using the pattern definition for gun which restricts evaluation of gun
to a numeric argument solves that problem.

hth,

albert



  • Prev by Date: Re: typsetting bug still present in Mathematica 7.01
  • Next by Date: Re: Style for function calls?
  • Previous by thread: Version problem with FindRoot
  • Next by thread: Re: Version problem with FindRoot