# Coupled ODEs/PDEs with functional initial(boundary?) conditions

I am trying to numerically solve the following coupled DEs:

$$\frac{d f(t) }{d t} =-f(t); f(0)=1; \frac{\partial g(t,\tau)}{\partial \tau}=-g(t,\tau); g(t,0)=f^2(t)$$

It is easy to solve by hand

$$f(t)=e^{-t}; g(t,\tau)=e^{-2t -\tau}$$

However I am having trouble solving it in Mathematica. I followed this solution and used the following code:

fSol = NDSolve[{D[f[t], t] == -f[t], f == 1}, f[t], {t, 0, 5}];
ff[t_] := f[t] /. fSol
gSol = NDSolve[{D[g[t, \[Tau]], \[Tau]] == -g[t, \[Tau]],g[t, 0] == ff[t]*ff[t]}, g[t, \[Tau]], {\[Tau], 0, 5}]


But the second NDSolve gave me the following error

NDSolve::ndinnt: Initial condition {<<1>>^2} is not a number or a rectangular array of numbers.


What can I do to resolve this?(In the end I would like to generalize this to two systems of DEs instead of just two DEs as shown here but I imagine the solution would be similar)

• initial conditions to NDSolve has to be numeric. Change to g[t, 0] ==t and you'll get same error. – Nasser Jun 9 at 6:24
• In the solution I linked, it seems the initial condition doesn't have to be numeric? There the poster gave u[t, 0] == 5*ff[t] as part of the conditions for u[t,x], where ff[t] is a function solved numerically previously. It worked there, why not here? – Lezhi Lo Jun 9 at 7:34
• Sorry, I did not even look at the linked question. I only tried what you have. Will have a look at the linked question now and see why it worked there if I can figure it out. – Nasser Jun 9 at 7:41

To get your solution to work, and avoid the error Initial condition {<<1>>^2} is not a number or a rectangular array of numbers you need to also give the range of t, like this

fSol = NDSolve[{D[f[t], t] == -f[t], f == 1}, {f}, {t, 0, 5}][];
ff = f /. fSol;

gSol = NDSolve[{D[g[t, τ], τ] == -g[t, τ], g[t, 0] == ff[t]*ff[t]}, g,
{τ, 0, 5}, {t, 0, 5}] Becuase now after adding {t, 0, 5} to the second NDSolve, it is happy, since it can evaluate ff[t]*ff[t] as numbers. Without this, you get the error you had.

And it is better to use f instead of f[t] when using NDSolve