Topic from: "Conquer Matlab must do exercise 50 Road"
The title changed to the way I wanted to write it.
1. Create a 3x3 matrix and extend it to the 4x5 matrix
= Ones (3,3= Zeros (3,3= rand (3,3) % = Randn (3,3) % produces an average value of 0, Variance σ^21, standard deviation σ= 1 Normal distribution matrix
MAT4 (4,5) = 10
2. Create a geometric series and then create a diagonal array from it, and store the matrix.
= Logspace (0,4,5= diag (a) Save mydate d1
%eye (m,n) generates a unit matrix of MXN
3. Call the matrix stored above and generate a column vector from it.
= Diag (D1)
4. Create a 3x3 magic square and a corresponding random matrix, splicing two matrices together. Then extract any element.
Magic Phalanx: The sum of any row, column, and diagonal is equal.
= Magic (3= rand (3,3= [MAT1,MAT2] %= [MAT1;MAT2] % = MAT3 (2:3, [1,3,4]) % extract 2nd, 3 lines, 1th,3 = Mat3 ([1,3],[2,4])
5. Find the Matrix's transpose matrix.
= Magic (3= rot90 (MAT1) %= mat1' % transpose matrix
6. Create a 4x4 unit matrix to extract the elements on the main diagonal
= rand (4,4= diag (MAT1)
7. Create a 4x5 random matrix that extracts a matrix of elements greater than 0.3 in the first row and the second row.
CLEAR;CLC;MAT1= rand (4,5) Mat2= MAT1 ([1,2],[1,2,3,4,5]) MAT3=mat2 (:) k=1; forII =1: Length (MAT3)if(MAT3 (ii) >0.3) mat4 (k)=MAT3 (ii); K= k +1; ENDENDMAT4
8. Calculate AXBXC.
= rand (3= Magic (3= rand (3,4) A*b*c
9. a=[1,2,3], calculate the product of a ' and a '.
= [1,2,3= A'A *BB*a
10. Finding the inverse matrix of the 5x5 matrix and the 4x3 matrix
= rand (5,5= rand (4,3= INV (A) %= PINV (B) %= *= b1*b
11. Solve AX = b solutions in two ways (A is a 4-order random matrix and B is a 4-order column vector)
= rand (4= Ones (4,1= INV (A) *= a\b % Direct use of Gaussian elimination, faster
12. Calculate A's 5-time square, calculation (0.5) ^a
The exponentiation algorithm for matrices (A^P):
① when P is a positive integer, a^p represents A squared P-Times
② when P is a negative integer, a^ (-P) represents the matrix A-1 squared P-Times
③ when P is 0 o'clock, a^0 equals the unit matrix of the same dimension as a
④ when P is a fraction, if a can be decomposed to a = Wdw-1,d to diagonal, then a^p = WDpW-1
Scalar matrix exponentiation (p^a):
If a can be decomposed to a = Wdw-1,d is diagonal, then the scalar matrix can be defined as:
= rand (4= a^5 %= (0.5) ^a
Matlab Exercises--matrix and array operations