I am quite new to Mathematica and I guess this question is really basic, but I can't figure it out myself. I'm making a simple notebook that plots a Hamiltonian function, a plane of constant energy, and the phase space of the system. I highlight the intersection of the plane and the Hamiltonian, and I would like that the highlighted curve would show up as a red orbit in the phase plane. This is my code:
H[q_, p_, a_] := a q p + p^3 + q^2;
Qdot[q_, p_, a_] := Derivative[0, 1, 0][H][q, p, a];
Pdot[q_, p_, a_] := -Derivative[1, 0, 0][H][q, p, a];
Const[E_] := E;
Pbar[q_, a_, E_] := Evaluate[NSolve[H[q, p, a] == E, p, Reals]];
Manipulate[
{
ContourPlot3D[{H[q, p, a] == z, Const[E] == z}, {q, -qext,
qext}, {p, -pext, pext}, {z, -zext, zext},
MeshFunctions -> {0 &, 0 &, Const[E] - H[#1, #2, a] &},
MeshStyle -> {Blue, Thick}, Mesh -> {{0}},
ContourStyle ->
Directive[Gray, Opacity[0.5], Specularity[White, 60]]],
StreamPlot[{Qdot[q, p, a], Pdot[q, p, a]}, {q, -qext,
qext}, {p, -pext, pext},
StreamPoints -> {{200, {{qbar, Pbar[qbar, a, E]}, {Red, Thick}}},
0.1, 10}]
},
{E, -5, 5},
{a, -10, 10},
{qbar, -1, 1},
{qext, 1, 5},
{pext, 1, 5},
{zext, 0.01, 5}
]
So the problem is with Pbar: it is a function, so it returns p -> _number_, not _number_. I need it to return the number, because that way StreamPlot will highlight the streamline starting from {qbar, Pbar[qbar, a,E]}

Values@NSolve[..]. – Michael E2 Dec 27 '15 at 03:44StreamPoints, not in the replacement rules only.Pbarmust be a number without braces.Partmust be added if you useValues.Values@NSolve[ .. ][[1, 1]]– Dec 27 '15 at 12:56