The EqnSolver Class


The EqnSolver Class

Before we dive into implementing algorithms to solve systems of equations, let us think about the structure of the methods and of the class that will define the methods . The thought process and design strategy will be similar to what was used in Chapter 17, " User -Defined Math Functions." We will define the methods in a class called EqnSolver . This class will be placed in the TechJava.MathLib package, the same package we used to store our user-defined math methods.

The methods in the EqnSolver class are intended to be used by a variety of applications; therefore, we will define the methods to be public and static . The original b vector and/or A matrix will be passed as input arguments to the methods. Any changes made to the A matrix and b vector will persist after the methods return. The b vector will be overwritten to contain the unknown quantities . The A matrix will be modified in a method-specific manner.

We will define five methods in the EqnSolver class, three will solve a system of equations, one will compute the inverse of a matrix, and one will be used to perform something known as partial pivoting. The skeleton form of the EqnSolver class is shown here.

 package TechJava.MathLib; public class EqnSolver {   public static void gaussJordan(double a[][],                                  double b[]) {}   public static void gaussian(double a[][],                               double b[]) {}   public static void luDecomp(double a[][],                               double b[]) {}   public static void invertMatrix(double a[][]) {}   private static void partialPivot(double a[][],                      double b[], int index[][]) {} } 


Technical Java. Applications for Science and Engineering
Technical Java: Applications for Science and Engineering
ISBN: 0131018159
EAN: 2147483647
Year: 2003
Pages: 281
Authors: Grant Palmer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net