Merge pull request #330 from JeonSeongBae/JeonSeongBae

Thanks for contribution
This commit is contained in:
Christian Bender 2018-03-29 23:52:05 +02:00 committed by GitHub
commit 6959592744
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -35,6 +35,7 @@ public class Matrix {
//test operations (valid)
System.out.println("2 * m2:\n" + m2.scale(2));
System.out.println("m2 / 2:\n" + m2.divide(2));
System.out.println("m2 + m3:\n" + m2.plus(m3));
System.out.println("m2 - m3:\n" + m2.minus(m3));
System.out.println("m2 * m3: \n"+m2.multiply(m3));
@ -118,6 +119,24 @@ public class Matrix {
return new Matrix(newData);
}
/**
* Returns this matrix divided by a factor. That is, computes sA where s is a
* constant and A is a matrix (this object).
*
* @param scalar : value to divide by
* @return A new matrix scaled by the scalar value
*/
public Matrix divide(int scalar) {
int[][] newData = new int[this.data.length][this.data[0].length];
for (int i = 0; i < this.getRows(); ++i)
for(int j = 0; j < this.getColumns(); ++j)
newData[i][j] = this.data[i][j] / scalar;
return new Matrix(newData);
}
/**
* Adds this matrix to another matrix.