Phase Portrait Example

Example 1

f[x_,y_]:=Exp[x+y]*(x+y);
g[x_,y_]:=Exp[x+y]*(x-y);

Basic Phase Portrait

lb=-3;
ub=3;
plot1=StreamPlot[{f[x,y],g[x,y]},{x,lb,ub},{y,lb,ub},PlotRange->{{lb,ub},{lb,ub}},FrameLabel->{"x","y"},LabelStyle->Directive[Black,Bold, Medium]];
plot2=ContourPlot[f[x,y]==0,{x,lb,ub},{y,lb,ub},ContourStyle->{Thick,Red}];
plot3=ContourPlot[g[x,y]==0,{x,lb,ub},{y,lb,ub},ContourStyle->{Thick,Blue}];
Show[plot1,plot2,plot3]

Example 2

f[x_,y_]:=y+x*Cos[x];
g[x_,y_]:=-Sin[x];

Basic Phase portrait

lb=-3;
ub=3;
plot1=StreamPlot[{f[x,y],g[x,y]},{x,lb,ub},{y,lb,ub},PlotRange->{{lb,ub},{lb,ub}},FrameLabel->{"x","y"},LabelStyle->Directive[Black,Bold, Medium]];
plot2=ContourPlot[f[x,y]==0,{x,lb,ub},{y,lb,ub},ContourStyle->{Thick,Red}];
plot3=ContourPlot[g[x,y]==0,{x,lb,ub},{y,lb,ub},ContourStyle->{Thick,Blue}];
Show[plot1,plot2,plot3]
Clear[lb,ub]

Phase portrait with single limit cycle

lb=-3;
ub=3;
plot1=StreamPlot[{f[x,y],g[x,y]},{x,lb,ub},{y,lb,ub},PlotRange->{{lb,ub},{lb,ub}},FrameLabel->{"x","y"},LabelStyle->Directive[Black,Bold, Medium]];
plot2=ContourPlot[f[x,y]==0,{x,lb,ub},{y,lb,ub},ContourStyle->{Thick,Red}];
plot3=ContourPlot[g[x,y]==0,{x,lb,ub},{y,lb,ub},ContourStyle->{Thick,Blue}];
sol=NDSolve[{x'[t]==f[x[t],y[t]],y'[t]==g[x[t],y[t]],x[0]==y[0]==1},{x,y},{t,20}];
plot4=ParametricPlot[Evaluate[{x[t],y[t]}/.sol],{t,0,20},PlotStyle->Black];
Show[plot1,plot2,plot3,plot4]
Clear[lb,ub]

Phase portrait with multiple limit cycles

lb=-20;
ub=20;
plot1=StreamPlot[{f[x,y],g[x,y]},{x,lb,ub},{y,lb,ub},PlotRange->{{lb,ub},{lb,ub}},FrameLabel->{"x","y"},LabelStyle->Directive[Black,Bold, Medium]];
plot2=ContourPlot[f[x,y]==0,{x,lb,ub},{y,lb,ub},ContourStyle->{Thick,Red}];
plot3=ContourPlot[g[x,y]==0,{x,lb,ub},{y,lb,ub},ContourStyle->{Thick,Blue}];
sol=NDSolve[{x'[t]==f[x[t],y[t]],y'[t]==g[x[t],y[t]],x[0]==y[0]==1},{x,y},{t,20}];
plot4=ParametricPlot[Evaluate[{x[t],y[t]}/.sol],{t,0,20},PlotStyle->Black];
sol=NDSolve[{x'[t]==f[x[t],y[t]],y'[t]==g[x[t],y[t]],x[0]==y[0]==5},{x,y},{t,100}];
plot5=ParametricPlot[Evaluate[{x[t],y[t]}/.sol],{t,0,100},PlotStyle->Black];
sol=NDSolve[{x'[t]==f[x[t],y[t]],y'[t]==g[x[t],y[t]],x[0]==y[0]==10},{x,y},{t,100}];
plot6=ParametricPlot[Evaluate[{x[t],y[t]}/.sol],{t,0,100},PlotStyle->Black];
Show[plot1,plot2,plot3,plot4,plot5,plot6]

Example 3

f[x_,v_]:=v;
g[x_,v_]:=Sin[x];

Basic Phase portrait

lb=-2*π;
ub=2*π;
plot1=StreamPlot[{f[x,v],g[x,v]},{x,lb,ub},{v,lb,ub},PlotRange->{{lb,ub},{lb,ub}},FrameLabel->{"x","y"},LabelStyle->Directive[Black,Bold, Medium]];
plot2=ContourPlot[f[x,y]==0,{x,lb,ub},{y,lb,ub},ContourStyle->{Thick,Red}];
plot3=ContourPlot[g[x,y]==0,{x,lb,ub},{y,lb,ub},ContourStyle->{Thick,Blue}];
Show[plot1,plot2,plot3]
Clear[lb,ub];

Comparison with contour plot of Hamiltonian

H[x_,v_]:=1/2*v^2+Cos[x];

lbx=-2*π;
ubx=2*π;
lbv=-3;
ubv=3;
ContourPlot[H[x,v],{x,lbx,ubx},{v,lbv,ubv},FrameLabel->{"x","y"},LabelStyle->Directive[Black,Bold, Medium],PlotRange->{{lbx,ubx},{lbv,ubv}},Contours->30]
Clear[lbx,ubx,lbv,ubv]