/*
This Program is taken from the following site (without permission) solely for the experimentation of cost analysis of practial java programs
http://www.physics.unlv.edu/~pang/cp2_j.html
*/
///////////////////////////////////////////////////////////////////////////
// //
// Program file name: LinearEq.java //
// //
// Tao Pang 2006 //
// //
// Last modified: November 6, 2006 //
// //
// (1) This Java program is part of the book, "An Introduction to //
// Computational Physics, 2nd Edition," written by Tao Pang and //
// published by Cambridge University Press on January 19, 2006. //
// //
// (2) No warranties, express or implied, are made for this program. //
// //
///////////////////////////////////////////////////////////////////////////
// An example of solving a linear equation set via the
// partial-pivoting Gaussian elimination.
import java.lang.*;
public class LinearEq{
public static void main(String argv[]) {
int n = 3;
double x[] = new double[n];
double b[] = {200,0,0};
double a[][]= {{ 100, 100, 100},
{-100, 300, -100},
{-100, -100, 300}};
int index[] = new int[n];
x = solve(a, b, index);
for (int i=0; i=0; --i) {
x[i] = b[index[i]];
for (int j=i+1; j c1) c1 = c0;
}
c[i] = c1;
}
// Search the pivoting element from each column
int k = 0;
for (int j=0; j 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