# Solving an ODE and a PDE

I am trying to solve coupled sets of (partial) differential equations. For my ODE, I use

ti = 0;
tf = 5;
ri = 0;
rf = 1.5;
ai = 0;
af = 2;
sol[t_, x_, y_, z_,
a_] = {X[t, x, y, z, a], Y[t, x, y, z, a], Z[t, x, y, z, a]} /.
First[NDSolve[{ D[X[t, x, y, z, a], t] == Y[t, x, y, z, a] ,
D[Y[t, x, y, z, a], t] == Z[t, x, y, z, a]  + 3.5 t,
D[Z[t, x, y, z, a], t] == X[t, x, y, z, a] + 2 Sin[a t] ,
X[0, x, y, z, a] == Sin[x + y],
Y[0, x, y, z, a] == Sin[2 z + y],
Z[0, x, y, z, a] == Sin[x + 0.5 z]}, {X, Y, Z}, {t, ti,
tf}, {x, ri, rf}, {y, ri, rf}, {z, ri, rf}, {a, ai, af},
MaxSteps -> \[Infinity]]]; // AbsoluteTiming


This solves these equations. Here my question is how to put {x,y,z}, which are at the moment inside a cube, inside a particular manifold,e.q, inside a sphere with radius rf.

For {X,Y,Z}, I also should solve another set of partial differential equations. Here I implemented

sol[t_, x_, y_, z_,
a_] = {X[t, x, y, z, a], Y[t, x, y, z, a], Z[t, x, y, z, a]} /.
First[
NDSolve[{
D[X[t, x, y, z, a], t] ==
Y[t, x, y, z, a] + D[Z[t, x, y, z, a], y] + 0.5 t ,
D[Y[t, x, y, z, a], t] ==
Z[t, x, y, z, a] + D[X[t, x, y, z, a], z] ,
D[Z[t, x, y, z, a], t] ==
X[t, x, y, z, a] + D[Y[t, x, y, z, a], x] + 2 Sin[a t] ,
X[0, x, y, z, a] == Cos[a x + y],
Y[0, x, y, z, a] == Sin[z + y],
Z[0, x, y, z, a] == a Sin[x + z]}, {X, Y, Z}, {t, ti, tf}, {x,
ri, rf}, {y, ri, rf}, {z, ri, rf}, {a, ai, af},
MaxSteps -> \[Infinity],
Method -> {"MethodOfLines", "TemporalVariable" -> t,
"SpatialDiscretization" ->
"FiniteElement"}]]; // AbsoluteTiming


But this script is not fully correct as I get these errors

Do you have suggestions for resolving these issues?

The finite element method in Version 13.2 is available for 1D/1.5D/2D/2.5D and 3D plus time. Your problem is 4D plus time. For this use the tensor product grid method - like in your first example.

• (+1)Thanks! Replacing FiniteElement with TensorProductGrid solves the second problem. Do you have a suggestion for the first question as well? Feb 2 at 13:57
• @Shasa If you are thinking in terms of Element[ {x,y,z,a}, Ball[]], then no, the tensor product grid method is for rectangular domains. Feb 2 at 14:14
• I see! Thank you for your response. Feb 2 at 15:37

I am note sure if I understand this correctly: " how to put {x,y,z}, which are at the moment inside a cube". I assume you want to display the vector field inside a cube. The vector field may e.g. be displayed using SliceVectorPlot3D. But besides x,y,z you have 2 more variables t and a. This may be handled using "Manipulate" (note the plot is rather slow):

ti = 0; tf = 5; ri = 0; rf = 1.5; ai = 0; af = 2;
sol[t_, x_, y_, z_,
a_] = {X[t, x, y, z, a], Y[t, x, y, z, a], Z[t, x, y, z, a]} /.
First[NDSolve[{D[X[t, x, y, z, a], t] == Y[t, x, y, z, a],
D[Y[t, x, y, z, a], t] == Z[t, x, y, z, a] + 3.5 t,
D[Z[t, x, y, z, a], t] == X[t, x, y, z, a] + 2 Sin[a t],
X[0, x, y, z, a] == Sin[x + y],
Y[0, x, y, z, a] == Sin[2 z + y],
Z[0, x, y, z, a] == Sin[x + 0.5 z]}, {X, Y, Z}, {t, ti, tf}, {x,
ri, rf}, {y, ri, rf}, {z, ri, rf}, {a, ai, af},
MaxSteps -> \[Infinity]]];
Manipulate[
SliceVectorPlot3D[
sol[0, x, y, z, 0], {x, ri, rf}, {y, ri, rf}, {z, ri, rf},
PlotLabel -> {t, a}]
, {t, ti, tf}, {a, ai, af}]


For a slices sphere, you may write:

Manipulate[
SliceVectorPlot3D[sol[0, x, y, z, 0],
"CenterCutSphere", {x, -1, 1}, {y, -1, 1}, {z, -1, 1},
PlotLabel -> {t, a}], {t, ti, tf}, {a, ai, af}]


For additional possibilities, look at the help.

• In my examples, I used {x, ri, rf}, {y, ri, rf}, {z, ri, rf}, but in my first part of the question I was wondering about having sth like {x,y,z} \[Element] sphere? How to implement sphere or another manifold? Feb 2 at 13:48
• Look what I added. Feb 2 at 14:32
• (+1) Thank you for your effort. The answer of @user21 addresses my concern. Feb 2 at 15:38