Instructions for using the Differential Equations Applet (JOde)

Go to the applet

Entering differential equations

Function reference

The following functions are available for use in expressions:
sin(x)
Returns sine of x.
cos(x)
Returns cosine of x.
tan(x)
Returns tangent of x.
artcan(x)
Returns inverse tangent of x.
arcsin(x)
Returns inverse sine of x.
abs(x)
Returns absolute value of x, i.e. x for x>=0 and -x for x< 0.
exp(x)
Returns the exponential of x.
ln(x)
Returns the natural logarithm of x.
sqrt(x)
Returns the square root of x for x>=0. If x< 0
min(x, y)
Returns x if x< y and y otherwise.
max(x, y)
Returns y if x< y and x otherwise.
step(x)
Returns 0 for x < 0 and 1 for x >= 0.
sgn(x)
Returns -1 for x < 0, 0 if x=0 and 1 for x > 0.
iffun(x, y, z)
Returns y for x is not equal to 0.0, z otherwise. Typically x is written as a logical expression (see operator reference). Note: This is a true function, i.e. it evaluates all its arguments (x, y, and z) before returning its value.

Mathematical constant reference

E
The base of natural logarithm.
PI
The circumference of a circle of diameter 1.
Infinity
Positive infinity.

Operator reference

In addition to the ordinary arithmetical operators +, -, *, /, the following operators are available for use in expressions:

x^y
Has a value of x raised to power y.
x < y
Has a value of 1.0 if x is less than y and 0.0 otherwise.
x <= y
Has a value of 1.0 if x is less or equal to y and 0.0 otherwise.
x > y
Has a value of 1.0 if x is greater than y and 0.0 otherwise.
x >= y
Has a value of 1.0 if x is greater or equal to y and 0.0 otherwise.
x == y
Has a value of 1.0 if x is equal to y and 0.0 otherwise.
x != y
Has a value of 1.0 if x is not equal to y and 0.0 otherwise.
x && y
Has a value of 1.0 if x and y are different from 0.0. Otherwise it has a value of 0.0.
x || y
Has a value of 1.0 if either x or y is different from 0.0. Otherwise it has a value of 0.0.
x; y
Has a value of y. The expression x is evaluated for its side effects. Typically x is an assignment, as in
k=7; k^3-k^2-1
Note: In logical expressions the value of 0.0 is equivalent to false and any value not equal to 0.0 is considered true. Logical operators return 1.0 when the logical expression is true. This resembles the convention used by languages like C and Java.

Plotting solutions for selected initial conditions

Click your mouse in the canvas area to select an initial condition. A solution passing through the indicated initial condition will be plotted. You can also select the initial condition precisely by typing in values of x and y. This method is described in this section.

Note: If there are more variables than 2, only two variables will be set based on the position of the mouse. The remaining variables will be set to 0.

Choosing abscissa and ordinate of the plot

If the number of variables is greater than 2 (including the independent variable) then you may select the variables that will be used as the abscissa and ordinate of the plot. This is done by pressing two choice buttons placed along the left and bottom edge of the plot and selecting one of the list of all variables.

Viewing solution tables

The applet tabulates numerical solutions of the differential equations. You can view tabulated values for each initial conditions in a window by clicking on the button labelled "Show table". A window entitled "Solution table" will pop up with all numerically generated solutions, in a form resembling tables in standard textbooks on numerical methods. One can use Cut-And-Paste to copy these tables into a text editor or word processor. The applet generates a solution table every time it recalculates the solution. Old solution tables can be erased by pressing the "Clear" button of the table window.

Setting ranges of variables

These are entered into areas labeled as "Min. x", "Max. x", "Min. y" and "Max. y" etc. They are not used in calculations, until they are entered by either pressing the Return key, or by pressing the "Submit All" button.

Setting the sizes of the grid

The sizes of the grid in the x- and y- and other directions are entered in areas marked as "Num. of segs" . They become effective upon either hitting the Return key (one item at a time) or by pressing the "Submit All" button, which updates all input related to entering the formula for dy/dx, the ranges and the number of grid intervals.

Zooming into a region

The right mouse button, on machines with 2 and 3 mouse buttons, or pressing the mouse button while the META key is depressed on machines with a single mouse button, will initiate a selection of a rectangle in the canvas. By dragging the mouse, the rectangular region is selected. When the mouse button is released, the range of the two coordinates is reduced to the selected triangle. The zoom operation can be undone by pressing middle mouse button on system with three mouse buttons (or where the "wheel" can be used as middle mouse button) or by pressing the ALT key simultaneously with the mouse button.

Display controls

Slopes
If checked, slopes are displayed.
Solutions
If checked, solutions with selected initial conditions are displayed.
Init. Conditions
If checked, every initial condition is marked and labeled.
Euler/ModifiedEuler/Midpoint/Runge-Kutta/RK4/Runge-Kutta-Fehlberg/RKF
Selects the algorithm used in calculating solutions.
Step
Displays and sets the integration step. Integration step is set automatically in the following circumstances: The automatic setting is calculated by dividing the range of the independent variable by the number of intervals. The automatic setting of the step can be overridden, though, by filling in the value of the step and hitting the Return key.

Adding initial conditions

The Applet maintains a list of initial conditions whose solutions will be plotted. You can:

Displaying tables of solutions

All solutions displayed by the applet can be tabulated by pressing the "Show table" button in the initial condition entry group of buttons. Tables are displayed in a separate window. The table can be edited or copied into another application (e.g. text editor). This is achieved by first selecting the data to be copied (typically with a mouse) and then with the usual Control-C (Cut) and Control-V (Paste) key combination, or other system-specific Cut/Paste keys. The table data can also be printed directly from the applet by selecting "Pring" from the "File" menu. Further necessary information on printing from the applet is contained in this section.

Printing

The page containing the Applet can be printed with all major browsers. However, there are some browser peculiarities.

Microsoft Internet Explorer

The default security settings do not allow unsigned applets to print. In order to print from the applet in Internet Explorer 5.5, one has two methods:

If you simply use the browsers "Print" button to print the version of the Applet embedded into the Web page, Internet Explorer will initialize the Applet before printing, and thus any changes, initial conditions, etc. will be lost. Therefore you must use the framed version of the Applet and select "Print" from the "File" menu of the Applets's window. You must also accept my security certificate when the Applet loads first by pressing OK when this dialog pops up.

Netscape

Netscape will correctly print the Applet embedded into the Web page . However, at least some versions (4.51) of the Communicator will crash if you try to print from the framed version. Thus, you should use the embedded version. Unfortunately, the embedded Applet cannot be resized without editing the containing Web page. In order to enable printing in the framed version, you should

Appletviewers

You can also print the Applet using Sun's appletviewer. Microsoft viewer JView does not allow printing.

Editing HTML

Another approach to printing is by editing the Applet's page with a text editor to enter the Applet parameters directly. Just edit the Applet's Web page with your favorite HTML editor or a text editor (my preferred way).

Errors

These are typically generated by typing in an expression (see "Entering Differential Equation" section) which does not conform to the syntax rules of the Applet. The most recent error message appears in the box labeled "Last error". It will hopefully identify the problem by pointing to the column in which the first error occurs. If not, by pressing the button labelled "Show All Errors" all error messages can be examined and used to correct the problem.

Advanced Topic: Downloading and running the Applet locally

You can download in a directory of your choice on your local machine. This Jar file contains all the necessary Java classes to run the applet. The entire package can be also downloaded as a zip archive. After downloading, make a new directory (UNIX users) or folder (Windows, Mac users) where you want the applet files to reside. Move the downloaded file into that directory or folder and unzip it there. In order to run the applet, you must add the Jar file to your Java CLASSPATH. Windows 95/98 users would probably do it in their AUTOEXEC.BAT file. UNIX users and Windows NT users would set the environment variable. You can also run the Java applet as an application, if you have a stand-alone Java interpreter. The syntax for running the applet is:
java -classpath=directory_prefix/(or\)JOdeApplet.jar JOde "dimension=2" "autonomous=true" ...

Advanced Topic: Controlling the Applet from HTML with parameters

All settings of the Applet can be set in the containing HTML document by passing parameters to the Applet. Currently, the applet recognizes these parameters, corresponding closely to the quantities which can be set from the graphical user interface (GUI).

Advanced Topic: Precedence of operators

The precedence of operators closely resembles that of C or Java. The following table lists operators according to precedence, highest precedence first:

Advanced Topic: User-defined functions and flow-control statements

User-defined functions

The applet supports user defined functions, conditionals and flow-control. They may be defined in equation #0 or in any other equation. For instance,
 C=7; function f(x, y) = x + y + C
defines a function which, when called with two arguments, returns their sum plus 7. It is worth noting that every statement of the JOde language is an expression. Function definition expression above returns a value of 0 when evaluated. The function is defined as a side effect.

Semi-colon

Semi-colon (;) is used as a separator in expressions. The resulting sequence of expressions is evaluated in order and the value of the last espression is returned. For example
x=1; y=2; x+y
is an expression whose value is 3.

Conditionals

JOde language supports the "if" statement. For instance, the following expression
x=2; if(x<3) 7 else 1
returns 7.

Loops

JOde language supports the "while" statement. If the body of the while loop is not evaluated, the value returned is 0. Otherwise, the value is that of the last evaluation of the body. For instance,
x=1; while(x<10) x=x+2
evaluates to 11. JOde supports " continue" and "break" statements in a way similar to C and Java. However, "continue" and "break" with no argument causes the value of the entire loop to be 0. If given an argument to " break", the entire loop evaluates to that argument. If "continue" is called with an argument, and the next test evaluates to false (i.e. 0.0) then the value of the entire loop will be the value given as an argument to "continue". Thus
x=1; while(x<10) x=x+2; if(x==5) break x
returns 5 and
x=1; while(x<10) x=x+2; if(x==5) break
return 0. In the following example:
x=1; while(x<2) if(x==1) x=3; continue 7; 5 
the value of the expression is 7. The semi-colon has very low precedence, and thus in the following example
x=1; while(x<2) if(x==1) x=3; continue (7; 5) 
the return value is 5 because of the explicit parenthesis.

 Go to the applet

Enjoy,

Marek Rychlik (rychlik@u.arizona.edu)