You can use built-in functions, or you can define your own functions. When you define a function, you can use it anywhere below or to the right of the definition.
When you evaluate an expression containing a function, PTC Mathcad performs the following steps:
• Evaluates the arguments you place between the parentheses.
• Replaces the dummy arguments in the function definition with the actual arguments you place between the parentheses.
• Performs the computation specified by the function definition.
• Returns the result as the value of the function.
The arguments of a user-defined function can represent scalars, vectors, or matrices. For example, you could define the above function as follows:
This is an example of a function that accepts a vector as an argument and returns a scalar result. User-defined function names are case sensitive. The function f(x) is different from the function F(x).
When you define a function, you do not need to define any of the names in the argument list. At this point, you are defining the actions PTC Mathcad performs on the arguments, not what the arguments are. It is only when you evaluate a function that you must provide the argument definitions. However, if in defining a function you use a variable name that is not in the argument list, you must define that variable name above the function definition. The value of that variable at the time you make the function definition then becomes a permanent part of the function.
If you want a function to depend on the value of a variable, you must include that variable as an argument. If not, PTC Mathcad just uses that variable’s fixed value at the point in the worksheet where the function is defined.