0
import Jama.Matrix;

public class T5 {
public static void main(String args[]){
    Matrix C=new Matrix(new double[][]{{1,0,0,},{0,1,0},{0,0,1}});
    Scanner x;
    try {
        x=new Scanner(new File("D://out.txt"));
        for (int i = 0; i < 100; i++) {
            double a1= x.nextDouble();
            Double b1=x.nextDouble();
            double c1=x.nextDouble();
            Matrix data1 = new Matrix(new double[][]{{a1, b1, c1}});
            double a = data1.get(i, 0);
            double b = data1.get(i, 1);
            double c = data1.get(i, 2);
            double[][] val = {{a}, {b}, {c}};
            Matrix A_new = new Matrix(val);
            Matrix newobser = C.times(A_new);
            newobser.print(9, 6);
        }
    }
    catch (Exception e){
        System.out.println(e);
    }
}
}

There is problem with this code. In this code there is a matrix data1 which have three column and 1 rows which iterate over time. I have file in hard disk name out.txt.This file contain 100 rows and 3 columns.I try to take column 1 of out.txt in variable a1,column 2 of out.txt in variable b1,column 3 of out.txt in variable c1.Then input that a1,b1,c1 in Matrix data1.Here I use JAMA matrix which is a in build matrix package. Get and print, times(use for matrix multiplication) are functions of JAMA matrix package. How could I proceed to taken input from an outside file?My process doesn't work.

Encipher
  • 1,370
  • 1
  • 14
  • 31
  • 1
    What does the content in your file look like? – ernest_k May 05 '18 at 13:47
  • `3.575008 -3.331063 2.346296` `3.576784 -3.329287 2.351792` `3.578560 -3.327511 2.357288` `3.580336 -3.325735 2.362784` `3.582112 -3.323959 2.368280` ................So on. It is arranged row and column wise. I am unable to show it here due to limited editing features. – Encipher May 05 '18 at 15:27

1 Answers1

0

Try mapping the contents of the file into an object (representing each row) while reading the file line by line; and each record in a line tab or comma separated.

Then iterate over the list of all the objects holding the contents from the file and add them into the matrix.