Java Gauss gaussian(double a[][], int index[])

Here you can find the source of gaussian(double a[][], int index[])

Description

gaussian

License

Open Source License

Declaration

public static void gaussian(double a[][], int index[]) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static void gaussian(double a[][], int index[]) {
        int n = index.length;
        double c[] = new double[n];

        // Initialize the index
        for (int i = 0; i < n; ++i) {
            index[i] = i;//from  ww  w  .  ja  v  a  2 s .c om
        }

        // Find the rescaling factors, one from each row
        for (int i = 0; i < n; ++i) {
            double c1 = 0;
            for (int j = 0; j < n; ++j) {
                double c0 = Math.abs(a[i][j]);
                if (c0 > c1)
                    c1 = c0;
            }
            c[i] = c1;
        }

        // Search the pivoting element from each column
        int k = 0;
        for (int j = 0; j < n - 1; ++j) {
            double pi1 = 0;
            for (int i = j; i < n; ++i) {
                double pi0 = Math.abs(a[index[i]][j]);
                pi0 /= c[index[i]];
                if (pi0 > pi1) {
                    pi1 = pi0;
                    k = i;
                }
            }

            // Interchange rows according to the pivoting order
            int itmp = index[j];
            index[j] = index[k];
            index[k] = itmp;
            for (int i = j + 1; i < n; ++i) {
                double pj = a[index[i]][j] / a[index[j]][j];

                // Record pivoting ratios below the diagonal
                a[index[i]][j] = pj;

                // Modify other elements accordingly
                for (int l = j + 1; l < n; ++l) {
                    a[index[i]][l] -= pj * a[index[j]][l];
                }
            }
        }
    }
}

Related

  1. gauss(double mean, double deviation, double x)
  2. gauss(double[] A, int m, int n)
  3. gauss(final double mean, final double sigma, final double x)
  4. gauss(int N, long seed)
  5. GaussElimination(double a[][])
  6. gaussian(double mu, double sigma, double x)
  7. gaussian(double mu, double sigma, double x)
  8. gaussian(double t)
  9. gaussian(double x, double sigma)