?? linearequationgrouptest.java
字號:
package linearEquationGroup;
//LinearEquationGroup class testing
import java.util.Scanner;
public class LinearEquationGroupTest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
LinearEquationGroup erGroup;
int n;
double a[][];
double b[];
double errAllowed;
double[] xIni;
double relaxationParameter;
String contin,another;
System.out.println("\n----------------------------the program solves a linear equation group" +
"----------------------------\n");
do {
// input the equation group
System.out.println("\ninput the number of the equation:");
n = input.nextInt();
a = new double[n + 1][n + 1];
b = new double[n + 1];
System.out
.println("\nleft to right,up to down,input the eqution group's left matrix "
+ "(use space to seperate):");
for (int i = 1; i < n + 1; i++)
for (int j = 1; j < n + 1; j++)
a[i][j] = input.nextDouble();
System.out
.println("\nup to down,input the eqution group's right value "
+ "(use space to seperate):");
for (int i = 1; i < n + 1; i++)
b[i] = input.nextDouble();
erGroup = new LinearEquationGroup(n, a, b);
// confirm the equation group
System.out.println("\nthe equation group that you input is:");
System.out.println(erGroup.confirm());
System.out.println("\ninput \"c\" to continue:");
contin=input.next();
// use Gauss elimination method
System.out.println("\nuse Gauss reduction to solve it:");
System.out.println(erGroup.gaussElimination());
System.out.println("\ninput \"c\" to continue:");
contin=input.next();
// use Crout elimination method
System.out.println("\n\nuse Crout reduction to solve it:");
System.out.println(erGroup.croutElimination());
System.out.println("\ninput \"c\" to continue:");
contin=input.next();
// use Cholesky method
System.out.println("\n\nuse Chelosky method to solve it:");
System.out.println(erGroup.cholesky());
System.out.println("\ninput \"c\" to continue:");
contin=input.next();
// use main element method
System.out.println("\n\nuse main element method to solve it:");
System.out.println(erGroup.mainElement());
System.out.println("\ninput \"c\" to continue:");
contin=input.next();
// use Jacobi iterative method
errAllowed = 0;
xIni = new double[n + 1];
System.out
.println("\n\nuse jacobi iterative method to solve it now.input the error allowed:");
errAllowed = input.nextDouble();
System.out.println("\nfrom x1 to x" + n
+ ",input the initialized value(use space to seperate)");
for (int i = 1; i < n + 1; i++)
xIni[i] = input.nextDouble();
System.out.println(erGroup.jacobiIterative(errAllowed, xIni));
System.out.println("\ninput \"c\" to continue:");
contin=input.next();
// use Gauss-Seidel iterative method
errAllowed = 0;
xIni = new double[n + 1];
System.out
.println("\n\nuse Guass-Seidel iterative method to solve it now."
+ "input the error allowed:");
errAllowed = input.nextDouble();
System.out.println("\nfrom x1 to x" + n
+ ",input the initialized value(use space to seperate):");
for (int i = 1; i < n + 1; i++)
xIni[i] = input.nextDouble();
System.out.println(erGroup.gaussSeidelIterative(errAllowed, xIni));
System.out.println("\ninput \"c\" to continue:");
contin=input.next();
// use relaxation iterative method
relaxationParameter = 1;
System.out
.println("\n\nuse relaxation iterative method to solve it now."
+ "input the error allowed:");
errAllowed = input.nextDouble();
System.out.println("\nfrom x1 to x" + n
+ ",input the initialized value(use space to seperate):");
for (int i = 1; i < n + 1; i++)
xIni[i] = input.nextDouble();
System.out.println("input the relaxation parameter:");
relaxationParameter = input.nextDouble();
System.out.println(erGroup.relaxationIterative(errAllowed, xIni,
relaxationParameter));
System.out
.println("\n input another linear equation group? y/n:");
another = input.next();
} while (another.equalsIgnoreCase("y"));
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -