Piecewise continuous functions MathCad Help

Piecewise continuous functions are useful for branching and iteration. There are five Mathcad functions falling into this category. The iffunction is useful for choosing one of two values based on a condition. The Heaviside step function, <I>(x), and the Kronecker Delta function, o(m, n), are special cases of the if function.

The until function is used to drive iteration. It is unique among Mathcad functions because it is designed to work only with range variables. This is the only Mathcad function which can actually halt iteration upon the occurrence of a condition. Mathcad Professional, however, also includes specialized programming operators that allow you to control iteration, as described in Chapter 18, “Programming.”

The last function is £ , the completely anti-symmetric tensor function. This returns a 0, 1,or -1 depending on the permutation of its arguments. Although this function is of limited applicability, it would be difficult to perform this function using any other combination of Mathcad functions

The if function

Use if to define a function that behaves one way below a certain number and behaves completely differently above that number. That point of discontinuity is specified by its first argument, condo The remaining two arguments let you specify the behavior of the function on either side of that discontinuity.

Although the argument cond can be any expression at all, it is usually more convenient to use a boolean expression from the table below. The following table shows the meaning of boolean expressions with numbers (x and y can be real scalars, while wand z can be complex scalars). As explained in Chapter 12, “Operators,” boolean operators can also be used to order string expressions character by character based on ASCII codes.

The if function

The if function

Note that boolean expressions involving inequalities cannot be used with complex numbers. This is because it is meaningless to speak of one complex number being “larger” or “smaller” than another.

To save time, Mathcad only evaluates those arguments it has to. For example, if cond is false, there is no need to evaluate tval since it will not be returned anyway. Because of this, errors in the unevaluated argument can escape detection. For example, Mathcad will never detect the fact that In(O) is undefined in the expression below:

Conditionals in Mathcad.

Conditionals in Mathcad.

The until function

Mathcad’s until function allows you to halt an iteration when a particular condition is met. The until function has no effect when its first argument involves no range variables. When the first argument does involve a range variable, Mathcad will iterate until the first argument evaluates to a negative value. When this happens, Mathcad halts iteration.

Do not use the until function in equations with more than one range variable (for example, multiple summations). Mathcad will halt all iteration on all range variables the first time that the first argument of until is negative. This usually does not produce the desired result.

The untiL function is useful in iterative processes with a specified convergence condition. For example, Figure 13-6 shows how to use the until function to test an iterative process for convergence. The iteration in the equation for xi continues until xi is within err of a. Figure 13-6 also shows how to use the last function to detect when iteration has halted and to compute the size of the resulting array.

Using the until function to haLt an iteration

Using the until function to haLt an iteration

When you use the until function, be sure that the value of the test expression does in fact change somewhere in the iteration. Otherwise, you may find yourself in an infinite loop. If this does occur, press the [Ese] key to interrupt calculation.

Impulse and step functions

These two functions are special cases of the if function. The Heaviside step function is equivalent to:

For integer m and n, the Kronecker delta function is equivalent to

Antisymmetric tensor function

The arguments to this function are three integers between 0 and 2 inclusive. It basically determines how many times you have to swap two numbers in order to get back to the sequence [0, 1,2] from whatever sequence [i,j, k] you passed to it.

Although this function is not used very often, it is truly indispensable when you need it. It is very difficult to perform this same feat using any other combination of Mathcad functions

Completely antisymmetric tensor of rank 3. i,j, and k must be integers between 0 and 2 inclusive (or between ORIGIN and ORIGIN + 2 inclusive if ORlGIN;tO). Result is 0 if any two are the same, 1 for even permutations, -1 for odd permutations.

Posted on November 21, 2015 in Built-in Functions

Share the Story

Back to Top
Share This