package com.imsl.test.example.math; import com.imsl.math.*; /** *
* Solves a small linear system with the Generalized Minimum Residual (GMRES) * method. *
* * A solution to a small linear system is found. The coefficient matrix is * stored as a full matrix and no preconditioning is used. Typically, * preconditioning is required to achieve convergence in a reasonable number of * iterations. * * @see Code * @see Output */ public class GenMinResEx1 implements GenMinRes.Function { // If A were to be read in from some outside source the // code to read the matrix could reside in a constructor. static private double a[][] = { {33.0, 16.0, 72.0}, {-24.0, -10.0, -57.0}, {18.0, -11.0, 7.0} }; static private double b[] = {129.0, -96.0, 8.5}; /** * Obtains the multiplication of the matrixa
and the input
* p
. The result is returned in z
.
*
* @param p a double
array with
* p.length
=a[0].length
* @param z a double
array
*/
@Override
public void amultp(double p[], double z[]) {
double[] result;
result = Matrix.multiply(a, p);
System.arraycopy(result, 0, z, 0, z.length);
}
public static void main(String args[]) throws Exception {
int n = 3;
GenMinResEx1 atp = new GenMinResEx1();
// Construct a GenMinRes object
GenMinRes gnmnrs = new GenMinRes(n, atp);
// Solve Ax = b
new PrintMatrix("x").print(gnmnrs.solve(b));
}
}