# Finding a determinant of matrix

• July 13th, 2013, 07:29 PM
sneupa1
Finding a determinant of matrix
I am new to java programming. I am working on a program that takes a text file and calculates the determinant.
The text file is in the following format:

dimension
matrix like shown below:

1
1
2
1 2
2 3
3
1 2 3
2 3 4
4 5 6

I have attached my classes. I am stuck in not being able to print the output for all the matrices.
Any help will be deeply appreciated!
• July 14th, 2013, 06:03 AM
Re: Finding a determinant of matrix
Matrix Determinant - Professor Java

This was where i mastered the art....:)
• July 15th, 2013, 02:47 PM
sneupa1
Re: Finding a determinant of matrix
Attachment 2195Attachment 2197

I could not figure out why the variable temp3 gets erased after I call that method findDeterminant with test2B argument. First iteration gives me right result. On the second iteration it is my temp3 is reset to 0 so I get the same result over all the iterations on the loop.

Any idea why this does not give me right result?
• July 15th, 2013, 02:51 PM
sneupa1
Re: Finding a determinant of matrix
package iotest;
import java.util.*;
import java.io.*;
import java.io.BufferedWriter;
import java.io.FileWriter;

{
public static void main(String [] args) throws IOException
{
for(int k =0; k<8; k++ )
{

String file_name = "C:/temp/testMatrix.txt";
String[] testFile = result.openFile();

int temp1 = 0;
int temp2 = 0;
int temp3 =0;
int temp4 = 0;
int size = 0;
int [] dimension = new int [1];

//Find the value of dimension of matrix
for(int i =temp3; i<temp3+1; i++)
{
try
{
dimension[temp4] = Integer.parseInt(testFile[i]);
size = dimension[temp4];
System.out.println("Dimension of Matrix is :"+ size );
ReadFile.writeTextFile("C:/temp/testOutPutDeterminant.txt", "Dimension of Matrix is :");

} catch (NumberFormatException nfe) {};

}

// create arrays for the matrices

String[] test2 = new String[size];
String[] [] test2A = new String[test2.length] [size];
int [] [] test2B = new int [test2.length][size];

for(int i = temp3+1; i <= temp3 + size ; i++)
{

System.out.println(testFile[i]);

test2 [temp2] = testFile[i];
temp2++;
temp1 = i;
}

temp2 = 0;
temp3 = temp1++;

System.out.println("Determinant of the above matrix is: ");

// creating a multi dimension array
int r = 0;
for (String test : test2)
{
test2A[r++] = test.split("\\s");
}
// convert a array of string into an array of integer

for (int i = 0; i < test2A.length; i++)
{
for(int j = 0; j < test2A.length; j++)
{
try {
test2B[i][j] = Integer.parseInt(test2A[i][j]);

} catch (NumberFormatException nfe) {};

}

}

System.out.println(Determinant.findDeterminant(tes t2B));