Numerical analysis often involves using the MATLAB program to solve the equations by using the column principal element elimination method respectively Ax=b
The specific methods and codes are illustrated by the following equation (3x3 matrix):
Using the column principal element elimination method to solve the equation group ax=b, the MATLAB program is used to realize:
(1)
1, MATLAB code to realize the solution of the equation can be divided into Two kinds , one is Entry-level , just simply calculate the problem, the second is a General-Purpose code , can realize many of the 3x3 matrix equation solution, write well later only need to change the elements in different matrices to calculate the corresponding solution, need to be established on the basis of familiarity with MATLAB, as follows:
The first code implementation-entry level:
A=[3.01,6.03,1.99,;1.27,4.16,-1.23,;0.987,-4.81,9.34]
a1=[3.01,6.03,1.99,1;1.27,4.16,-1.23,1;0.987,-4.81,9.34,1]
B1=A1 (1,1:4)
C1=A1 (2,1:4)
D1=A1 (3,1:4)
E1=-1.27/3.01*b1+c1
F1=-0.987/3.01*b1+d1
P1=e1 (ON)
Q1=F1 (ON)
if (ABS (p1) >=abs (Q1))
A1=p1
A2=q1
Ff1=e1
Ee1=f1
Else
A1=q1
A2=p1
Ff1=f1
Ee1=e1
End
G1=-a2/a1*ff1+ee1
H1=[e11; FF1; G1]
J1=H1 (1:3,1:3)
B1=H1 (1:3,4)
X1=j1\b1
The second type of code is implemented as follows-proficiency in the general level:
A=[3.01,6.03,1.99,;1.27,4.16,-1.23,;0.987,-4.81,9.34]
a1=[3.01,6.03,1.99,1;1.27,4.16,-1.23,1;0.987,-4.81,9.34,1]
B1=A1 (1,1:4)
C1=A1 (2,1:4)
D1=A1 (3,1:4)
F1=A1 (a)
F2=A1 (2,1)
F3=A1 (3,1)
if (ABS (F1) >=abs (F2))
if (ABS (F1) >=abs (F3))
F11=f1
E11=b1
F22=f2
E12=c1
F33=f3
E13=d1
Else
F11=f3
E11=d1
F22=f1
E12=b1
F33=f2
E13=c1
End
End
if (ABS (E2) >=abs (E3))
F11=f2
E11=c1
F22=f1
E12=b1
F33=f3
E13=d1
Else
F11=f3
E11=d1
F22=f1
E12=b1
F33=f2
E13=c1
End
E1=-f22/f11*e11+e12
F1=-f33/f11*e11+e13
P1=e1 (ON)
Q1=F1 (ON)
if (ABS (p1) >=abs (Q1))
A1=p1
A2=q1
Ff1=e1
Ee1=f1
Else
A1=q1
A2=p1
Ff1=f1
Ee1=e1
End
G1=-a2/a1*ff1+ee1
H1=[e11; FF1; G1]
J1=H1 (1:3,1:3)
B1=H1 (1:3,4)
X1=j1\b1
The output results are as follows:
A =
3.0100 6.0300 1.9900
1.2700 4.1600-1.2300
0.9870-4.8100 9.3400
A1 =
3.0100 6.0300 1.9900 1.0000
1.2700 4.1600-1.2300 1.0000
0.9870-4.8100 9.3400 1.0000
B1 =
3.0100 6.0300 1.9900 1.0000
C1 =
1.2700 4.1600-1.2300 1.0000
D1 =
0.9870-4.8100 9.3400 1.0000
F1 =
3.0100
F2 =
1.2700
F3 =
0.9870
F11 =
3.0100
E11 =
3.0100 6.0300 1.9900 1.0000
F22 =
1.2700
E12 =
1.2700 4.1600-1.2300 1.0000
E33 =
0.9870
E13 =
0.9870-4.8100 9.3400 1.0000
E11 =
1.2700
E11 =
1.2700 4.1600-1.2300 1.0000
E22 =
3.0100
E12 =
3.0100 6.0300 1.9900 1.0000
E33 =
0.9870
E13 =
0.9870-4.8100 9.3400 1.0000
E1 =
0-3.8295 4.9052-1.3701
F1 =
0-8.0430 10.2959 0.2228
P1 =
-3.8295
Q1 =
-8.0430
A1 =
-8.0430
A2 =
-3.8295
FF1 =
0-8.0430 10.2959 0.2228
EE1 =
0-3.8295 4.9052-1.3701
G1 =
0 0 0.0030-1.4762
H1 =
1.2700 4.1600-1.2300 1.0000
0-8.0430 10.2959 0.2228
0 0 0.0030-1.4762
J1 =
1.2700 4.1600-1.2300
0-8.0430 10.2959
0 0 0.0030
B1 =
1.0000
0.2228
-1.4762
X1 =
1592.6
-631.9
-493.6
It can be seen that: the difference between the two code is that each step of the column in the main element of the main element of the judgment above, the first direct view, so the use of specific numbers instead of, and the second pair of variables have a general definition and assignment, through the IF statement size judgment, such a method will be more general, Based on the proficiency of MATLAB.
Using the column principal element elimination method to solve the ax=b of the equations respectively, and realize with MATLAB program (most effective version)