Raising a matrix to a power. Some properties of operations on matrices. Matrix expressions

The operation of raising to the power n can be formally applied to square matrices. To do this, n must be an integer. The result of this operation is given in table. 9.1. You can enter the operator for raising a matrix m to the power n in the same way as for a scalar quantity: by clicking the Raise to Power button on the Calculator panel or by pressing the key<А>. After the placeholder appears, you should enter the value of the degree n into it.

Table 9.1. Results of raising a matrix to a power

0 identity matrix of matrix dimension M

1 the matrix M itself

1 M -1 - matrix inverse of M

2,3,...MM, (MM)M, ...

2, -3, ... M -1 M -1 , (M -1 M -1)M -1 , ...

Some examples of raising matrices to powers are shown in Listing 9.15.

Listing 9.15. Examples of raising a square matrix to an integer power

Vectorization of arrays

Mathcad's vector algebra includes a somewhat unusual operator called the vectorize operator. This operator is intended, as a rule, to work with arrays. It allows you to perform the same type of operation on all elements of an array (i.e., matrix or vector), thereby simplifying the programming of loops. For example, sometimes you want to multiply each element of one vector by the corresponding element of another vector. There is no such operation directly in Mathcad, but it can be easily accomplished using vectorization (Listing 9.16). For this:

· Enter the vector expression as shown in the second line of the listing (note that in this form the multiplication symbol denotes the scalar product operator of vectors).

· Move the cursor so that the input lines highlight the entire expression that needs to be vectorized (Fig. 9.3).

Enter the vectorization operator by clicking the Vectorize button on the Matrix panel (Fig. 9.3), or using a keyboard shortcut +<->.

· Enter<=>to get the result.

Rice. 9.3. Vectorization operator

Listing 9.16. Using vectorization to multiply elements of a vector



The vectorization operator can only be used with vectors and matrices of the same size.

Most non-specific Mathcad functions do not require vectorization to perform the same operation on all elements of the vector. For example, the argument trigonometric functions by definition is a scalar. If you try to calculate the sine of a vector quantity, Mathcad will vectorize by default, calculating the sine of each element and producing the corresponding vector as the result. An example is shown in Listing 9.17.

Listing 9.17. Vectorization is optional for most Mathcad functions

Symbolic operations with matrices

All matrix and vector operators discussed above can be used in symbolic computation. The power of symbolic operations lies in the ability to perform them not only on specific numbers, but also on variables. Some examples are shown in Listing 9.18.

Listing 9.18. Examples of symbolic operations on vectors and matrices

Feel free to use the symbol processor as a powerful math reference. For example, when you want to recall some definition from the field of linear algebra (for example, the rules for multiplication and matrix inversion are shown in the first lines of Listing 9.18).

Matrix functions

Let's list the main built-in functions designed to make working with vectors and matrices easier. They are needed to create matrices, merge and select parts of matrices, obtain the basic properties of matrices, etc.

Matrix creation functions

The most visual way to create a matrix or vector is to use the first button on the Matrix toolbar. However, in most cases, particularly when programming complex projects, it is more convenient to create arrays using built-in functions.

Defining matrix elements using a function

· matrix(M,N,f) - creating a matrix of size M*N, each i, j element of which is f(i, j) (Listing 9.19);

o M - number of lines;

o N - number of columns;

o f (i, j) - function.

Listing 9.19. Creating a Matrix

To create matrices, there are two more specific functions, used mainly for quick and effective presentation of any dependencies in the form of three-dimensional graphs (such as a surface or a spatial curve). All of their arguments, except the first one (functions), are optional. Let's consider the first of the functions.

CreateSpace(F(or f1, f2, f3), t0, t1, tgrid, fmap) - creates a nested array representing the x-, y- and z-coordinates of a parametric space curve, given function R;

      • F(t) is a vector function of three elements, defined parametrically with respect to a single argument t;
      • f1(t) ,f2(t), f3(t) - scalar functions;
      • t0 - lower limit t (default -5);
      • t1 - upper limit t (default 5);
      • tgrid - number of grid points by t variable (default 2o);
      • fmap is a vector function of three arguments that specifies a coordinate transformation.

Rice. 9.4. Using the CreateSpace function with a different set of parameters

An example of using the CreateSpace function is shown in Fig. 9.4. Note that it didn't take any effort to plot the spiral graph. additional code, except for defining the parametric dependence in the vector function F.

The matrix creation function for a 3D surface plot is designed in exactly the same way, except that the surface definition requires two variables rather than one. An example of its use is illustrated in Fig. 9.5.

Rice. 9.5. Using the CreateMesh function with a different set of parameters

· CreateMesh(F(or g, or f1, f2, f3) , s0, s1, t0, t1, sgrid, tgrid, fmap) - creates a nested array representing the x-, y- and z-coordinates of the parametric surface specified by the function F;

      • F(s,t) is a vector function of three elements, defined parametrically with respect to two arguments s and t;
      • g (s, t) - scalar function;
      • f1(s,t),f2(s,t),f3(s,t) - scalar functions;
      • s0, t0 - lower limits of arguments s, t (default -5);
      • s1, t1 - upper limits of arguments s, t (default 5);
      • sgrid, tgrid - number of grid points based on variables s and t (default 20);
      • fmap is a three-element vector function of three arguments that specifies a coordinate transformation.

Examples of nested arrays that are created by the CreateMesh and CreateSpace functions are shown in Listing 9.20. Each matrix of the three nested matrices that form the array defines the x-, y-, and z-coordinates of points on the surface or curve, respectively.

Listing 9.20. The result of the CreateMesh and CreateSpace functions (Fig. 9.4 - 9.5)

Creating matrices special type

It's easy to create matrices in Mathcad a certain type using one of the built-in functions. Examples of using these functions are shown in Listing 9.21.

· identity (N) - identity matrix of size N*N;

· diag(v) - diagonal matrix, on the diagonal of which are the elements of the vector v;

· geninv(A) - creation of a matrix inverse (on the left) of matrix A;

· rref (A) - transformation of matrix or vector A into stepwise form;

      • N - integer;
      • v - vector;
      • A is a matrix of real numbers.

The size N*M of matrix A for the geninv function must be such that N>M.

Listing 9.21. Creating matrices of a special type

NOTE

In Mathcad 14 and 15, vectorization can be carried out not only in numerical, but also in symbolic (analytical) calculations.

Most non-specific Mathcad functions do not require vectorization to perform the same operation on all elements of the vector. For example, the argument of trigonometric functions is, by definition, a scalar. If you try to calculate the exponent of a vector quantity, Mathcad will vectorize by default, raising each element to the e power and producing the corresponding vector as the result (Listing 7.13).

Listing 7.13. Argument vectorization is optional for most Mathcad built-in functions

7.3. Calculation of determinants and inversion of square matrices

Let us consider several more extremely important operations of linear algebra related to the concept of the determinant of a matrix. Despite the fact that some of them are also implemented in Mathcad in the form of operators, they require (when performing calculations using numerical algorithms) much more attention than the operators mentioned in the two previous sections.

7.3.1. Determinant of a square matrix

The Determinant of a matrix is ​​denoted by the standard mathematical symbol. To enter the operator for finding the determinant of a matrix, you can click the Determinant button on the Matrix toolbar (Listing 7.14) or type on the keyboard<|>(by pressing the keys +<\>). As a result of any of these actions, a placeholder appears in which to place the matrix. To calculate the determinant of a matrix already entered:

1. Move the cursor in the document so as to place the matrix between the input lines (remember that the input lines are vertical and horizontal segments of blue color, forming a corner pointing to the current editing area).

2. Enter the operator for finding the determinant of a matrix.

3. Enter an equal sign (or symbolic output) to calculate the determinant (numerically or analytically, respectively, as shown in Listing

ATTENTION!

Do not confuse the operators for calculating the determinant of a square matrix and the length of a vector. Starting with Mathcad 12, forced control of user actions when entering these operators has been introduced to avoid confusion (since the same symbol is used for these

two operations). If you try to calculate the determinant of a matrix using the A operator entered from the Calculator panel rather than the Matrix panel, an error message will be displayed, and the result of the determinant calculation will appear only after the user calls context menu and will confirm in it that he is going to calculate exactly the determinant of the matrix. The same applies to the vector length if you try to enter it not from the Calculator panel, but from the Matrix panel.

Listing 7.14. Calculating the determinant of a square matrix

7.3.2. Matrix rank

The rank of a matrix is ​​the largest natural number k for which there is a non-zero determinant of the kth order of a submatrix composed of any intersection of k columns and k rows of the matrix.

To calculate the rank in Mathcad, use the rank function (Listing 7.15).

 rank(A) - matrix rank: A - matrix.

Listing 7.15. Calculating the rank of a matrix

7.3.3. Square Matrix Inversion

Search inverse matrix possible if the matrix is ​​square and its determinant is not equal to zero. The product of the original matrix and its inverse is, by definition, the identity matrix. To enter an inverse matrix search operator, click the Inverse button on the Matrix toolbar. Listing 7.16 shows an example of finding the inverse of a matrix and then verifying that it was calculated correctly.

Listing 7.16. Calculating the inverse matrix

7.3.4. Raising a square matrix to a power

The operation of exponentiation n can be formally applied to square matrices. To do this, n must be an integer. The result of this operation is given in table. 7.1. You can enter the operator for raising a matrix M to the power n in exactly the same way as for a scalar quantity: by pressing the button Exponentiation(Raise to Power) in the Calculator panel or by pressing the key<^>. After the placeholder appears, you should enter the value of the degree n into it.

Table 7.1. Rules for raising a matrix to a power

Identity matrix of matrix dimension M

The matrix M itself

M -1 - matrix, inverse M

Linear algebra

Table 7.1 (end)

2 ,3 , ...

M M, (M M) M, ...

–2 , –3 , ...

M-1 M-1 , (M-1 M-1 ) M-1 , ...

Examples of raising a matrix to a power are given in Listing 7.17.

Listing 7.17. Raising a square matrix to an integer power

7.3.5. Matrix norms

In linear algebra, various vector and matrix norms (norm) are used, which assign a certain scalar numerical characteristic to the matrix. The matrix norm reflects the order of magnitude of the matrix elements. In various specific problems of linear algebra they are used different kinds normal Mathcad has four built-in functions for calculating different norms of square matrices:

 norm1(A) - norm in space L1;

 norm2(A) - norm in space L2;

Some properties of operations on matrices.
Matrix Expressions

And now there will be a continuation of the topic, in which we will consider not only new material, but also work out operations with matrices.

Some properties of operations on matrices

There are quite a lot of properties that relate to operations with matrices; in the same Wikipedia you can admire the orderly ranks of the corresponding rules. However, in practice, many properties are in a certain sense “dead”, since only a few of them are used in solving real problems. My goal is to consider the practical application of properties on specific examples, and if you need a rigorous theory, please use another source of information.

Let's look at some exceptions to the rule, which will be required to complete practical tasks.

If a square matrix has inverse matrix, then their multiplication is commutative:

Identity matrix is called a square matrix whose main diagonal units are located, and the remaining elements are equal to zero. For example: , etc.

Wherein the following property is true: if an arbitrary matrix is ​​multiplied left or right to the identity matrix suitable sizes, then the result is the original matrix:

As you can see, the commutativity of matrix multiplication also takes place here.

Let's take some matrix, well, let's say, the matrix from the previous problem: .

Those interested can check and make sure that:

The unit matrix for matrices is an analogue of the numerical unit for numbers, which is especially clear from the examples just discussed.

Commutativity of a numerical factor with respect to matrix multiplication

For matrices and real number the following property holds:

That is, the numerical factor can (and should) be moved forward so that it “does not interfere” with multiplying matrices.

Note : generally speaking, the formulation of the property is incomplete - the “lambda” can be placed anywhere between the matrices, even at the end. The rule remains valid if three or more matrices are multiplied.

Example 4

Calculate Product

Solution:

(1) According to the property move the numerical factor forward. The matrices themselves cannot be rearranged!

(2) – (3) Perform matrix multiplication.

(4) Here you can divide each number by 10, but then among the elements of the matrix there will appear decimals, which is not good. However, we notice that all numbers in the matrix are divisible by 5, so we multiply each element by .

Answer:

A little charade for independent decision:

Example 5

Calculate if

The solution and answer are at the end of the lesson.

What technical technique is important when solving such examples? Let's figure out the numbers last of all .

Let's attach another carriage to the locomotive:

How to multiply three matrices?

First of all, WHAT should be the result multiplying three matrices? A cat will not give birth to a mouse. If matrix multiplication is feasible, then the result will also be a matrix. Hmmm, well, my algebra teacher doesn’t see how I explain the closedness of the algebraic structure relative to its elements =)

The product of three matrices can be calculated in two ways:

1) find and then multiply by the matrix “ce”: ;

2) either first find , then multiply .

The results will definitely coincide, and in theory this property called associativity of matrix multiplication:

Example 6

Multiply matrices in two ways

Algorithm solutions two-step: we find the product of two matrices, then again we find the product of two matrices.

1) Use the formula

Action one:

Act two:

2) Use the formula

Action one:

Act two:

Answer:

The first solution is, of course, more familiar and standard, where “everything seems to be in order.” By the way, regarding the order. In the task under consideration, the illusion often arises that we are talking about some kind of permutations of matrices. They are not here. I remind you again that V general case IT IS IMPOSSIBLE TO REVERSE MATRICES. So, in the second paragraph in the second step we perform multiplication, but in no case do . With ordinary numbers such a number would work, but with matrices it would not.

The property of associative multiplication is true not only for square, but also for arbitrary matrices - as long as they are multiplied:

Example 7

Find the product of three matrices

This is an example for you to solve on your own. In the sample solution, the calculations are carried out in two ways; analyze which path is more profitable and shorter.

The associative property of matrix multiplication also holds for more quantity multipliers.

Now is the time to return to powers of matrices. The square of the matrix is ​​considered at the very beginning and the question on the agenda is:

How to cube a matrix and higher powers?

These operations are also defined only for square matrices. To build square matrix into a cube, you need to calculate the product:

In fact it's special case multiplication of three matrices, according to the associativity property of matrix multiplication: . And a matrix multiplied by itself is the square of the matrix:

Thus, we get the working formula:

That is, the task is performed in two steps: first, the matrix must be squared, and then the resulting matrix must be multiplied by the matrix.

Example 8

Construct the matrix into a cube.

This is a small problem to solve on your own.

Raising a matrix to the fourth power is carried out in a natural way:

Using the associativity of matrix multiplication, we derive two working formulas. Firstly: – this is the product of three matrices.

1) . In other words, we first find , then multiply it by “be” - we get a cube, and finally, we perform the multiplication again - there will be a fourth power.

2) But there is a solution one step shorter: . That is, in the first step we find a square and, bypassing the cube, perform multiplication

Additional task to Example 8:

Raise the matrix to the fourth power.

As just noted, this can be done in two ways:

1) Since the cube is known, then we perform multiplication.

2) However, if according to the conditions of the problem it is required to construct a matrix only to the fourth power, then it is advantageous to shorten the path - find the square of the matrix and use the formula.

Both solutions and the answer are at the end of the lesson.

Similarly, the matrix is ​​raised to the fifth and higher powers. From practical experience I can say that sometimes I come across examples of raising to the 4th power, but I don’t remember anything about the fifth power. But just in case, I will give the optimal algorithm:

1) find ;
2) find ;
3) raise the matrix to the fifth power: .

These are, perhaps, all the basic properties of matrix operations that can be useful in practical problems.

In the second section of the lesson, an equally colorful crowd is expected.

Matrix Expressions

Let's repeat the usual school expressions with numbers. A numeric expression consists of numbers, mathematical symbols, and parentheses, for example: . When calculating, the familiar algebraic priority is valid: first, brackets, then executed exponentiation/rooting, Then multiplication/division and last but not least - addition/subtraction.

If a numeric expression makes sense, then the result of its evaluation is a number, For example:

Matrix Expressions are arranged almost the same way! With the difference that the main characters are matrices. Plus some specific matrix operations, such as transposing and finding the inverse of a matrix.

Let's consider matrix expression , where are some matrices. In this matrix expression, three terms and addition/subtraction operations are performed last.

In the first term, you first need to transpose the matrix “be”: , then perform the multiplication and enter the “two” into the resulting matrix. note that the transposition operation has more high priority than multiplication. Parentheses, as in numerical expressions, change the order of actions: – here the multiplication is performed first, then the resulting matrix is ​​transposed and multiplied by 2.

In the second term, matrix multiplication is performed first, and the inverse matrix is ​​found from the product. If you remove the brackets: , then you first need to find the inverse matrix and then multiply the matrices: . Finding the inverse of a matrix also takes precedence over multiplication.

With the third term, everything is obvious: we raise the matrix into a cube and enter the “five” into the resulting matrix.

If a matrix expression makes sense, then the result of its evaluation is a matrix.

All tasks will be from real ones tests, and we'll start with the simplest:

Example 9

Given matrices . Find:

Solution: The order of operations is obvious, multiplication is performed first, then addition.


Addition cannot be performed because the matrices are of different sizes.

Don’t be surprised; obviously impossible actions are often proposed in tasks of this type.

Let's try to calculate the second expression:

Everything is fine here.

Answer: action cannot be performed, .