Implementation of Special Matrices
- Unit array generation
Eye (n)
Eye (m, n)
- Zero matrix generation
Zeros (n)
Zeros (m, n)
- Generation of full 1 Matrix
Ones (n)
Ones (m, n)
- Random Element Matrix Function
Rand (n, m)
Rand (n)
- Diagonal Matrix
Diag (V) % V = [1 2 3 4];
- Adjoint Matrix
Compan (P) % p = [1, a1, a2,..., an]
- Upper Triangle Matrix lower Triangle Matrix
Triu (B)
Tril (B)
Matrix Functions
- Determine a Matrix
Det ()
- Matrix Inversion
Inv ()
Pinv ()
- Matrix Trace
Trace ()
- Rank of the matrix
Rank ()
- Matrix triangle Decomposition
[L, U] = lu ()
- Matrix Singular Value Decomposition
Cond ()
- Matrix norm
N = norm (A, option)
- Matrix feature multiclass value and feature vector
[V, D] = eig ()
- Matrix feature polynomials, feature equations, and feature roots
P = poly ()
V = roots (P)
Bytes ------------------------------------------------------------------------------------------------------------------
MatLabInMomentArray
We know that solving linear equations is the core of linear algebra.MomentArrayIt plays an important role in solving linear equations. Next we will use scientific computing softwareMATLABTo demonstrate how to useMomentArrayAt the same time, it also makes the students' understanding of linear algebra more rational.
I,MomentArrayOfStructure
InMatLabMedium,StructureMomentArrayThere are two methods. One is the direct method, which is directly input through the keyboard.StructureMomentArray. The other is to use functions to generateMomentArray.
Example 1. Use the Pascal function to generateMomentArray
A = Pascal (3)
A =
1 1 1
1 2 3
1 3 6
Example 2. Use the magic function to generateMomentArray
B = magic (3)
B =
8 1 6
3 5 7
4 9 2
Example 3. Use a function to generate a 4*3 randomMomentArray
> C = rand (4, 3)
C =
0.9501 0.8913 0.8214
0.2311 0.7621 0.4447
0.6068 0.4565 0.6154
0.4860 0.0185 0.7919
Example 4. Use the direct input method to generate ColumnsMomentArray, LineMomentArrayAnd constant
U = [3; 1; 4]
U =
3
1
4
V = [2 0-1]
V =
2 0-1
S = 7
S =
7
II,MomentArrayBasic operation
1. Arithmetic Operations
Example 5.MomentArrayAddition
X = a + B
X =
9 2 7
4 7 10
5 12 8
Example 6.MomentArraySubtraction
Y = X-A
Y =
8 1 6
3 5 7
4 9 2
Note:If twoMomentArrayIf the size is not exactly the same, an error will occur!
For example, x = a + u
??? Error Using ==> plus
Matrix dimensions must agree.
Example 7.MomentArrayMultiplication
X = a * B
X =
15 15 15
26 38 26
41 70 39
Note:If the firstMomentArrayNumber of columns and the secondMomentArrayThe number of rows is different.MomentArrayIt cannot be multiplied.
For example, x = A * V
??? Error Using ==> mtimes
Inner matrix dimensions must agree.
InMATLABMedium,MomentArrayDivision has two operators, namely, the left division "\" and the right division "/",MomentArrayThe right division operation is slower, while the left division operation can avoid singularity.MomentArrayThey are mainly used to solve linear equations.MomentArrayDivision.
2,MomentArrayTranspose, inverse, and determining operations
Like linear algebra,MomentArrayYou only need to use the symbol "," to represent the transpose.
Example 8. SearchMomentArrayB's transpose
X = B'
X =
8 3 4
1 5 9
6 7 2
Linear AlgebraMomentArrayThe inverse operation is very complex.MATLABMedium,MomentArrayOnly the function "inv" is required for the inverse operation, which greatly simplifies the calculation process.
Example 9. SearchMomentArrayInverse of
X = inv ()
X =
3-3 1
-3 5-2
1-2 1
InMATLAB...MomentArrayCan be implemented using the "det" function.
Example 10. SearchMomentArrayThe determining factor of
X = det ()
X =
1
Note:InMomentArrayWhen the inverse and the deciding factorMomentArrayIs a partyArrayOtherwise, an error occurs!
For example,> X = inv (u)
??? Error using ==> inv
Matrix must be square.
Another example is X = det (u)
??? Error using ==> det
Matrix must be square.
III,MomentArrayCommon Function operations
1.MomentArrayFeature value calculation
In linear algebra, computingMomentArrayThe process of feature values and feature vectors is quite troublesome,MATLABMedium,MomentArrayThe feature value operation only requires the function "eig" or "eigs.
Example 11. SearchMomentArrayFeature values and feature vectors of
> [B, c] = eig ()
B =
-0.5438 to 0.8165 0.1938
0.7812-0.4082 0.4722
-0.3065 0.4082 0.8599
C =
0.1270 0 0
0 1.0000 0
0 0 7.8730
In the above exampleB,CMomentArrayFeature vectorsMomentArrayAnd feature valueMomentArray.
2.MomentArrayRank Calculation
MomentArrayRank is widely used in linear equations, while rank is calculated in linear algebra.MomentArrayThe rank is also very complex, but inMATLABMedium,MomentArrayYou only need to use the "rank" function.
Example 12. SearchMomentArrayRank of
> X = rank ()
X =
3
3.MomentArrayOrthogonal operation
InMATLABMedium,MomentArrayThe orthogonal operation can be calculated by the function "orth. The following example is used to findMomentArrayA group of orthogonal bases.MomentArrayOrthogonal.
Example 13. SearchMomentArrayOrthogonal basis of
> X = Orth ()
X =
-0.1938 0.8165 0.5438
-0.4722 0.4082-0.7812
-0.8599 to 0.4082 0.3065
4.MomentArrayTrace operations
MomentArrayIndicatesMomentArrayThe sum of all elements on the main diagonal line, inMATLABMedium,MomentArrayThe trace can be calculated by the function "trace.
Example 14. SearchMomentArrayA's trace
> X = trace ()
X =
9
4. SpecialMomentArrayGeneration
MATLABProvides several specialMomentArray, Including:
1. EmptyMomentArray
NullMomentArrayIt is represented by "[]" And is null.MomentArrayBut the variable name exists in the workspace.
Example 15
> []
Ans =
[]
2. UnitMomentArray
InMATLABMedium, UnitMomentArrayIt can be implemented using the "eye (n, m)" function, where the number of rows in the n table and the number of columns in the m table.
Example 16
> X = eye (4, 3)
X =
1 0 0
0 1 0
0 0 1
0 0 0
3. All elements with 1MomentArray
InMATLAB, All elements are 1MomentArrayIt can be implemented using the ones (n, m) function.
Example 17
> X = ones (4, 3)
X =
1 1 1
1 1 1
1 1 1
1 1 1
4. If all elements are 0MomentArray
InMATLAB, All elements are 0MomentArrayIt can be implemented using the "zeros (n, m)" function.
Example 18
> X = zeros (4, 3)
X =
0 0 0
0 0 0
0 0 0
0 0 0
5. CubeMomentArray
CubeMomentArrayThere is an interesting property. Each row, column, and two diagonal lines have the same elements..MATLABProvide cubeMomentArrayThe function "magic (n)" is used to generate a cube of N levels.Array.
6. adjointMomentArray
InMATLAB,MomentArrayAccompaniedMomentArrayIt can be implemented using the "compan (A)" function.
Example 20
> U = [1 0-7 6];
> X = compan (u)
X =
0 7-6
1 0 0
0 1 0
Note:The variable in the compan () function must be in the vector form, notMomentArray.
7. RandomMomentArray
RandomMomentArrayIt is very important in the research of mathematical statistics. They indicate that elements are subject to a certain distribution, such as even distribution and normal distribution.MomentArray. InMATLABMedium, randomMomentArrayIt can be implemented using the "rand (n, m)" function.
Example 21
> X = rand (4, 3)
X =
0.9501 0.8913 0.8214
0.2311 0.7621 0.4447
0.6068 0.4565 0.6154
0.4860 0.0185 0.7919
8. PascalMomentArray
We know that the coefficient after the expansion of the quadratic term increases with N to form a triangle table, called
Yang Hui triangle. Composed of the Yang Hui triangle tableMomentArrayCalled Pascal)MomentArray, Function pascal (n) to generate an n-level pascalMomentArray.
Example 22
> X = pascal (3)
X =
1 1 1
1 2 3
1 3 6
9. Van DimonMomentArray
InMATLABThe function vander (V) generates a model based on the vector V.MomentArray.
Original: http://hi.baidu.com/%B6%AC%CC%EC%C0%EF%B5%C4%D2%BB%BF%C3%B2%DD/blog/item/3d2190878d6d662fc75cc371.html