Re: Version problem with FindRoot

*To*: mathgroup at smc.vnet.net*Subject*: [mg97285] Re: Version problem with FindRoot*From*: dh <dh at metrohm.com>*Date*: Tue, 10 Mar 2009 05:33:37 -0500 (EST)*References*: <goqug8$ng0$1@smc.vnet.net>

Hi Robert, FindRoot first calls gun[x] with a symbolic argument to check if it can make simplifications. To prevent evaluation of gun with a symbolic argument, declare it so that is evaluated only for numeric arguments: gun[x_?NumericQ] := (soln = NDSolve[system[x], {w, v, f}, {n, 0, 10}])[[1, 2, 2]][10.] hope this helps, Daniel Dr. Robert Kragler wrote: > 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 *) > > works with earlier Mathematica versions 3.0, 4.2 but NOT for 5.2 (which > I am currently still using in order to finish a manuscript before I will > adapt this to version 7.0). In Mathematica version 6.0 and 7.0 FindRoot > will work again if the following (version 6 ) system option is used : > > SetSystemOptions["EvaluateNumericalFunctionArgument"->False] > > There is no problem to plot the function gun[x]with Plot[gun[x],{x,0,1}] > in Mathematica. > However, in Mathematica version 5.2 FindRoot gives rise to the following > (error) message : > > NDSolve::"ndinnt": "Initial condition x is not a number or a rectangular > array of numbers." > > FindRoot::nlnum : The function value {-1.+v´[n][10.`] is not a list of > numbers with > dimensions {1} at {x} = {1.`}.} > > Does anybody have an idea what to do in the case of version 5.2 ? Thanks > for any suggestion. > > Robert Kragler > > email: kragler at hs-weingarten.de > > >