Re: ODE system - shooting for a terminal point
- To: mathgroup at smc.vnet.net
- Subject: [mg121173] Re: ODE system - shooting for a terminal point
- From: David Bailey <dave at removedbailey.co.uk>
- Date: Fri, 2 Sep 2011 03:29:26 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <j3l17d$btv$1@smc.vnet.net>
On 31/08/2011 11:08, The Mighty Algernon wrote: > Hi, > > I wonder if you could help me. > > I have a system of ODE in which I have to figure out the initial > conditions of part of the differential equations. I managed to do this > by the shooting method by writing the system as a function of the > initial conditions. > > For example solution[yini_,zini_]:=NDSolve[...... > > then I used FindRoot on the set of terminal restrictions to find yini > and zini (these are the initial conditions). This procedure worked > although it is terribly sensitive to the first guesses on the FindRoot > and some results I get are obviously wrong. But this is something I > can refine. > > Now I have a similar goal but the variable I'm trying to guess is not > an initial condition of a differential equation but the terminal value > of the range of the exogenous variable. For example, > > If I have a system of 2 ODE , y[x] and z[x], I want to know for {x, > 0,xtarget} what is my xtarget. Think of x as time and I want to figure > when is the terminal time of the system such that some restrictions at > the terminal time are met. > > My first ideia was to adapt the above procedure, writing > > solution[xtarget_]:=NDSolve[...... > then giving the set of restrictions and then using FindRoot to get > xtarget, but Mathematica gives me an error message the xtarget is not > a real value. > > > My question is : > > Is it possible to adapt the procedure outlined above, meaning that > I'm just doing some kind of error here (that I'll have to correct), or > Mathematica does not handle this kind of problems directly in NDSolve > and I have to write some sort of loop with ever more refined guesses > for xtarget? > > My best regards > > Joao Pereira > I think what you are asking, boils down to the problem of how to find a root of f[x] when f[x], itself faults when x has no value - e.g. because it contains an NDSolve. The solution is to wrap f[x] in something that will prevent evaluation unless x is numeric - e.g. SetAttributes[g,HoldFirst]; g[x_?NumericQ]:=f[x] Now use g[x] inside FindRoot. David Bailey http://www.dbaileyconsultancy.co.uk