# Extracting a streamline from StreamPlot

The following function generates a stream plot for t1 and t2.

StreamPlot[{k, (-L1 k Sin[t1[t]])/(L2 Sin[t2[t]])},
{t1[t], -Pi/2, Pi/2}, {t2[t], -Pi/2, Pi/2}


I know that each streamline gives me a set of values of t1 and t2 for which

L1 Cos[t1[t]] + L2 Cos[t2[t]] == rvar


is constant, for any values of L1 and L2.

I want to extract the values of a streamline for a particular value of rvar. How can I do this?

A solution for the differential equation is also something that can help. Thanks

• Have a look at StreamPoints. – rmw Sep 23 '18 at 14:19

Another approach is to use ContourPlot. For instance,

cp = With[{L1 = 1, L2 = 3, rvar = 3},
ContourPlot[L1 Cos[t1[t]] + L2 Cos[t2[t]] == rvar,
{t1[t], -Pi/2, Pi/2}, {t2[t], -Pi/2, Pi/2}, ContourStyle -> Red,
FrameLabel -> Automatic, ImageSize -> Large, LabelStyle -> {Black, Bold, Medium}]] and the values of the points making up the curve are given by

pts = cp[[1, 1]];


which can be visualized by

ListPlot[pts, ImageSize -> Large, LabelStyle -> {Black, Bold, Medium}] Just use NDSolve. It is meant precisely for this, i.e. numerical solution of differential equations. StreamPlot is for plotting and won't be accurate anyway.

• I tried using that, but I'm unable to put it in the correct form i think. How can i put two variables as such? – Ashwin Kumar Sep 23 '18 at 14:38

Here is an NDSolveValue approach. First, some example parameters:

L1 = 1;
L2 = 3;
rvar = 3;


eqn = L1 Cos[t1[t]]+L2 Cos[t2[t]]==rvar


To use NDSolveValue, we need an initial condition, for which I will use FindInstance:

initial = {t1[t], t2[t]} /. First @ FindInstance[
{eqn, -π < t1[t] < π, -π < t2[t] < π},
{t1[t], t2[t]},
Reals
]


{-π/2, 0}

We have two dependent variables, so we need another ODE. The obvious choice is to parametrize by the arc-length. So, the ODE is:

sol = NDSolveValue[
{
eqn, t1'[t]^2 + t2'[t]^2 == 1,
t1 == initial[], t2 == initial[],
WhenEvent[EuclideanDistance[{t1[t],t2[t]}, initial]<.002, end = t; "StopIntegration"]
},
{t1, t2},
{t, 0, 18}
];


Probably a better detector of when the solution overlaps itself could be used, but the above did the job.

Visualization:

plot = ParametricPlot[Through @ sol @ t, {t, 0, end}] And a table of values:

pts = Table[Through @ sol @ t, {t, Subdivide[0, end, 30]}];


Visualization:

Show[plot, ListPlot[pts, PlotStyle->Red]] 