6. Use matlab to complete the rank of the symbolic matrix and the inverse matrix and determinant of the symbolic square matrix (matlab program)

1. Brief description

      

Use M file to create matrix
    For a relatively large and complex matrix, you can create an M file specially for it. The following is a simple example to illustrate how to create a matrix using an M file.

    Example 2-2   uses the M file to create a MYMAT matrix.
(1)  Start the relevant editing program or MATLAB text editor, and input the matrix to be built:
(2)  Save the input content in plain text ( let the file name be mymatrix.m) .
(3)  Enter mymatrix in the MATLAB command window , that is, run the M file, and a matrix named MYMAT will be automatically created for future use.

Use a colon expression to create a vector
    A colon expression can generate a row vector. The general format is:
    e1:e2:e3
where e1 is the initial value, e2 is the step size, and e3 is the end value.
In MATLAB , you can also use the linspace function to generate row vectors. Its call format is:
linspace(a,b,n)
where a and b are the first and last elements of the generated vector, and n is the total number of elements.
Obviously, linspace(a,b,n) is equivalent to a:(ba)/(n-1):b .


Building large matrices
Large matrices can be built from small matrices or vectors enclosed in square brackets.

2. Code

%% Learning objective: rank of matlab symbolic matrix

clear all;
syms x y;
f1=sym('[1,x^2,3;exp(x),x+y,y;3+x,sin(x),cos(y)]')
f2=sym('[1,x^2,3;exp(x),x+y,y]')
g1=rank(f1)
g2=rank(f2)
 

%% Learning objective: inverse matrix and determinant of matlab symbolic square matrix

clear all;
syms x;
A1=sym(magic(4))
Y1=inv(A1) % inverse matrix
det(A1) % determinant

A2=sym([4-x,x,x-4;x,x-4,x+4;x,x,4])
Y2=inv(A2)
det(A2)

3. Running results

 

 

Guess you like

Origin blog.csdn.net/m0_57943157/article/details/132254797