» **Matrices **

Edit# Editing

There are few ways to insert matrix (matrices). From the menu: **Insert=>Matrix**, keybord shortcut **CTRL+M**, from the Matrices palette (Matrix 3x3), inserting the function **mat(**. You will get the 3x3 template, or the dialog box to insert the number of rows and columns. Let as assign to a variable name *A*, matrix with dimensions 3(rows)x3(columns). For instance, press: **A:** and then **CTRL+M**. The matrix template with 3x3 empty place holders will appear.

If you change your mind about dimensions you can always change the matrix dimensions. Just click inside the matrix on the right lower corner. The black square with a vertical and horizontal line will appear. With the left mouse button (mouse pointer will change the appearance) drag and correct the dimensions. You can do that even if the placeholders are not empty,

Let us now fil in the placeholder like in the following picture. If we point the matrix with the mouse, the tooltip will appear. This is the the symbolic presentation of matrix. As you could see, real numbers are presented as fractions and there are also two undefined variables (*a* and *b*, without numerical values)

Edit# Usage: Symbolic vs. Numeric

If we assign the values to variables *a* and *b* before the matrix definition, the result would be:

We can present the result of matrix*A* symbolically (operator →) or numerically (operator = ). Note the difference:

Edit# Extracting Elements

Also, the individual matrix element could be presented with the function **el**. Press **el(A,** or **A[**. You will see

Edit# Assigning Values to Elements

Now, you can insert single integer (vector) or two integers (matrix) to asign vector or matrix elements. Here (matrix) press 3,1→ or 3,1= . The value of *A* in the third row and first column will appear (the minimal row and column index is 1).

Edit# Vectors

SMath will consider **column matrix** as **vectors**. Vector elements need only one index. Here is the example (row matrices still need two index, with the 1 as the first one)

Edit# Advanced

It should be noted that elements of a matrix could be of different data type (numeric, text, units). Here are few simple examples demonstrating this feature.

Note the using of function**row** and **col** to extract a single row or single column.

SMath also supports nested matrices, i.e. the matrix element could also be a matrix. See the next example.

The individual elements are presented in the same way as before.

Matrices in SMath are dynamic arrays and they can change their dimensions. For instance**matrix** function gives a matrix filled with zeros. See how you can do the same by assigning the zero value to the element z_{3 4}.

Try to put now, say,**z**_{5 5}:=2

Besides the matrix/vector variables, there are also matrix/vector functions.

Function*f* have a single argument and it returns a three element vector. The argument can be scalar,vector or matrix. __Try it__. Function *ff* expects two element vector, and function *F* expects two arguments and returns 2x2 matrix. __Play with them__.

When dealing with matrices, although there are many matrix/vector operators and functions, sooner or later there will loops be involved. Most often the single, double or nested**for** loops are used. See this simple example:

You can initialize an empty matrix with a fixed dimension using the matrix(rows,cols) and setting one of the two arguments to 0.

If you change your mind about dimensions you can always change the matrix dimensions. Just click inside the matrix on the right lower corner. The black square with a vertical and horizontal line will appear. With the left mouse button (mouse pointer will change the appearance) drag and correct the dimensions. You can do that even if the placeholders are not empty,

Let us now fil in the placeholder like in the following picture. If we point the matrix with the mouse, the tooltip will appear. This is the the symbolic presentation of matrix. As you could see, real numbers are presented as fractions and there are also two undefined variables (

Edit

We can present the result of matrix

Edit

Edit

Edit

Edit

Note the using of function

SMath also supports nested matrices, i.e. the matrix element could also be a matrix. See the next example.

The individual elements are presented in the same way as before.

Matrices in SMath are dynamic arrays and they can change their dimensions. For instance

Try to put now, say,

Besides the matrix/vector variables, there are also matrix/vector functions.

Function

When dealing with matrices, although there are many matrix/vector operators and functions, sooner or later there will loops be involved. Most often the single, double or nested

You can initialize an empty matrix with a fixed dimension using the matrix(rows,cols) and setting one of the two arguments to 0.