# Using NDSolve on a vector-valued PDE

I would like to use NDSolve to evaluate a PDE involving a vector valued function. For instance, I'm looking for something like a heat equation with vector-valued boundary conditions:

NDSolve[{D[u[t, x], t] == D[u[t, x], x, x], u[0, x] == {1,0},
u[t, 0] == {Cos[t],Sin[t]}, u[t, 5] == {1,0}}, u, {t, 0, 10}, {x, 0, 5}]


When I try this I get several error messages:

Thread::tdlen: Objects of unequal length in {0,0} {1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,1.} cannot be combined.

NDSolve::vlen: "The vector {0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.} and the weight vector {0.,0.} are of unequal lengths. "

NDSolve::ndnum: Encountered non-numerical value for a derivative at t == 0.


How do I get around this? I'd like to avoid using different equations for each component function of $u$.

Apologies if I'm missing something simple—I'm still a beginner and I've searched for a solution for some time without success.

u[t_, x_] := {u1[t, x], u2[t, x]};


This tells M all u's in the code are vectors:

eq = {D[u[t, x], t] == D[u[t, x], {x, 2}], u[0, x] == {1, 0},
u[t, 0] == {Cos[t], Sin[t]}, u[t, 5] == {1, 0}};
NDSolve[eq, u[t, x], {t, 0, 10}, {x, 0, 5}]


Update: For plotting, might be easier to use {u1,u2} instead of {u1[t,x],u2[t,x]}. Hence the above becomes

u[t_, x_] := {u1[t, x], u2[t, x]};
eq = {D[u[t, x], t] == D[u[t, x], {x, 2}], u[0, x] == {1, 0},
u[t, 0] == {Cos[t], Sin[t]}, u[t, 5] == {1, 0}};
sol = First@NDSolve[eq, {u1, u2}, {t, 0, 10}, {x, 0, 5}]


Not can do things like

Plot[{(u1 /. sol)[t, 0], (u2 /. sol)[t, 0]}, {t, 0, 2 Pi}, PlotTheme -> "Detailed"]


 ParametricPlot[{(u1 /. sol)[t, 0], (u2 /. sol)[t, 0]}, {t, 0, 2 Pi}]


• That works perfectly! Thanks a ton, Nasser. Nov 30, 2014 at 7:32
• I didn't include this in the question, but if there's a simple answer, would you mind letting me know how to plot the solution parametrically in $t$ for fixed $x$? The naive ParametricPlot[u[t,0] /. heat, {t, 0, 2 Pi}]` doesn't seem to do it. I should have put this in the question as it's my ultimate objective (and I can open another question), but I thought it would follow easily. Nov 30, 2014 at 8:47
• @NickStrehlke added plot. Not sure if this is what you are looking for. Nov 30, 2014 at 9:10
• That's right along the lines of what I was looking for. Thanks again for your help! Nov 30, 2014 at 18:21