Re: NDSolve and InterpolatingFunction
- To: mathgroup at smc.vnet.net
- Subject: [mg56148] Re: NDSolve and InterpolatingFunction
- From: rknapp at wolfram.com
- Date: Sat, 16 Apr 2005 03:53:36 -0400 (EDT)
- References: <d3o06i$blo$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Virgil Stokes wrote: > I am solving the following system of ODE's > > g = 9.81 ; (* acceleration of gravity [m/s^2] *) > d = 0.063; (* diameter of ball [m] *) > m = 0.05; (* mass in kg *) > \[Rho] = 1.29; (* air density, [kg/m^3] *) > \[Alpha] = \[Rho] Pi d^2/(8 m) > > h = 1; (* initial height [m] *) > v0 = 25; (* magnitude of ball velocity [m/s] *) > \[Theta] = 15 (* initial angle of release [15 degrees] *) > > vars = {x[t], vx[t], z[t], vz[t]} > > initc = {x[0] == 0, vx[0] == v0*Cos[\[Theta] Degree], z[0] == h, > vz[0] == v0*Sin[\[Theta] Degree]} > > v[t] = Sqrt[vx[t]^2 + vz[t]^2]; > > eq1 = x'[t] == vx[t]; > eq2 = vx'[t] == -0.508 \[Alpha] vx[t] v[t]; > eq3 = z'[t] == vz[t]; > eq4 = vz'[t] == -g - 0.508 \[Alpha] vz[t] v[t]; > eqns = {eq1, eq2, eq3, eq4} > > sol = NDSolve[Join[eqns, initc], vars, {t, 0, 25}] > > which works fine; but how can I find (e.g. using Solve) the value of t > such that z[t] is 0; i.e, where, z[t] (in the > form of an InterpolatingFunction) is zero. > You won't be able to do it with Solve since the result in sol is a numerical approximation, not a symbolic function. FindRoot, however works just fine after running the commands you gave above, In[12]:= FindRoot[z[t] /. sol, {t,0,25}] Out[12]= {t->1.36201} In version 5.1, an even more convenient way to get the point at which z is zero is to use the EventLocator method: In[13]:= sol=NDSolve[Join[eqns,initc],vars,{t,0,25}, Method->{"EventLocator", "Event"->z[t], "EventAction":>(tzroot = t)}]; tzroot Out[13]= 1.36201 You will find documentation for EventLocator in the NDSolve AdvancedDocumentation: http://documents.wolfram.com/mathematica/Built-inFunctions/AdvancedDocumentation/DifferentialEquations/NDSolve/ODEIntegrationMethods/ControllerMethods/EventLocation.html Rob Knapp Wolfram Research