Menu

Friday 20 November 2015

MatrixMaths Class (Java Concept)

package matrix;

/**
 *
 * Adeniran Adetunji
 */
public class MatrixMath extends MatrixC {
   
   
   double [][] addMatrix(double[][]augendMatrix, double[][]addendMatrix)
   {
       int x = augendMatrix.length;
       int y = augendMatrix[0].length;
       double [][]totalMatrix = new double[x][y];
     
     
       if((augendMatrix.length==addendMatrix.length)
               &&(augendMatrix[0].length==addendMatrix[0].length))
       {
           for(int i=0; i<augendMatrix.length; i++)
           {
               for (int k=0; k<augendMatrix[i].length; k++)
               {
                   totalMatrix[i][k]=getElement(augendMatrix, i, k )+
                              getElement(addendMatrix, i, k);
               }
           }
         
       }
       else
       {
           System.out.println("Matrix a not of the same dimension");
           System.out.println("Matrix Cannot be added");
       }
     
       return totalMatrix;
   }
   
}

No comments:

Post a Comment

Please drop your comment here, thanks.