Vector and matrix operators. Array addition, страница 2

b.gifIf n = 0 this returns the identity matrix whose dimensions match those of M.

b.gifIf n = 1 this just returns M.

b.gifIf n = -1 this returns inverse of M if it exists.

b.gifIf n is a positive integer this multiplies M by itself n times.

b.gifIf n is a negative integer this multiplies the inverse of M by itself n times.

Operands:


b.gifM is square.

b.gifn is a dimensionless integer.

You can evaluate matrix powers symbolically. To do so:

b.gifSelect the expression to evaluate.

b.gifChoose Simplify from the Symbolics menu.

Keystroke: -A

Returns an array the same size as A containing the negative of each element of A. It is equivalent to multiplying A by -1.

Operands:


b.gifA is an array

Vector subscript

Keystroke: [

romsubm.gif

This returns the nth element of v. If v has no nth element, you'll see an appropriate error message.

Operands:


b.gifv is a vector (an array with one column).

b.gifn is a dimensionless integer.

Keep in mind that all arrays start at 0 by default, not 1. For a vector with 10 elements, n must run between 0 and 9. To change this, choose Options / Built-In Variables tab from the Math menu and change ORIGIN.

Use subscripts when graphing vectors.

Matrix subscript

Keystroke: [

romsubmn.gif

This returns the mnth element of M. If M has no mnth element, you'll see an appropriate error message.

Operands:


b.gifM is an array.

b.gifm and n must be dimensionless integers.

Keep in mind that all arrays start at 0 by default, not 1. For a matrix with 10 rows and 5 columns,

b.gifm must run between 0 and 9

b.gifn must run between 0 and 4

To change this, choose Options from the Math menu and click on the Built-In Variables tab in the Math Options dialog box. Change the ORIGIN.

ORIGIN (Default = 0)

This represents the starting index of all arrays. To change it, choose Options / Built-In Variables tab from the Math menu.

You can set ORIGIN to any integer, positive or negative. The value you set for ORIGIN will affect every array in your worksheet.


Keystroke: -

A - B

Subtracts the elements of B from the corresponding elements of A. A and B must have the same number of rows and columns.

A - x

If A is an array and x is a scalar then A - x is an array formed by subtracting x from every element in A.

Operands:


b.gifA and B are matrices having the same number of rows and columns.

b.gifx is a scalar.

Superscript operator

Keystroke: Ctrl+6

romatsup.gif

Returns the nth column of the array M. If M has no nth column, you'll see an appropriate error message.

Operands:


b.gifM must be an array

b.gifn is a scalar. It may not be complex

Keep in mind that all arrays start at 0 by default, not 1. For a matrix with 10 columns, n must run between 0 and 9. To change this, choose Options / Built-in Variables tab from the Math menu and change ORIGIN.

Example:

To get a row from a matrix, use this in conjunction with the transpose operator. For example, to get the first row from a matrix M, type M Ctrl+1 Ctrl+6 1.

Keystroke: Ctrl+1

ramattra.gif

This returns the n x m array formed by interchanging rows and columns of an m x n array.

Operands:


b.gifM is an m x n array.

Although you can use the matrix transpose operator to find matrix transposes numerically, you can also find matrix transposes symbolically.

Keystroke: Ctrl+-

rovector.gif

Changes the meaning of operators and functions so that they apply to every element of an array. This allows you to perform calculations in parallel.

Operands:


b.gifA and B are arrays with the same number of rows and columns.

To vectorize an expression,

1.  Place the expression between the editing lines.

2.  Press Ctrl+-.

Examples:

To perform matrix multiplication of A and B, you would see

ramatx.gif

To multiply each element of A by the corresponding element in B.

roabvec.gif

Note:

Many functions and operators automatically perform operations on the elements of arrays so you do not always have to use the vectorize operator. Use the vectorize operator primarily when a function or operator has a special meaning for arrays. For instance, in the examples above, multiplication has a special meaning for arrays and that meaning is used by default. The vectorize operator has to be used to force an element-by-element multiplication.

Sum elements of a vector

Keystroke: Ctrl+4

s_bigsig.gifv

Returns the sum of all the elements in the vector v.

Operands:


b.gifv is a vector.