Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Matrix(String path) throws Exception {
- BufferedReader reader = new BufferedReader(new FileReader(path));
- List<List<Double>> fileMatrix = new ArrayList<List<Double>>();
- String line;
- while ((line = reader.readLine()) != null) {
- List<Double> matrixLine = new ArrayList<Double>();
- Scanner scanner = new Scanner(line);
- while (scanner.hasNextDouble()) {
- matrixLine.add(scanner.nextDouble());
- }
- fileMatrix.add(matrixLine);
- }
- if (fileMatrix.size() == 0 || fileMatrix.size() != fileMatrix.get(0).size() - 1) {
- System.err.println("Wrong matrix format");
- throw new Exception();
- }
- size = fileMatrix.size();
- double[][] matrix = new double[size][];
- for (int i = 0; i < size; i++) {
- matrix[i] = new double[size + 1];
- for (int j = 0; j < size + 1; j++) {
- matrix[i][j] = fileMatrix.get(i).get(j);
- }
- }
- double[][] inverseMatrix = new double[size][];
- for (int i = 0; i < size; i++) {
- inverseMatrix[i] = new double[size];
- inverseMatrix[i][i] = 1.0;
- }
- this.matrix = matrix;
- this.transform = Transform.NONE;
- this.inverseMatrix = inverseMatrix;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement