GLE Example: diffeq.gle

[PDF file]

 


size 10 8

include "graphutil.gle"

sub plotone x0 y0 cnt
   amove xg(x0) yg(y0)
   for i = 0 to cnt
      x0 = x0+y0*dt
      y0 = y0+(y0*(1-x0^2)-x0)*dt
      if (x0<-3) or (x0>3) or (y0<-3) or (y0>3) then
         i = cnt
      end if
      aline xg(x0) yg(y0)
   next i
end sub

sub plotall
   dt = 0.05
   set color gray40
   graph_line 0 -3 0 3
   graph_line -3 0 3 0
   set color rgb255(38,38,134)
   plotone -0.25 0 250
   plotone -0.1  0 250
   plotone  0.1  0 250
   plotone  0.25 0 250
   for j=0 to 3
      plotone -3  j 100
      plotone  3 -j 100
   next j
   for j=-3 to 3 step 0.25
      plotone -j  3 100
      plotone  j -3 100
   next j
end sub

set texlabels 1
begin graph
   scale  auto
   title  "2D differential equation"
   xtitle "$x$"
   ytitle "$y$"
   xaxis min -3 max +3
   yaxis min -3 max +3
   draw plotall
end graph

begin object key
   begin box add 0.1 fill white
      begin tex
         $\left\{ \begin{array}{l}
         \frac{dx}{dt}=y\vspace{0.2cm}\\
         \frac{dy}{dt}=-x+y(1-x^2)
         \end{array} \right.$
      end tex
   end box
end object

amove xg(xgmax) yg(ygmin)
draw key.br

 

[Return to examples page]