Re: Solving Ordinary differential equations by NDSolve
- To: mathgroup at smc.vnet.net
- Subject: [mg104983] Re: [mg104962] Solving Ordinary differential equations by NDSolve
- From: Pratip Chakraborty <pratip.chakraborty at gmail.com>
- Date: Sun, 15 Nov 2009 20:48:59 -0500 (EST)
- References: <200911151055.FAA09206@smc.vnet.net>
Hi, There is nothing to be panicked about the complex values of V. Just use Chop to get rid of the complex tail which is nothing but a artifact generated during numerical computation. You can see it yourself Plot[Evaluate[V[t]/.sol//Chop]*1000,{t,0,9},PlotRange->All] Grid[Table[{t,v[t]//Chop},{t,0,9,1}]] And also to see the residual error of the solution generated by NDSolve evaluate the following Er=(V'[t]==A Sqrt[2 (Po (V0/V[t])^gamma-Pa)/rho])/.a_==b_-> (a-b)^2/.V[t]-> v[t]/.V'[t]-> v'[t]; Grid[Table[{t,Er//Chop},{t,0,9,1}]] Now you will realize that there is nothing wrong with the solution. Regards, Pratip On Sun, Nov 15, 2009 at 11:55 AM, Allamarein <matteo.diplomacy at gmail.com>wrote: > I'd solve this ODE: > > V'[t] == A Sqrt[2 (Po (V0/V[t])^gamma - Pa)/rho > IC: V[0] == V0 > > I wrote this code: > > d = 2*10^-2 ; > A = d^2 3.14/4; > Po = 5 *101325; > Pa = 1*101325 ; > rho = 1000 ; > V0 = 5*10^-3 ; > gamma = 1.14; > sol = NDSolve[{ > V'[t] == A Sqrt[2 (Po (V0/V[t])^gamma - Pa)/ rho], > V[0] == V0}, > {V}, {t, 0, 9}, > MaxSteps -> 1000000, AccuracyGoal -> 10, PrecisionGoal -> 10]; > v[t_] := V[t] /. sol[[1]]; > Plot[Evaluate[V[t] /. sol]*1000, {t, 0, 9}, PlotRange -> All] > Grid[Table[{t, v[t]}, {t, 0, 9, 1}]] > > If it can be useful, I can underline units of these variables: > d [m] > P0, Pa [Pa] > rho [kg/m^3] > V [m^3] > gamma [--] > t [sec] > > Running this code, V has got comlex part. This is impossible, because > it's a volume. > I should re-write my ODE in order NDSolve can digest better or I can > set an option in my code where I suggest " V must be positive and > real"? > >
- References:
- Solving Ordinary differential equations by NDSolve
- From: Allamarein <matteo.diplomacy@gmail.com>
- Solving Ordinary differential equations by NDSolve