# "Spaghetti"-solutions for ODE nonautonomous system and reduced vector field

Projections of the 3-dimensional phase-space of a non-autonomous ODE system

Multidimensional obstacle avoidance in ODE (Visualization)

Given simple system of ODE:

$$\begin{cases} \dot{x}=g \\ \dot{o}=2 \cdot(-o+x) \\ \dot{g}=(1+\sin(3 t)) \cdot (-g+\frac{df}{do}) \\ \dot{h}=-h+\frac{d^2f}{d^2o} \end{cases}$$

where $$f = e^{-o^2}$$

It is not difficult to construct a 3D trajectory using the command ParametricPlot3D.

Clear["Derivative"]

ClearAll["Global*"]

pars = {xs = -1, k = (1 + 1 Sin[3 t])};

f = Exp[-(o[t])^2];

s = NDSolve[{x'[t] == g[t], o'[t] == 2 (-o[t] + x[t]),
g'[t] == k (-g[t] + D[f, {o[t], 1}]),
h'[t] == -h[t] + D[f, {o[t], 2}], x[0] == xs, o[0] == xs,
g[0] == 0.01, h[0] == 0}, {x, o, g, h}, {t, 0, 200},
MaxSteps -> \[Infinity]];

ParametricPlot3D[Evaluate[{o[t], g[t], h[t]} /. s], {t, 0, 200},
PlotPoints -> 100, ColorFunction -> (Hue[#4] &),
BoxRatios -> {1, 1, 1}, PlotRange -> Full]


Questions:

1. How to combine multiple solutions for different initial conditions on one ParametricPlot3D?
2. How to plot the final point on the ParametricPlot3D?
3. How to build a vector field around the trajectory?
• I suggest using ParametricNDSolveValue. Commented Jun 4, 2021 at 9:05
• @ΑλέξανδροςΖεγγ I have not used this command before. Could you demonstrate this and frame it as an answer?
– dtn
Commented Jun 4, 2021 at 9:08
• OK, please see my post below. Commented Jun 4, 2021 at 9:17
• Perhaps a caveat: I've thought about this problem, off and on, for several years — albeit not very seriously. But that means that probably many people have thought about this problem, some seriously, at least since good, fast, color graphics have been available. AFAICT, no one has thought of a good solution. Even 3D phase spaces, which are possible to visualize, are rarely done; that might change with the new StreamPlot3D. As the dimension increases, the projection down to 3D graphics (on a 2D display) loses more and more information. The system in the Q is 5D. Commented Jun 4, 2021 at 20:12
• @MichaelE2 At the moment, I decided to give up the idea of visualizing a vector field, but for now I will work with trajectories. It's enough. And yes, the task is much more difficult than I thought.
– dtn
Commented Jun 4, 2021 at 20:15

Several plots and the endpoints can be drawn by:

Clear["Derivative"]
ClearAll["Global*"]
pars = {xs = -1, k = (1 + 1 Sin[3 t])};
f = Exp[-(o[t])^2];
s = Table[
NDSolve[{x'[t] == g[t], o'[t] == 2 (-o[t] + x[t]),
g'[t] == k (-g[t] + D[f, {o[t], 1}]),
h'[t] == -h[t] + D[f, {o[t], 2}], x[0] == xs, o[0] == xs,
g[0] == g0, h[0] == 0}, {x, o, g, h}, {t, 0, 200},
MaxSteps -> \[Infinity]], {g0, 0, 4, 0.8}];
funs[t_] = {o[t], g[t], h[t]} /. (Transpose[s][[1]]);
end = funs[200];

Show[{
ParametricPlot3D[Evaluate[funs[t]], {t, 0, 200}, PlotPoints -> 100,
ColorFunction -> (Hue[#4] &), BoxRatios -> {1, 1, 1},
PlotRange -> Full],
Graphics3D[{PointSize[0.03], Point[end]}]
}]


If you want different colors for different trajectories you simply eliminate the ColorFunction command:

Show[{ParametricPlot3D[Evaluate[funs[t]], {t, 0, 200},
PlotPoints -> 100,
BoxRatios -> {1, 1, 1}, PlotRange -> Full],
Graphics3D[{PointSize[0.03], Point[end]}]}]


The velocity field is actually 4 dimensional and can not simply be drawn. What we can do is to draw velocity vectors along the trajectories:

velocities =
Table[Arrow[{{o[t], g[t],
h[t]}, {o[t], g[t], h[t]} + 0.5 {2 (-o[t] + x[t]),
k (-g[t] + D[f, {o[t], 1}]), -h[t] + D[f, {o[t], 2}]}}], {t,
0, 200}] /. (Transpose[s][[1]]) // Flatten;
Show[{
ParametricPlot3D[Evaluate[funs[t]], {t, 0, 200}, PlotPoints -> 100,
ColorFunction -> (Hue[#4] &), BoxRatios -> {1, 1, 1},
PlotRange -> Full],
PointSize[0.03], Point[end]}]
}]


• Thanks for answer! Yes, this is exactly the problem, and this caused difficulties for me too. Do I understand correctly that a vector field cannot be extended to the entire specified range? (ie so that the entire "cube" is filled with vectors).
– dtn
Commented Jun 4, 2021 at 9:06
• Don't you know how to assign a separate color to each curve?
– dtn
Commented Jun 4, 2021 at 9:26
• And another question, how to build the same graphs if several initial conditions are set not for one variable, but for several variables? For example: mathematica.stackexchange.com/questions/175253/…
– dtn
Commented Jun 4, 2021 at 9:27
• The velocity field changes with the time. Therefore, you would have to draw a vector field as a function of time, e.g. using Manipulate. I added how you could draw different colors for different trajectories. Commented Jun 4, 2021 at 9:30
• Let's try to look at a vector field with Manipulate.
– dtn
Commented Jun 4, 2021 at 9:31

The "final point" follows from

ode = {x'[t] == g[t], o'[t] == 2 (-o[t] + x[t]),g'[t] == k (-g[t] + D[f, {o[t], 1}]),h'[t] == -h[t] + D[f, {o[t], 2}]}
Reduce[ode/.   s_'[t] -> 0]
(*(g[t] == 0 && Sin[3 t] == -1 && h[t] == 2 E^-x[t]^2 (-1 + 2x[t]^2) &&o[t] == x[t]) || (x[t] == 0 && o[t] == 0 && h[t] == -2 && g[t] == 0)*)


FixedPoint: x[t]==0,o[t]==0,g[t]==0,h[t]==-2

• Yes, it's just solving a system of equations. The problem is how to beautifully place this point on Plots?
– dtn
Commented Jun 4, 2021 at 9:12
• Perhaps Show[{"your plot", Graphics3D[{Red,Point[{0,0,-2}]]}] Commented Jun 4, 2021 at 9:14
• Is it possible to do this automatically, without manually entering the fixed point?
– dtn
Commented Jun 4, 2021 at 9:18
• Calculate the fixpoint = {o[t], g[t], h[t]} /. Solve[ode /. s_'[t] -> 0, {x[t], o[t], g[t], h[t]}][[1]] (*{0, 0, -2}*) and use it Show[...,Point[fixpoint]... Commented Jun 4, 2021 at 9:24

With respect to 1., I suggest using ParametricNDSolveValue

Clear["Derivative"]
Clear[f, k, s]
f = Exp[-(o[t])^2];
k = (1 + 1 Sin[3 t]);
s = ParametricNDSolveValue[{x'[t] == g[t], o'[t] == 2 (-o[t] + x[t]),
g'[t] == k (-g[t] + D[f, {o[t], 1}]),
h'[t] == -h[t] + D[f, {o[t], 2}], x[0] == xs, o[0] == xs,
g[0] == 0.01, h[0] == 0}, {o[t], g[t], h[t]}, {t, 0, 200}, {xs},
MaxSteps -> \[Infinity]
]
ParametricPlot3D[s /@ {-1, -1.5, -2} // Evaluate, {t, 0, 200}, PlotPoints -> 100, BoxRatios -> {1, 1, 1}, PlotRange -> Full]

• Thank you very much.
– dtn
Commented Jun 4, 2021 at 9:21