# Vector or subscript notation MathCad Help

This chapter has shown many examples using subscript notation and range variables, Chapter 10, “Vectors and Matrices,” showed many examples using vector notation without subscripts. This distinction is important. If you use subscripts when they are not required, or vice versa, you probably won’t get the answer you’re looking for.

Subscripts refer to individual array elements. When you use range variables as subscripts like Mt], Mathcad runs through the individual elements of the array one at a time.

Without subscripts, the variable name refers to the whole array.

Here are some rules of thumb for when to use subscripts:

• To refer to an individual array element, use numbers as subscripts. For example, to see matrix element (2,3), type M [2 , 3 =.

• To refer to an array as a whole, use the array name without subscripts. (The term array means either a vector or a matrix.) The array name with no subscripts is appropriate for multiplying one matrix by another, applying the mean function to an array, or viewing a whole vector or matrix-all cases where you want to treat the array as a whole. For example, to view the whole matrix M in Figure 11,-13-, type M=.

• To refer to each of the array elements in succession, use the array name with a range variable subscript. This is useful when defining the matrix elements using some sort of formula. For example, to define the matrix M in Figure 11-13, type three equations:

Iterative calculations with and without subscripts

It’s often faster to use vector operations to perform iterative calculations than it is to do them element by element with a range variable. This is discussed in more detail-in the section “Doing calculations in parallel” in Chapter 10. Unfortunately, not all iterative calculations can be done as vector operations. For example, the seeded iteration technique discussed earlier in this chapter cannot be done with vector operations.

To tell if an equation with subscripts could be rewritten using vector notation and the vectorize operator, check the following:

• If all the subscripts in the calculation are the same, then the calculation can probably be done quickly using vector operations. For example, consider this equation

Since this equation contains no subscript other than i, it can be rewritten with the vectorize operator ([Ctrl]-) instead of with subscripts:

• If the subscripts in a calculation vary or if there is arithmetic involved in computing the subscript, then the calculation probably cannot be done using vector operations. For example, seeded iteration involves the subscripts i and i-I in the same equation. Since the subscripts are not the same, and since the second subscript involves arithmetic, this calculation cannot be done using vector operations.

• If the range variable appears anywhere in an equation other than in a subscript, the equation cannot be written using vector operations. For example, the variable 0 below cannot be defined using the vectorize operator. Although the range variable appears on the left side as a subscript, its presence in an expression on the right disqualifies the entire equation

Figure 11-14 shows the polar coordinate conversions from Figure 11-6 computed two ways: using subscripts and using vector operations. The second method is much faster in Mathcad.

Posted on November 20, 2015 in Range Variables