Defining a Function with a Program |
The following steps illustrate how to define a simple program which takes two arguments, divides the first argument by the second, and returns the base-10 logarithm of the result.
Type the left side of a function definition, followed by [:] for the definition symbol.
Define a local variable by typing the variable name (in this case, z), followed by the local assignment operator. This defines z only within the scope of this program; outside the program, z is undefined and has no effect.
Complete the local assignment, in this case by typing x/w in the placeholder to the right of the arrow. Select the entire expression.
Use the Add Line operator to add a second placeholder below the definition for an additional program statement (a program can have any number of statements).
The last placeholder should always contain the value returned by the program. Type log(z) into this placeholder.
A function defined as a program behaves the same as any other user-defined function.
By using the full set of programming operators, you can create complex function definitions, but all program definitions follow the same basic steps outlined above.
Mathcad can evaluate most programs symbolically, though some limitations do apply.