This section describes how to use MATLAB for related computing. MATLAB has a lot of built-in computing methods and functions. Even if you do not know the number method, you can perform some complex calculations, such as solving the inverse of the matrix, solving the integral, differential, perform Fourier variation and inverse transformation, and perform linear fitting by least square. Example 1. Solving the Inverse Moment of a Matrix
This section describes how to use MATLAB for related computing. MATLAB has a lot of built-in computing methods and functions. Even if you do not know the number method, you can perform some complex calculations, such as solving the inverse of the matrix, solving the integral, differential, perform Fourier variation and inverse transformation, and perform linear fitting by least square. Example 1. Solving the Inverse Moment of a Matrix
This section describes how to use MATLAB for related computing. MATLAB has a lot of built-in computing methods and functions. Even if you do not know the numerical method, you can perform some complex calculations, such as solving the inverse of the matrix, solving the integral, differential, perform Fourier variation and inverse transformation, and perform linear fitting by least square.
Example 1. Solve the inverse matrix of a matrix and perform multiplication calculation of the matrix.
First, input (or define) a matrix a, then the input should be:
> A = [1 2; 3 4]
If there is no semicolon, press enter to output a matrix.
Calculate the inverse matrix of matrix a. The functions used for solving the problem are as follows:
> B = inv ()
Calculate the Matrix Multiplication. Here, calculate the transpose of matrix a multiplied by matrix B, while the transpose of matrix only needs to be added by an underscore:
> C = a * B'
The output result is as follows:
A =
1 2
3 4
B =
-2.0000 1.0000
1.5000-0.5000
C =
0 0.5000
-2.0000 2.5000
B '=
-2.0000 1.5000
1.0000-0.5000
Example 2: The definition of symbolic operations mainly involves the application of syms and sym, as follows:
Both are defined symbols, but there are some differences. Before using symbols, syms defines all the symbols used. The following can be used directly. sym is defined in operations and each symbol needs to be defined once, syms is not convenient. The following is an example.
For example, syms x (t)
Equal
A = sym ('A ');
T = sym ('T ');
X = symfun (sym ('x'), {t });
Syms x beta real
Equal
X = sym ('x', 'real ');
Beta = sym ('beta ', 'real ');
The above syms first defines several function symbols, which can be used directly below. There is no need to show sums or sym in the formula, and sym appears in the following formula.
Example 3: Calculate the integral and differential, and use the MATLAB Functions int and diff. Because symbolic operations are involved, you need to use syms to define the symbols before using them, as shown below:
Syms x
Int (x) Press enter to obtain
Ans =
* ^ 2/2
You can also directly enter int (sym (x) and press enter to get
Ans =
* ^ 2/2
Of course, you can also perform complex Integral Computation. because there may be many symbols involved, we recommend that you use syms to define the symbols used and use the int function, perform credit calculation.
The diff function is used in a similar way as int. For example:
> Syms x y
> Y = diff (sin (x ))
Y =
Cos (x)
To use these MATLAB Functions flexibly, we still need to constantly try and use them.
Example 4: Application of solve and dsolve Functions
These two functions can be used to solve function equations or equations. solve is mainly used to solve general equations and equations, while dsolve is generally used to solve differential equations. The specific example is as follows:
For example, to solve the equation sin (x) * pi = 8, find x
> Solve ('sin (x) * pi = 8 ')
Ans =
Asin (8/pi)
Pi-asin (8/pi)
Here, x is solved by default. If it is> solve ('sin (x) * pi * y = 8'), x is still solved by default, what if I want to output y? You need to> solve ('sin (x) * pi * y = 8', 'y'), then it will output ans = 8/(pi * sin (x ));