Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Avoiding divide by zero error in NDSolve

  • To: mathgroup at smc.vnet.net
  • Subject: [mg62463] Re: Avoiding divide by zero error in NDSolve
  • From: Peter Pein <petsie at dordos.net>
  • Date: Fri, 25 Nov 2005 02:25:02 -0500 (EST)
  • References: <dm49jj$sul$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

pradeep suresh schrieb:
> Hi all,
> I am having this problem of mathematica not letting me specify the exact 
> intial values to a differential equation set. a simple example follws
> 
> Simple Mass Balance Equation set in Chemical Systems.
> 
> Nsp = 5;
> k1 = 100;
> For[i = 1, i < (Nsp + 1), i++, k2[i] = k1/Nsp];
> eqn1 = {D[M[t], t] == k1, M[0] == 0};
> eqn2 = Table[{D[M[t]y[i][t], t] == k2[i],y[i][0] ==k2[i]/k1},{i,Nsp}];
> var1 = Table[y[i][t], {i, Nsp}];
> var2 = Join[{M}, var1];
> sol=NDSolve[{eqn1,eqn2},var2,{t,0,10}]
> 
> Mathematica refuses to solve this system showing error messages of 
> encountering 1/0. If i change the initial condition of M to some 
> arbitrary nonzero value, it is able to solve this system although now 
> the set of equations are practically meaningless for me. Is there any 
> way i can retain the meaning of my equations and still get them solved 
> by mathematica? Plz advice!
> 
> Thanks & Happy thanksgiving,
> Pradeep
> 
Hi Pradeep,

eqn1 determines m as m[t]=k1 t. Substituting this into eqn2 leaves you 
with _very_ simple equations:
In[1]:=
nsp = 5; k1 = 100;
Do[k2[i] = k1/nsp, {i, nsp}];
msol = DSolve[{m'[t] == k1, m[0] == 0}, m, t][[1]]
Out[3]=
{m -> Function[{t}, 100*t]}
In[4]:=
eqn2 = Simplify[Flatten[
   {m'[t]*y[#][t]==k2[#], y[#][0]==k2[#]/k1}& /@ Range[nsp]] /. msol]
Out[4]=
{5*y[1][t] == 1, 5*y[1][0] == 1,
  5*y[2][t] == 1, 5*y[2][0] == 1,
  5*y[3][t] == 1, 5*y[3][0] == 1,
  5*y[4][t] == 1, 5*y[4][0] == 1,
  5*y[5][t] == 1, 5*y[5][0] == 1}

so y[i][t]==1/5, i=1..5

Regards,
   Peter


  • Prev by Date: Re: permutations
  • Next by Date: Re: problems with typesetting in packages
  • Previous by thread: Re: Re: Avoiding divide by zero error in NDSolve
  • Next by thread: Re: Avoiding divide by zero error in NDSolve