Plotting Direction Fields and Trajectories

WARNING you are NOT running inside netmath so you cannot edit the plots nor click to produce them.

The highlighted regions of this tutorial are sensitive to double clicking with the left mouse button. Use the arrow keys to move up or down in the tutorial.

The first thing we wish to do is plot direction fields and then
trajectories which represent solutions. If you have trouble look for
the section on trouble below. For a differential equation in two
variables, the variables are presumed to be y and x,
with the differential being dy/dx

plotdf -ode {d(y,x)=2*y-sin(x)}

To plot an orbit click with mouse (left button) on the plot window, and a trajectory through the point where you click will be computed.

dy/dx  = 2 y - sin(x)

After you have calculated some trajectories, you may save or print the plot. See the 'Save' or 'Print' button on the bar at the top of the plot. You may configure the print or save by using the 'Config' button.

To plot a solution which you have computed by hand or by symbolic methods on the same graph as the above you can do

plotdf -ode {d(y,x)=-y+5*sin(2*x)} -xfun {sin(2*x)-2*cos(2*x) + 3* exp(-x)} -xradius 6 -xcenter 4 -yradius 3 -doTrajectoryAt {0.0 1.0}

A differential equation involving x,y,and t may also be entered, and things like the xrange specified

plotdf -ode { D(x,t)= y; D(y,t)= -2*sin(x) + 0.1* y} -xradius 4 -tinitial 0.0 -tstep .1

Note that the values of D(x,t) and D(y,t) must be independent of t,
since otherwise the vector field could not be drawn (it would depend
on time!). Many natural physical problems do have equations where the
right side is independent of 't'. The numerical methods however are
valid for the case where the right side does involve 't'.

You may alter the text in these expressions and then reclick. For
example you might change sin to cos. For the above example notice how
the trajectories in the top part of the plane.

plotdf -ode {d(y,x)=log(abs(y))+2*x*exp(2*x)}
The list of functions recognized is

. Syntax is like that of C except that we use a^b to denote a raised to the b power, ie pow(a,b).

To see an ode with a non unique solution, we could look at

dy/dx =y**(1/3).

However dfplot will interpret the third root as the real part of the first of the 3 complex roots, which will always be positive. If we want the real root which is negative when y is negative, then we have to be a little fancier and use a conditional to consider the case of y>0 and y<0

  (y > 0 ? 1 : -1)*abs(y)**(1/3.0)


plotdf -ode {d(y,x)=(y > 0 ? 1 : -1)*abs(y)**(1/3.0)}

Try clicking very close to the horizontal line in the middle. Can you get the horizontal y=0 solution? Doesn't seem very stable there does it..?

Right now we are using the Adams-Moulton predictor corrector method.