Return to the home page.

The Ultimate Windows Math Toolbox

 


bullet Ver 3.1.805
8 September 2008
bullet Free support
bullet Only $44.85 (US)
(Professional)
Click to buy UltimaCalc Professional
bullet Only $34.85 (US)
(Standard)
Click to buy UltimaCalc Standard.

bullet Free download

<<< Prev  Next >>>
Algebra - Introduction   

 

User-defined Functions

Algebra UltimaCalc provides two methods of defining your own functions - by direct entry, or by using an editor.

Direct Entry

The simple way to define a function is by typing its definition into the input window.

Example:
divide(x, y):= x/y defines a trivial function that takes two arguments and returns the result of dividing the first argument by the second. Having entered this definition, the expression divide(a^3, a) returns the value a^2.

User-defined functions can be viewed by clicking on the 'Symbols'button on the Algebra window. This opens a window that shows all user-defined functions and all symbols to which values have been assigned. This window also allows editing and creation of user-defined functions.


Using the Function Editor

To open the function editor, click on the 'Symbols' button to view all user-defined functions and symbols which have values. If you click in this window with the mouse's right-hand button, a menu pops up. This menu always has an item to allow you to create new user functions. If the mouse pointer was over a previously-defined function, you will have the option of editing the function.

If you choose to create a new function, the editor window is as shown below. (If you are editing an existing function, the window is similar, but it will not allow you to change the function's name.).


Function Editor


Enter the name of the function into the first edit box. Into the next box, labelled 'Parameters', type a list of the symbols to be used to name the arguments, separating each symbol with a comma. In the 'Function Definition' box, enter the expression(s) to be evaluated when the function is executed. When ready, click on the 'OK' button to have the function created.

The 'Open...' and 'Save...' buttons allow the function definition to be saved as a plain text file. The 'Notes...' button allows the attaching of notes to the function, perhaps to describe its purpose.

Using the function editor makes it possible to define functions which incorporate multiple expressions, as compared with the direct entry method which only accepts a single expression as the function's body. You can also include notes, by clicking on the notebook icon. The function editor also allows the definition of local variables. The use of local variables with multiple expressions is useful with complicated functions. An example is:


Function Editor in use


This function calculates the area of a triangle, given its three sides. It uses a local variable s to hold the half sum of the side lengths. If this variable had not been declared to be local, it would have been treated as a global symbol. In other words, without s in the 'Locals' edit box, executing the function would cause a symbol sto be created. This symbol would have the value assigned to it when the function executed, and it would remain accessible just as if it had been defined by typing it into the input window.

Thus, executing the function TriangleArea(5, 12, 13) when the symbol s is not defined as a local gives the result 30 and creates a symbol s with value 15. Executing TriangleArea(7, 24, 25) gives the result 84 and changes the value of s to 28. This side effect does not occur when s is defined as a local.