You can refer to individual array elements by using subscripts. You can also refer to an entire column of an array by using a superscript. To type a subscript, use the left bracket key” [ ” and put an integer or a pair of integers in the placeholder. To insert a superscript operator, press [Ctrl]6 and place an integer in the placeholder.

Vector and matrix elements are ordinarily numbered starting with row zero and column zero. To change this, change the value of the built-in variable ORIGIN. See “Changing the array origin” on page 188.

**Subscripts and vector elements**

The top equation in Figure 10-1 defines the vector v. To see the zeroth (top) element of the vector v:

• Type v[0=

You can also define individual vector elements by using a subscript on the left side of a definition. To change “z to 6:

• Type v[2: 6

When you define vector elements, you may leave gaps in the vector. For example, if v is undefined and you define v3 as 10, “o- vI’ and v2 are all undefined. Mathcad fills these gaps with zeros until you enter specific values for them, as shown in Figure 10- 3. Be careful of inadvertently creating very large vectors and matrices by doing this.

**Subscripts and matrix elements**

To view or define a matrix element, use two subscripts separated by a comma. In general, to refer to the element in the ith row,jth column of matrix M, type

M [i, j

Note that the subscripts, like division and exponentiation, are “sticky.” Whatever you type after [ remains in the subscript until you press [Space] to leave.

If you want to add more to the equation, press [Space] to place the entire matrix element name, Mi,} , between the editing lines.

Figure 10-4 shows some examples of how to define individual matrix elements and how to view them. Notice that, as with vectors, Mathcad fills unspecified matrix elements with zeros

You can also define the elements of a vector or matrix with a definition like Vi := i , where i is a range variable. See Chapter 11, “Range Variables.”

**Superscripts with matrix columns**

To refer to an entire column of an array, press [Ctrl]6 and place the column number in the resultant placeholder. Figure 10-5 shows how to place the third column of the matrix M in the vector v.

You can also extract a single row from a matrix by extracting a column from the transposed matrix. This is shown on the right-hand side of Figure 10-5

**Changing the array origin**

By default, Mathcad arrays begin at element zero. To change this, change the value of the built-in variable ORIGIN. When you use subscripts to refer to array elements, Mathcad assumes the arrays begin at the current value of ORIGIN

For example, suppose you want all your arrays to begin with element one. There are two ways to change the value of ORIGIN for the whole worksheet:

• Choose the Options command from the Math menu, click on the Built-In Variables tab, and change the value of ORIGIN.

• Enter a global definition for ORIGIN anywhere in your worksheet. For example, to change the ORIGIN to one, type: ORIGIN-1.

If you change ORIGIN to one, Mathcad no longer maintains an element zero for vectors or a zeroth row and column for matrices. Figure 10-6 shows a worksheet with the ORIGIN set to 1. Note that when you try to refer to V Mathcad displays an appropriate error message.

When you redefine ORIGIN in a worksheet, keep in mind the following suggestions:

• If you define ORIGIN with a definition in the worksheet rather than using the Options command on the Math menu, use a single global definition, Although you can redefine ORIGIN with a “: =” this will invariably lead to confusion, Changing ORIGIN in the middle of a worksheet can cause confusing effects. Array elements will seem to have shifted n positions, where n is the difference between the old ORIGIN and the new ORIGIN.

• Don’t forget to type ORIGIN in capital letters. Mathcad variable names are casesensitive. Because ORIGIN is a built-in variable, its name is not font sensitive. It is however, still case-sensitive.

• When you define an array, Mathcad assigns zero to any undefined element,s. See Figure 10-3 for an example.

• If you inadvertently define an array starting with element one when ORIGIN is set to its default value of zero, you will get unexpected answers with array functions like mean andfft. This is because Mathcad will automatically define Xo = 0 for all these arrays. This extra element distorts the values returned by array functions. To avoid this problem, choose Options from the Math menu, click on the Built-In Variables tab, and set ORIGIN to 1.

• When you set ORIGIN in the Built-In Variable dialog box, its value applies to all array variables. It is not possible to have some variables use one ORIGIN and others use a different ORIGIN

• You can use ORIGIN to define variables with negative subscripts. If you set ORIGIN to -10, all arrays will begin with element -10.

• If you reference an array element with a subscript less than ORIGIN,Mathcad marks the array reference with an error message indicating that the array index goes beyond the ends of the array