# Projection of a 3D ODE solution on a parametric 2D streamplot

### Problem

I have a third-order dynamical system of which I'd like to plot the solutions on the streamplot defined by the same dynamical system, as a function of one of the three variables.

These are the equations:

\begin{align*} x^\prime &= (1 - z) (A (1 - x) - x)\\ y^\prime &= B - (1 - z) y\\ z^\prime &= z (1 - z) \end{align*} I would like to plot a projection of the trajectory on the (x, y) plane, as a function of the value the variable z assumes. I can treat z almost as it were a parameter, its solution being an invertible function of time.

### What I've done so far

Taking inspiration from here and here, I was able to plot the parametic streamplot (corresponding to stacks of the ideal 3D phase diagram as a function of z) and the solution of 3D dynamical system separately:

splot = Manipulate[StreamPlot[
{
(1 - z) (A (1 - x) - x),
B - (1 - z) y
},
{x, 0, 1}, {y, 0, 5}, StreamColorFunction -> "Rainbow",
StreamScale -> Large, StreamPoints ->Fine], {z, 0, 1}];

pplot = ParametricPlot3D[
Evaluate[
First[{x[t], y[t], z[t]} /.
NDSolve[
{
x'[t] == (1 - z[t]) (A (1 - x[t]) - x[t]),
y'[t] == B - (1 - z[t]) y[t],
z'[t] == z[t] (1 - z[t])
Thread[{x, y, z} == {0.1, 0, 0.01}]}, {x, y}, {t, 0, 10}]]],
{t, 0, 10}, PlotStyle -> Red];


How to superimpose splot and pplot, always being able to vary the value of z? Of course, Show[splot, pplot] does not work...

### What I would like to do

In summary, I'd like to obtain a 2D projection of the 3D solution of the dynamical system, and plot it onto a streamplot defined by the (x, y) field, as a function of the value the variable z assumes.

Thanks in advance for you help.

• Just try ParametricPlot3D and see what happens. – zhk Mar 20 '17 at 13:22
• Yes, with ParametricPlot3D I can get the 3D trajectory. Thanks! But still how to project it on the 2D streamplot? I still obtain "Could not combine the graphics objects in Show" – Orso Mar 20 '17 at 14:55
• How is this possible? Your 3D has x, y and z but in StreamPlot you have just x and y. – zhk Mar 20 '17 at 15:43
• Not sure if this is what you mean, but I had to remove any dependence from z in the streamplot if I wanted to obtain the plot. Ideally, I'd like to have the complete form that you can see in the NDSolve part in the streamplot, too. – Orso Mar 20 '17 at 15:58

Perhaps, this can motivate desired answer:

f[a_, b_, x_, y_, z_] := {(1 - z) (a (1 - x) - x), b - (1 - z) y,
z (1 - z)}
sol = ParametricNDSolve[{{x'[t], y'[t], z'[t]} ==
f[a, b, x[t], y[t], z[t]],
x == x0, y == y0, z == z0}, {x, y, z}, {t, 0, 10}, {a, b,
x0, y0, z0}];
s1 = Show[
ParametricPlot[
Evaluate[{x[1, 1, 0.3, 0.2, 0.1][t],
y[1, 1, 0.3, 0.2, 0.1][t]} /. sol], {t, 0, 10},
PlotRange -> {0, 10}, PlotStyle -> Red],
StreamPlot[f[1, 1, x, y, 0.1][[;; 2]], {x, 0, 10}, {y, 0, 10}],
Frame -> True, PlotLabel -> "z=0.1", ImageSize -> 300];
s2 = Show[
ParametricPlot[
Evaluate[{x[1, 1, 0.3, 0.2, 0.1][t],
y[1, 1, 0.3, 0.2, 0.1][t]} /. sol], {t, 0, 10},
PlotRange -> {0, 10}, PlotStyle -> Red],
StreamPlot[f[1, 1, x, y, 0.2][[;; 2]], {x, 0, 10}, {y, 0, 10}],
Frame -> True, PlotLabel -> "z=0.2", ImageSize -> 300];
p = ParametricPlot3D[
Evaluate[{x[1, 1, 0.3, 0.2, 0.1][t], y[1, 1, 0.3, 0.2, 0.1][t],
z[1, 1, 0.3, 0.2, 0.1][t]} /. sol], {t, 0, 10},
PlotRange -> {0, 10}, ImageSize -> 300];
Row[{s1, s2, p}] 