Nested arrays MathCad Help

An array element need not be a scalar. In Mathcad Professional it’s possible to make an array element itself be another array. This allows you to create arrays within arrays.

These arrays behave very much like arrays whose elements are all scalars. However, there are some distinctions:

• You cannot use the Matrix command from the Insert menu to insert an array into a placeholder that’s already inside an array.

• You cannot display the entire nested array. You will instead see a notation like “{ 3,2}” to indicate that a 3 x 2 array is present in a particular array location.

• Most math operators and functions do not make sense in the context of nested arrays.

The following sections explore these differences in some detail

Defining a nested array

You define a nested array in much the same way you would define any array. The only difference is that you cannot use the Matrix command from the Insert menu when you’ve selected a placeholder within an existing array. You can, however, click on a placeholder in an array and type the name of another array as shown in Figure 10-22.

Figure 10-22 shows three ways to define a matrix of matrices: using range variables, element by element, and with the Matrix command from the Insert menu.

In addition to those methods shown in Figure 10-22, you can also use the READPRN function in the array of empty placeholders created using the Matrix command. Keep in mind, however, that you can’t use READPRN on the same file more than once in a given matrix. The READPRN function is discussed more fully in Chapter 19, “Data Management.”

Defining nested arrays

Defining nested arrays

Displaying nested arrays

When you display a nested array using the equal sign, you won’t actually see every element in every nested array. Such a display would be very cumbersome, especially when you consider that an array inside an array may itself contain arrays within it

Instead, whenever an array element is itself an array, Mathcad indicates this by showing the number of rows and columns rather than the array itself. Figure 10-23 shows how the arrays created in Figure 10-22 would appear when displayed. Each array element is displayed either:

• As a number when the array element is simply a number, or

• As an ordered pair m, n where m and n are the number of rows and columns in the array which occupying that array element.

Note that the B array contains an element, B2, which is itself a nested array. To view this array, you would simply nest your subscripts as shown in the lower-right comer of Figure 10-22.

Displaying nested arrays.

Displaying nested arrays.

Operators and functions for nested arrays

Most operators and functions do not work with nested arrays. This is because there is no universally accepted definition of what the correct behavior should be in this context. For example, there is no clear definition of what it means to “invert” such an array. When you attempt to perform the usual arithmetic operations on nested arrays, you will get either an error message or a meaningless result. For the most part, nested arrays are designed only for storing and accessing data in a convenient way.

Certain operators and functions are nevertheless useful and appropriate for nested arrays. For example, transpose does something meaningful as shown at the bottom of Figure 10-23. Operators which make sense in the context of nested arrays are:

Operators and functions for nested arrays

Operators and functions for nested arrays

Useful functions for nested arrays tend to be those having to do with the number of rows and columns in an array or those used for joining or dividing arrays. In particular, you can use the rows and cols functions to distinguish between scalar array elements and array elements which are themselves arrays. Both these functions return a zero in the former case and the appropriate number in the latter. The functions you’ll find useful when working with nested arrays are

Operators and functions for nested arrays

Operators and functions for nested arrays



Posted on November 20, 2015 in Vectors and Matrices

Share the Story

Back to Top
Share This