Basic mathematical operation symbols
Symbol | function | Symbol | function |
---|
+ | addition | - | subtraction |
* | Matrix multiplication | .* | Multiplication, dot multiplication, that is, array multiplication |
/ | Right division | ./ | Right division of array |
\ | be demoted | '\'. | Array left division (there is no single quotation mark here) |
^ | Power | .^ | Array power |
' | Matrix conjugate reprint | .' | Matrix transpose |
Simple example of basic operation
>>%Definition matrix A Sum matrix B
>>A=round(rand(3)*10)
A=
9 4 4
3 5 7
4 9 1
>>B=magic(3)
B=
8 1 6
3 5 7
4 9 2
>>%Cross multiplication and dot multiplication of matrices
>>C1=A*B
C1=
100 65 90
119 133 123
47 56 77
>>C2=A.*B
C2=
72 4 24
21 45 63
8 81 2
>>%Left division and right division of matrices
>>D1=A./B
D1=
1.1250 4.0000 0.6667
2.3333 1.8000 1.2857
0.5000 1.0000 0.5000
>>D2=A.\B
>D2=
0.8889 0.2500 1.5000
0.4286 0.5556 0.7778
2.0000 1.0000 2.0000
>>%Matrix power
>>E1=A.^2
E1=
81 16 16
49 81 81
4 81 1
>>E2=A^2
E2=
117 108 76
144 190 118
83 98 90
As can be seen from the example, no matter which operation method (multiplication, division and power), it is marked with "." The operation mode of represents the operation on the elements of the matrix. For a matrix, the right division of a matrix is a division in a general sense, while the left Division has a symmetrical meaning, that is, A./B=B.\A.
Common punctuation in the command line
Symbol | name | Function and significance |
---|
'space' | Space | Separator between input quantities (these spaces between variables will be ignored in the command window); Enter the separator between array elements |
, | comma | To display the separation between the calculation results and other commands; Separator between input quantities or between array elements |
. | spot | In numerical calculation, it can be used as a decimal point; In the process of array operation, it can be used as the indicator of element operation |
; | semicolon | At the end of the command line, it means that the calculation result will not be displayed after the calculation; Or as a separator between array rows when entering an array |
: | colon | When generating a one-dimensional array, it can be used as a separator; All sequences composed of all elements used for single subscript reference; Separator during loop operation |
% | Percent sign | It is located at the beginning of the command line, indicating that the line is a comment line, which increases the readability of the input or deformed file. All contents after the percent sign are comment contents, which are not compiled and displayed in the command window |
'' | Single quote pair | Used to define a string |
() | Parentheses | Change the priority order in the operation process; Used in function calls; Index as array |
[] | square brackets | Definition matrix |
{} | Curly bracket | Define cell array, special character parentheses in graphics |
_ | Underline | Hyphens used when defining variables, functions, or files; The leading symbol of the subscript in a graph |
... | Continuation number | When the command in the input command window is long, you can enter more than 3 point numbers on the first line and continue to enter the command on the next line to complete the input and execution of the long command |
@ | "At" No | Put it in front of the function name to form a function handle; As the leading character of an anonymous function |
! | exclamatory mark | Call operating system operation |
Common operations and editing commands in the command window
command | Function and significance | command | Function and significance |
---|
cd | Show or change working directory | pack | Defragment memory |
clc | Clear command window | path | Show search directory |
clear | Clear variables in workspace | quit | Exit MATLAB |
clf | Clear graphics window | save | Save memory variables |
disary | Log file naming | type | Show file contents |
dir | Displays the files in the current directory | what | List MATLAB files in the directory |
disp | Displays the contents of a variable or text | which | Locate the path to the MATLAB file |
echo | Command window information display switch | who | Lists the variables for the workspace |
hold | Drawing hold command | whos | Detailed list of workspace variables |
load | Loads variables in the specified file | | |
MATLAB operation command demonstration
>>who
Your variables are:
A B C1 C2 D1 D2 E1 E2
>>whos
Name Sive Byte Class
A 3*3 72 double arry
B 3*3 72 double arry
C1 3*3 72 double arry
C2 3*3 72 double arry
D1 3*3 72 double arry
D2 3*3 72 double arry
E1 3*3 72 double arry
E2 3*3 72 double arry
Grand total is 72 elements uisng 576 bytes
>>what
M-files in the current disrectory d:\Program Files\MATLAB71\work
cplxmap intexp3 m4simu13 optfun updown1
flow1 m4_simu14 mysource tmps updown2
MEX-files in the current directory d:\Program File\MATLAB71\work
fact myclac
MDL-files in the current directory d:\Program File\MATLAB71\work
signa9 simu3
signa10 simu4
simu1 simu5
simu11 simu6
simu12 simu7
simu13 simu8
simu13_state_space simu_15
simu14_transfer_function simu_continuous0
simu14_nonliner simu_continuousl
simu2
>>clear
Display of command window
Format command | meaning |
---|
format short | Including 4 significant digits after the decimal point, and no more than 7 significant digits at most; If the value is greater than 1000, it is expressed according to the scientific counting method |
format long | Represented by 15 digits |
format short e | 5-digit scientific counting method |
format long e | 15 bit scientific calculation method |
foramt short g | Automatically select the best numerical representation from format short and format short e |
format long g | Automatically select the best numerical representation from format long and format long e |
format rat | It is expressed by approximate rational numbers |
format hex | Hexadecimal representation |
format + | It is used for +, - and spaces to represent positive, negative and zero respectively. Imaginary numbers in complex numbers are not represented |
format bank | Financial representation, yuan, angle, grade |
format compart | There are no spaces between display variables |
format loose | Space between display variables |