Re: FindRoot and NDSolve
- To: mathgroup at smc.vnet.net
- Subject: [mg48073] Re: FindRoot and NDSolve
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Tue, 11 May 2004 05:19:56 -0400 (EDT)
- References: <20040510110322.14062.qmail@sina.com>
- Sender: owner-wri-mathgroup at wolfram.com
On 10 May 2004, at 20:03, longbw2005 wrote: > Dear SiR: > i have a problem about the numberic calulation of mathematica and i > hope you can give me some advice. thank you! > i want to use FindRoot to solve an eqution whose cofficent depend on > the result of NDSolve. > > the procedure is as follow : > > fdc[c1_?NumericQ] = c1 -0.455802; > (1) > mt1[c1_?NumericQ] = 0.75 - c1; > (2) > fg[c1_?NumericQ] =21.8552*fdc[c1]; > (3) > fb[c1_?NumericQ] =3.1088*10^8*fdc[c1]^1.7*mt1[c1]; > (4) > n20[c1_?NumericQ] = fb[c1]/fg[c1]; > (5) > > ans=NDSolve[{n'[L]==-(18138.6*Exp[-0.0063*L]-n[L])/1700/ > fg[c1],n[0]==n20[c1]},n,{L,0,2000}]; > n2=ans[[1,1,2]]; > (6) > n2[0]=n20[c1]; > > mt2=2*10^-15*NIntegrate[n2[l]*l^3,{0,2000}]; > (7) > > f1=mt1[c1]/mt2-1; > ans=FindRoot[f1,{c1,0.46,0.65}]; > > f1 is the equation,c1 is the unkown variable,mt1 calculated by (2), > mt2 calculated by (7), > > The mathematica gives error message: > NDSolve::ndinnt: Initial condition n20[c1] is not a number or a > rectangular \ > array of numbers. > > > it seems that fg ,fb and n20 did not get evaluated as numbers. > > if there is no mistake in the defination,i can not figure out where > the mistake is. i use mathematica 5.0 windows version. > > any suggestion will be appreciated! Thank you > > > Actually,there are many mistakes here: in fact so many it is very difficult to understand what your are trying to do. Your first definition of ans can't possibly return any answer since your initial condition for n n[0]==n20[c1] is not given in terms of a numerical value . I have also no idea what you expect to get from n2=ans[[1,1,2]]. Actually, should also remove all those _?NumericQ from the first group of definitions as they only prevent evaluation of expressions like n2[0]=n20[c1], but because there are so many ohter things wrong it won't help much. But but in any case, what is n2[0] doing there at all? And what is this: > mt2=2*10^-15*NIntegrate[n2[l]*l^3,{0,2000}]; ? First, there is no variable you are integrating with respect to. But even if we assume you meant it to be l, still > mt2=2*10^-15*NIntegrate[n2[l]*l^3,{l, 0,2000}]; can't be computed because you have not defined n2[l] (you have only defined n2[0] and even that only in terms of c1, which is not a number). I am afraid at this stage you have not even got to the stage when one could seriously try to help you. Sorry about being so unhelpful. Andrzej