       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};
> eqn2 = Table[{D[M[t]y[i][t], t] == k2[i],y[i] ==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
>
> Thanks & Happy thanksgiving,
>

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