I saw a good book when I was learning numerical values. Practice English
We should have a better understanding of the Gaussian elimination method. We have done a lot in high generation and linear algebra, but we still need to pay attention to some things when implementing computers,
Gaussian elimination method for selecting principal element in % Column
Function x = lufact_my (A, B)
% Inpiut A is the coefficient matrix, and B is the right-side item.
% Output X is the solution
[N, N] = size ();
X = zeros (n, 1 );
Y = zeros (n, 1 );
C = zeros (1, N );
R = 1: N;
K = 1;
While k <= N-1
% Evaluate the maximum value in the column to Max
[Max1, J] = max (ABS (A (K: n, k )));
% Switch row
C = a (K, :); % C is the value of column K of
A (K, :) = a (J + k-1, :); % assign the K column of A to the maximum
A (J + k-1, :) = C;
D = R (k );
R (K) = R (J + k-1 );
R (J + k-1) = D;
% When the principal component is 0
If a (K, K) = 0
'A is singular. No unique solution'
Break
End
% To upper triangle
For M = k + 1: N
Mult = A (M, k)/A (K, k );
A (M, K) = mult;
A (M, k + 1: n) = A (M, k + 1: N)-mult * a (K, k + 1: N );
M = m + 1;
End
K = k + 1;
End
% Process the right-side items, but ensure that the row exchange is the same. Pay attention to the role of R (k ).
Y (1) = B (r (1 ));
For k = 2: N
Y (K) = B (R (k)-A (k, 1: K-1) * Y (1: K-1 );
End
X (n) = y (N)/A (N, N );
For k = N-1 :-
X (K) = (Y (k)-A (K, k + 1: N) * X (k + 1: N)/A (K, k );
End
Demo ---
> A = [2,-;, 5;, 2];
> B = [1, 4, 5];
> Lufact_my (A, B)
Ans =
9
-1
-6
>
This algorithm cannot calculate zero principal component, but its limitations are relatively large. Next, write an improved...