Next: Equation Dialog Box Up: Typing Equations Previous: Variables and Parameters

## User-defined Functions

What does it do? You will often deal with equations that are just too complicated to fit on one line of the equation dialog box. In this case, you can define an auxiliary function that then appears on the right-hand side of a differential equation. Moreover, you may sometimes wish to plot functions related to solutions of differential equations, such as the difference in two variables. Again, a user-defined function gives you a variable to plot.

How do I use it? User-defined functions may be entered in any of the following ways:

f(x) = x^2+t
f() = x^2+t
f(t,x) = x^2+t
f = x^2+t

The thing to remember is that in the when a function is defined, the program ignores all text between the left parenthesis and the equal sign. Thus every user defined function may be considered to depend on t and all variables, including itself. Indeed, f(t) = f+t+x
is perfectly acceptable. In evaluation, the last expression would add the values of the variables t, x, and f at the last time step, and would then replace these in a new value of the variable f. On the other hand, one may not give arguments to a user defined function in the equation. For example, the expression y'=2*f(t+2) would generate a syntax error, but if f were defined, then the expressions f( ) = t+2 and y'=2*f would be acceptable.

User-defined functions are evaluated differently from variables. Each time an initial value solver, such as Runge-Kutta, is used, two passes are made in evaluating functions. First, all user defined functions are evaluated and stored, and then differential equations are evaluated using the updated function values. Thus f( ) = t^2 + 1
y'=-y+f
would evaluate a differential equation of the form y'=-y+t^2+1.

Kevin Cooper
Wed Sep 30 15:21:52 PDT 1998