In the last section, we studied the basic operation of MATLAB, and one of the ways to define variables is to assign values directly, such as a= 1. In fact, the essence of this operation is to define the simplest matrix of 1× 1 (this phenomenon can be observed in workspace).
The basic form of matrix can be expressed as follows
Among them, the above matrix is a matrix with 2 rows and 4 columns, and a MATLAB matrix follows the following principles;
Generally speaking, you can use the idea of direct assignment to create directly, as shown below:
In fact, this method of direct assignment is too time-consuming and laborious. We usually use another method: create arithmetic progression (a:b:c) with colon operator.
The library function of MATLAB contains many functions to quickly create a matrix, such as 1, 0, eye, rand, magic, true and false, which are explained here:
The function of one
Zero function
Eye function
Rand function
Randn function
Magical function
Real function
False function
There is also a generating function, which can quickly generate a one-dimensional matrix: linspace, logspace and so on.
Linspace function
Logarithmic space function
Fortunately, the priority of operators in MATLAB does not conflict with general mathematical knowledge. Operators and variables do not need to force spaces. "I add spaces purely for beauty. Of course, it is best not to add spaces when taking the negative sign." Therefore, as long as you know some operators in MATLAB, it is easier to get started with matrix operation. The content of this part of matrix operation is consistent with linear algebra. It should not be difficult for people with a foundation in linear algebra to understand. Students who have no basic knowledge of linear algebra are advised to execute the following commands in a single step, carefully observe the changes of the results and be familiar with the functions of these operators.
Operator operations are generally divided into two categories: array operators and matrix operators.
Array operators can be understood as operations on matrix elements, which have nothing to do with the nature of the matrix itself, and are also one-to-one operations.
This time, almost all the contents can be copied to MATLAB for execution, and almost only observation is needed. Many generated functions don't need to be memorized by rote, and the function names can be almost translated literally, and you can remember them without stress after using them for a few times at first (even if you remember a letter wrongly, MATLAB will prompt you to enter the correct name).