Example of phase plain created by ode solving, contour lines (cont) and flow threads.
MGL code:
subplot 2 2 0 '<_':title 'Cont':box
axis:xlabel 'x':ylabel '\dot{x}'
new f 100 100 'y^2+2*x^3-x^2-0.5':cont f
subplot 2 2 1 '<_':title 'Flow':box
axis:xlabel 'x':ylabel '\dot{x}'
new fx 100 100 'x-3*x^2'
new fy 100 100 'y'
flow fy fx 'v';value 7
subplot 2 2 2 '<_':title 'ODE':box
axis:xlabel 'x':ylabel '\dot{x}'
for $x -1 1 0.1
ode r 'y;x-3*x^2' 'xy' [$x,0]
plot r(0) r(1)
ode r '-y;-x+3*x^2' 'xy' [$x,0]
plot r(0) r(1)
next
C++ code:
void smgl_ode(mglGraph *gr)
{
gr->SubPlot(2,2,0,"<_"); gr->Title("Cont"); gr->Box();
gr->Axis(); gr->Label('x',"x"); gr->Label('y',"\\dot{x}");
mglData f(100,100); gr->Fill(f,"y^2+2*x^3-x^2-0.5");
gr->Cont(f);
gr->SubPlot(2,2,1,"<_"); gr->Title("Flow"); gr->Box();
gr->Axis(); gr->Label('x',"x"); gr->Label('y',"\\dot{x}");
mglData fx(100,100), fy(100,100); gr->Fill(fx,"x-3*x^2"); gr->Fill(fy,"y");
gr->Flow(fy,fx,"v","value 7");
gr->SubPlot(2,2,2,"<_"); gr->Title("ODE"); gr->Box();
gr->Axis(); gr->Label('x',"x"); gr->Label('y',"\\dot{x}");
for(double x=-1;x<1;x+=0.1)
{
mglData in(2), r; in.a[0]=x;
r = mglODE("y;x-3*x^2","xy",in);
gr->Plot(r.SubData(0), r.SubData(1));
r = mglODE("-y;-x+3*x^2","xy",in);
gr->Plot(r.SubData(0), r.SubData(1));
}
}