Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Finding a determinant of matrix

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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!
    Attached Files Attached Files


  2. #2
    Banned
    Join Date
    Jul 2013
    Posts
    49
    Thanks
    1
    Thanked 5 Times in 4 Posts

    Default Re: Finding a determinant of matrix

    Matrix Determinant - Professor Java


    This was where i mastered the art....

  3. #3
    Junior Member
    Join Date
    Jul 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Finding a determinant of matrix

    Page1.jpgPage2.jpg

    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?
    Attached Images Attached Images

  4. #4
    Junior Member
    Join Date
    Jul 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Finding a determinant of matrix

    package iotest;
    import java.util.*;
    import java.io.*;
    import java.io.BufferedWriter;
    import java.io.FileWriter;

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

    String file_name = "C:/temp/testMatrix.txt";
    ReadFile result = new ReadFile(file_name);
    int numberOfLines = ReadFile.readLines();
    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));
    ReadFile.writeTextFile("C:/temp/testOutPutDeterminant.txt", "Final");


    } // for loop ends
    //temp3 = 0;
    }

    }//

Similar Threads

  1. Matrix Program
    By panzer in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 30th, 2013, 06:15 AM
  2. Printing the following Matrix
    By justfun87 in forum Loops & Control Statements
    Replies: 2
    Last Post: June 23rd, 2013, 09:31 AM
  3. Knapsack problem , check if matrix can fill list of smaller matrix list.
    By ofirattia in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 8th, 2012, 01:20 PM
  4. Help with Identity matrix!
    By javabeginner123456 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 9th, 2011, 06:42 PM
  5. Adding two matrix together
    By papated21 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 2nd, 2011, 01:52 PM