# NDSolve Problem

I am trying to solve a chemical equilibrium ODE with NDSolve where one function is the argument to another.

I.E. My equations look like:

A'[t] == B[t] + f[A[t]] C[t],
B'[t] == ...,
C'[t] == ...


This is the actual code:

sol = NDSolve[{
T'[t] == -((uCO[T[t]] nCO'[t] + uO[T[t]] nO'[t] + uO2[T[t]] nO2'[t] + uCO2[T[t]] nCO2'[t])/(CvCO[T[t]] nCO[t] + CvO[T[t]] nO[t] + CvO2[T[t]] nO2[t] + CvCO2[T[t]] nCO2[t])),
nCO'[t] == -nCO[t] nO[t] m[t] r1[T[t]] - nCO[t] nO2[t] r2[T[t]] + nCO2[t] m[t] r1b[T[t]] + nCO2[t] nO[t] r2b[T[t]],
nO'[t] == -nCO[t] nO[t] m[t] r1[T[t]] + nCO[t] nO2[t] r2[T[t]] - 2 nO[t] nO[t] m[t] r3[T[t]] + nCO2[t] m[t] r1b[T[t]] - nCO2[t] nO[t] r2b[T[t]] + 2 nO2[t] m[t] r3b[T[t]],
nO2'[t] == -nCO[t] nO2[t] r2[T[t]] + nO[t] nO[t] m[t] r3[T[t]] + nCO2[t] nO[t] r2b[T[t]] - nO2[t] m[t] r3b[T[t]],
nCO2'[t] == nCO[t] nO[t] m[t] r1[T[t]] + nCO[t] nO2[t] r2[T[t]] - nCO2[t] m[t] r1b[T[t]] - nCO2[t] nO[t] r2b[T[t]],
m'[t] == nCO'[t] + nO'[t] + nO2'[t] + nCO2'[t],
T[0] == 1500,
nCO[0] == nCOinit,
nO[0] == 0.,
nO2[0] == nO2init,
nCO2[0] == 0.,
m[0] == nCOinit + nO2init
},
{T, nCO, nO, nO2, nCO2, m},
{t, 0.00, 1.00},
MaxSteps -> 300000
]


The problem is that my functions:

CvCO2, CvCO, CvO, CvO2, uCO2, uCO, uO2, uO, r1, r2, r3, r1b, r2b, r3b


can only take a numeric value argument.

Mma spits our many errors due to that...

Any idea how to solve this problem?

f[x_ ? NumericQ] := ...

• @JonathanRoy You need to clear them first, otherwise both definitions persist (check it using ?f). So evaluate Clear[f]. But since you have so many, just start with a fresh kernel (Evaluation -> Quit Kernel) to test this. Mar 9, 2012 at 19:22
• @Jonathan Whenever I have a function that has a not-totally-general pattern, such as f[x_?NumericQ], I precede the definition with Clear[f]. This way I make sure that when I change the definition (and possibly change the patter as well), I won't end up with several coexisting definitions that I don't want. It's useful to make this a habit. Mar 9, 2012 at 19:36