[Matlab] Constants and commonly used special matrix functions
Past review
[Summary] ⧫ [Matlab Six Degrees of Freedom Robot] Series Article Summary \blacklozenge \fcolorbox{black}{aqua}{[Matlab Six Degrees of Freedom Robot] Series Article Summary}
⧫[ M a t l a b six degrees of freedom robot ] series of articles summary
foreword
This article introduces some pre-defined special variables in Matlab, usually calledconstant, two tables are listed below, includingcommon constantandCommonly used special matrix functions。
The following is the text of this article, including the tables and codes of commonly used constants and commonly used special matrix functions and a step-by-step analysis of the code.
text
1. Commonly used constants
Definition: Knowing the motion parameters of each joint, find the pose of the end effector relative to the reference coordinate system.
1. Table of common constants
constant | illustrate | constant | illustrate |
---|---|---|---|
i,j | Imaginary unit, defined as − 1 \sqrt{-1}−1 | eps | Relative Accuracy of Floating-Point Arithmetic |
pi | PI | realmax | largest positive real number |
Inf | Unprecedented | realmin | smallest positive real number |
NaN | Indeterminate ( 0 / 0 ) (0/0)(0/0) | ans | default variable name |
2. Code example
In MATLAB programming, when defining a variable, avoid having the same name as the constant, so as not to change the value of the constant and cause inconvenience to the calculation.
MATLAB code input constant output is as follows:
>> i
ans = 0 + 1i
>> pi
ans = 3.14159265358979
>> inf
ans = Inf
>> nan
ans = NaN
>> eps
ans = 2.22044604925031e-16
>> realmax
ans = 1.79769313486232e+308
>> realmin
ans = 2.2250738585072e-308
>> ans
>>
first inputanswill appear after inputrealminThe value of ans = 2.2250738585072 e − 308 ans = 2.2250738585072e-308ans=2 . 2 2 5 0 7 3 8 5 8 5 0 7 2 e−3 0 8 , when using the commandclearAfter that, a null value will appear.
2. Commonly used special matrix functions
1. Table of commonly used special matrix functions
Function name | illustrate | Function name | illustrate |
---|---|---|---|
zeros | All 0 00 matrix | eye | identity matrix |
ones | All 1 11 matrix | compan | Adjoint matrix |
rand | uniformly distributed random matrix | hilb | H i l b e r t Hilbert H i l b e r t matrix |
randn | Normally distributed random matrix | invhilb | H i l b e r t Hilbert H i l b e r t inverse matrix |
magic | Rubik's cube matrix | vander | V a n d e r Vander V a n d e r matrix |
diag | diagonal matrix | pascal | P a s c a l Pascal P a s c a l matrix |
trio | upper triangular matrix | hadamard | H a d a m a r d Hadamard H a d a m a r d matrix |
trill | lower triangular matrix | tender() | H ankel HankelH a n k e l matrix |
2. Code example
After the MATLAB code is typed into a special matrix generation function, the output is as follows:
zeros
>> zeros
ans = 0
>> zeros(3)
ans = 0 0 0
0 0 0
0 0 0
ones
>> ones
ans = 1
>> ones(3)
ans = 1 1 1
1 1 1
1 1 1
rand
>> rand
ans = 0.400758135480105
>> rand(3)
ans = 0.764893793995034 0.464428454367176 0.927653178179463
0.582893514061483 0.513381433938698 0.23087376700534
0.217163157933335 0.862468459521113 0.344401924372255
randn
>> randn
ans = 0.375644208035345
>> randn(3)
ans = -0.112892984467453 -0.313987577226449 -0.731194789130593
0.479258573665327 0.159292754138156 -2.60703227023313
0.605389358206988 -0.600365174356452 0.0765585801546292
magic
>> magic(3)
ans = 8 1 6
3 5 7
4 9 2
>> magic(5)
ans = 17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
设A = [ 2 5 7 4 7 3 8 9 2 ] A = \left[\begin{matrix}2&5&7\\4&7&3\\8&9&2\\\end{matrix}\right]A=⎣⎡248579732⎦⎤
diag(A)、triu(A)、tril(A)
>> diag(A)
ans =
2
7
2
>> triu(A)
ans =
2 5 7
0 7 3
0 0 2
>> tril(A)
ans =
2 0 0
4 7 0
8 9 2
Summarize
The above is the description of the system constants. This article introduces the constant names and function names of constants and special matrices in detail, as well as the implementation of their codes. MATLAB provides functions for common constants and special matrices, which makes our calculation process more convenient.
references
MATLAB/Simulink System Simulation——Tsinghua University Press