# Getting error when I substitute PDE for ODE

The following code works perfectly:

func[k_] :=
func[k] =
NDSolve[{
y'[t] == y[t] - z[t],
z'[t] == y[t] - k*z[t],
y[0] == 3, z[0] == 0},
{y, z}, {t, 0, 2}]
Manipulate[Plot[({
y[tt] /. func[k]
}),
{tt, 0, 2},
PlotLegends -> {y}],
{k, 0, 3, 0.5}
]


is a minimized version of the 1st answer of this post.

The problematic code:

func[k_] :=
NDSolve[{
y'[t, x] == y[t, x] - z[t, x],
z'[t, x] == y[t, x] - k*z[t, x],
y[0, x] == 3, z[0, x] == 0,
y[t, -2] == 0, z[t, -2] == 0,
y[t, 2] == 1, z[t, 2] == 0
},
{y, z}, {t, 1, 5}, {x, -2, 2}]

Manipulate[
DensityPlot[({y[tt, xx] /. func[l]}), {tt, 0, 5}, {xx, -2, 2}],
{l, 0, 3, 0.5}]


{func[0]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing"

The error keeps showing up when I try to change "the working" code as the "problematic" one.

There are many posts about this error here, I have read a plenty of them and tried their solutions but those did not solve my problem. I would appreciate if someone would points out

• why the error happened
• how to fix it?
• The first code example works in Mathematica v12 without error. Commented Sep 30, 2020 at 7:43
• @Ulrich Neumann, yes it works i thought i wrote, I edit my question. now its clear that it works. :) Commented Sep 30, 2020 at 7:57
• @LouisB I tried both, not worked unfortunately. Commented Sep 30, 2020 at 7:59
• y'[t, x], z'[t, x]  isn't a well defined Mathematica expression Commented Sep 30, 2020 at 8:08
• You are changing an ODE to PDE. It is correct to add boundary conditions as you did. However, the boundary condition may not contradict the initial conditions. E.e. the initial condition specifies that y[0,-2]==3. However, the boundary condition says y[0,-2]==0 Commented Sep 30, 2020 at 10:58

Y[k_] := NDSolveValue[{y'[t] == y[t] - z[t], z'[t] == y[t] - k*z[t],y[0] == 3, z[0] == 0}, y , {t, 0, 2}]