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

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

ID: 3743322 • Letter: P

Question

Part I: Solving simultaneous equations using the matrix package You will use the following files: matrix.iar documentation found in javadoc > Matrix o make.batfor those unable to set the PATH and CLASSPATH environment variables Consider the following set of equations: 1.6x1 +2.4x 3.7x)-22.10 17.6x -5.6x2 0.05x3 4.35 2x 2x 25.3x 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 3x1 matrix of the unknown values, and b is a 3x1 matrix of the right-hand side (RHS). This matrix equation can be inverted to solve for the unknowns, x- A-b. 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

/**********************************************************************

You hadn't included the matrix.jar file. However I searched

the web and found the one that should be used here.

This solution works.

Compile it using:

javac Equations.java -cp ./path/to/matrix.jar

And run with:

java Equations

Do give leave your feedback it it works.

*****************************************************************/

/*****************Equations.java******************************/

import matrix.*;

//Import the package that was given in your documentation

public class Equations {

public static void main(String args[]) {

MatrixOperationsInterface matA = new Matrix(3, 3),

matB = new Matrix(3, 1);

//Initializing first matrix

matA.setElement(1, 1, 1.6);

matA.setElement(1, 2, 2.4);

matA.setElement(1, 3, -3.7);

matA.setElement(2, 1, 17.6);

matA.setElement(2, 2, -5.6);

matA.setElement(2, 3, 0.05);

matA.setElement(3, 1, -2.0);

matA.setElement(3, 2, 2.0);

matA.setElement(3, 3, 25.3);

//Initializing second matrix

matB.setElement(1, 1, -22.10);

matB.setElement(2, 1, -4.35);

matB.setElement(3, 1, 233.70);

//Calculating the resultant matrix by inversing matA and multiplying it with matB

MatrixOperationsInterface result = matA.inverse().multiply(matB);

//Display the result

System.out.printf("x = %.2f y = %.2f z = %.2f ",

result.getElement(1, 1),

result.getElement(2, 1),

result.getElement(3, 1));

}

}