Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

java Part I: Solving simultaneous equations using the matrix package You will us

ID: 3743220 • Letter: J

Question

java

Part I: Solving simultaneous equations using the matrix package You will use the following files: . matrix.jar documentation found in javadoc > Matrix o e.bat //for those unable to set the PATH and CLASSPATH environment variables . Consider the following set of equations: 1.6x1 + 2.4x2 - 3.7x3-22.10 17.6x1 5.6x2 0.05x3--4.35 -2x 2x2 +25.3x3 -233.70 These equations can be represented in matrix form as Ax b where A is a 3x3 matrix of the coefficients, x is a 3xl matrix of the unknown values, and b is a 3xl matrix of the right-hand side (RHS). This matrix equation can be inverted to solve for the unknowns, x - Ab. Use the matrix package (in the jar file, don't extract the files) and the associated external documentation to solve the above system of equations. You will need to use the import statement and -classpath (or-cp) to compile and run so that you can access the classes in the jar file. You may want to consider using a batch file to speed up compiling and running with a custom classpath. Declare your matrix variables to be type MatrixOperationsInterface. Call your driver Equations.java

Explanation / Answer

Answer :
Take the matrix values as standard input
Equations.java

import java.util.Scanner;

import Jama.Matrix;

public class Equations {

public static void main(String[] args) {

double[][] coeff = new double[3][3];

Scanner s = new Scanner(System.in);

for(int i=0;i<3;i++) {

for(int j=0;j<3;j++) {

coeff[i][j] = s.nextDouble();

}

}

double[][] rhsArray = new double[3][1];

for(int i=0;i<3;i++) {

rhsArray[i][0] = s.nextDouble();

}

Matrix lhsMatrix = new Matrix(coeff);

Matrix rhsMatrix = new Matrix(rhsArray);

Matrix ans = lhsMatrix.solve(rhsMatrix);

System.out.println("x1 is : " + ans.get(0, 0));

System.out.println("x2 is : " + ans.get(1, 0));

System.out.println("x3 is : " + ans.get(2, 0));

//System.out.println(ans);

}

}