Gauss - of Jordan elimination method Summary

Suddenly discovered after a cultural lesson to learn for a long time (tao) Xi (ke), he forgot Gaussian elimination (I'm too weak

 

So today to learn (gao look at this thing

 

Gauss - of Jordan (Jordan) elimination method!

(Following switched some degree)

Mathematically, Gaussian elimination (or translation: Gaussian elimination), programming is an algorithm in linear algebra, is used to solve linear equations. 
However, the algorithm is very complex, not commonly used subtraction elimination method, determined rank of the matrix, and the inverse matrix determined reversible square. However, if
the over one million equations, the algorithm will be very time-saving. Some great equations usually use iterative methods and fancy elimination to solve. When used
while in a matrix, the Gaussian elimination method will produce a "ladder line a formation." Gaussian elimination can be used in the computer to solve the equations and thousands of
unknowns. Some methods are also specifically designed to address some of the coefficients of equations has a special arrangement [1].

Good strong!

However, the horse feels much simpler algorithm

So my konjac on a lazy bar

Probably idea is this:

  1. Find a "principal component" (apparently this zhu yuan should be no choice over unknown)

  2. The main element in this equation coefficients of a

  3. elimination by subtraction, the other equation the unknown is the full elimination

  4. Repeat the above steps until a diagonal matrix (where Gaussian elimination with different triangular matrix)

But in fact, in the process of doing it, is to become the matrix of the left matrix, the matrix on the right is tired at this time of the original matrix matrix spicy!

   Here the position paper is not enough, I do not write / doge (Gugu Gu

 The code to stay in this right: (a far less toxic milk after test)

 Topic Source: Luo Gu P3389 [template] testosterone ♂ Adams elimination method

#include<bits/stdc++.h>
using namespace std;
double a[110][110];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=n+1;++j)
        {
            scanf("%lf",&a[i][j]);
        }
    }
    for(int i=1;i<=n;++i)
    {
        int maxx=i;
        for(int j=i+1;j<=n;++j)
            if(fabs(a[i][j])-fabs(a[maxx][j])) maxx=j;
        for(int j=1;j<=n+1;++j)
            swap(a[maxx][j],a[i][j]);
        if(!a[i][i]) 
        {
            cout<<"No Solution"<<endl;
            return 0;
        }
        else
        {
            for(int j=1;j<=n;++j)
            {
                if(i==j) continue;
                double temp=a[j][i]/a[i][i];
                for(int k=i+1;k<=n+1;++k)
                {
                    a[j][k]-=a[i][k]*temp;
                }
            }
            a[i][n+1]/=a[i][i];
        }
    }
    for(int i=1;i<=n;++i)
    {
        printf("%.2lf\n",a[i][n+1]);
    }
}

 

Guess you like

Origin www.cnblogs.com/ZzTzZ/p/11290883.html