/** * Basic Algorithms, V22.0310.003, Fall 1999 (Yap) * * This Matrix Class illustrates the use of 2-dimensional arrays * * Constructors: * Matrix(n): gives an uninitialized nxn matrix * Matrix(n,seed): gives a random nxn matrix of doubles in [0,1] * Matrix(n,flag): gives zero (flag=false) or identity nxn matrix * * Public Methods: * static boolean equal(M,N): matrix equality * static Matrix add(M,N): matrix addition * static Matrix mul(M,N): matrix multiplication * public void dump(): prints out THIS matrix * public void main(String): main */ import java.util.*; // import java.lang.Math.*; // alternative source of randomness public class Matrix { private int size; // Assert: n>0 private double[][] entry; // Initialize random number generator: private String name; private static Random R = new Random((long)12345); //********************************************************** //********** constructors ********************************** //********************************************************** // un-initialized matrix public Matrix(int n) { int i; int j; size = n; entry = new double [n][n]; // uninitialized } // Matrix(n) // identity or zero matrix: flag=true => identity public Matrix(int n, boolean flag) { int i; int j; size = n; entry = new double [n][n]; for (i = 0; i