Gaussian elimination of column-selected principal component-MATLAB

Source: Internet
Author: User

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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.