This is actually an assigment i have in training at my office. I publish it here so all of you can review it. I hope this will help you solve problem, mainly for you who is learning basic of programming.

Assumption: matrices static size is 2×2 for number 8 and 9.

General – These methods required by the operations bellow

Methods getRowColumn
INIT anyValue pass it reference
REPEAT
GET anyValue
IF anyValue<=0 THEN
SHOW warning message
END IF
UNTIL anyValue>0

1. Matrices Addition
INIT rowNumber
INIT columnNumber
CALL getRowColumn with rowNumber
CALL getRowColumn with columnNumber
INIT two dimensional array matricesA with rowNumber as row size and columnNumber as column size
INIT two dimensional array matricesB with rowNumber as row size and columnNumber as column size
INIT two dimensional array matricesZ with rowNumber as row size and columnNumber as column size
FOR each row of matricesA
FOR column of matricesA
GET value for matricesA(row, column)
END FOR
END FOR
FOR each row of matricesB
FOR each column of matricesB
GET value for matricesB(row, column)
END FOR
END FOR
FOR each i from zero to row size of matricesZ
FOR each j from zero to column size of matricesZ
CALCULATE matricesZ(i, j) as sum of matricesA(i, j) and matricesB(i, j)
END FOR
END FOR
FOR each row of matricesZ
FOR each column of matricesZ
SHOW value of matricesZ(row, column)
END FOR
END FOR

2. Matrices Subtraction
INIT rowNumber
INIT columnNumber
CALL getRowColumn with rowNumber
CALL getRowColumn with columnNumber
INIT two dimensional array matricesA with rowNumber as row size and columnNumber as column size
INIT two dimensional array matricesB with rowNumber as row size and columnNumber as column size
INIT two dimensional array matricesZ with rowNumber as row size and columnNumber as column size
FOR each row of matricesA
FOR each column of matricesA
GET value for matricesA(row, column)
END FOR
END FOR
FOR each row of matricesB
FOR each column of matricesB
GET value for matricesB(row, column)
END FOR
END FOR
FOR each i from zero to row size of matricesZ
FOR each j from zero to column size of matricesZ
CALCULATE matricesZ(i, j) as matricesA(i, j) subtracted by matricesB(i, j)
END FOR
END FOR
FOR each row of matricesZ
FOR each column of matricesZ
SHOW value of matricesZ(row, column)
END FOR
END FOR

3. Matrices Multiplication
INIT rowA
INIT columnA
INIT rowB
INIT columnB
CALL getRowColumn with rowA
CALL getRowColumn with columnA
REPEAT
CALL getRowColumn with rowB
IF rowB not equal to columnA THEN
SHOW warning message
SET rowB to zero
END IF
UNTIL row B equal to columnA
CALL getRowColumn with columnB
INIT two dimensional array matricesA with rowA as row size and columnA as column size
INIT two dimensional array matricesB with rowB as row size and columnB as column size
INIT two dimensional array matricesZ with rowA as row size and columnB as column size
FOR each row of matricesA
FOR each column of matrices A
GET value for matricesA(row, column)
END FOR
END FOR
FOR each row of matricesB
FOR each column of matricesB
GET value for matricesB(row, column)
END FOR
END FOR
FOR i=0 to row size of matricesA
FOR j=0 to column size of matricesB
FOR z=0 to column size of matricesA
CALCULATE matricesZ[i][j] = matricesZ[i][j] + (matricesA[i][z] * matricesB[z][j])
END FOR
END FOR
FOR each row of matricesZ
FOR each column of matricesZ
SHOW value of matricesZ(row, column)
END FOR
END FOR


4. Multiplication of Matrices by a Scalar
INIT rowNumber
INIT columnNumber
INIT scalarValue
CALL getRowColumn with rowNumber
CALL getRowColumn with columnNumber
INIT two dimensional array matricesA with rowNumber as row size and columnNumber as column size
FOR each row of matricesA
FOR each column of matricesA
GET value for matricesA(row, column)
END FOR
END FOR
GET any value for scalarValue
FOR each row of matricesA
FOR each column of matricesA
CALCULATE matricesA(row, column) as matricesA(row, column) multiplied by scalarValue
END FOR
END FOR
FOR each row of matricesA
FOR each column of matricesA
SHOW value of matricesA(row, column)
END FOR
END FOR

5. Division of Matrices by a Scalar
INIT rowNumber
INIT columnNumber
INIT scalarValue
CALL getRowColumn with rowNumber
CALL getRowColumn with columnNumber
INIT two dimensional array matricesA with rowNumber as row size and columnNumber as column size
FOR each row of matricesA
FOR each column of matricesA
GET value for matricesA(row, column)
END FOR
END FOR
GET any value for scalarValue
FOR each row of matricesA
FOR each column of matricesA
CALCULATE matricesA(row, column) as matricesA(row, column) divided by scalarValue
END FOR
END FOR
FOR each row of matricesA
FOR each column of matricesA
SHOW value of matricesA(row, column)
END FOR
END FOR

6. How to define an Orthogonal Matrices
INIT two dimensional array matricesA with row size equal to two and column size equal to two
INIT two dimensional array transMatricesA with row size equal to two and column size equal to two
INIT two dimensional array inverseMatricesA with row size equal to two and column size equal to two
INIT determinant
INIT constantX
INIT isEqual
SET isEqual to true
FOR each row of matricesA
FOR each column of matricesA
GET value for matricesA(row, column)
END FOR
END FOR
FOR each i from zero to row size of transMatricesA
FOR each j from zero to column size of transMatricesA
SET transMatricesA(i, j) to matricesA(j, i)
END FOR
END FOR
CALCULATE determinant as matricesA(1,1) * matricesA(2,2) – matricesA(1,2) * matricesA(2,1)
CALCUTATE constantX as one divided by determinant
SET inversematricesA(1,1) to matricesA(2,2)
SET inversematricesA (2,2) to matricesA(1,1)
SET inversematricesA (1,2) as minus matricesA(1,2)
SET inversematricesA (2,1) as minus matricesA(2,1)
FOR each each row of matricesA
FOR each column of matricesA
IF transMatriceA(row, column) is not as equal as inverseMatricesA(row, column)
SHOW warning message
SET isEqual to false
EXIT for loop
END IF
END FOR
END FOR
IF isEqual THEN
SHOW equal message
END IF

7. How to define Matrices Transpose
INIT rowNumber
INIT columnNumber
CALL getRowColumn with rowNumber
CALL getRowColumn with columnNumber
INIT two dimensional array matricesA with rowNumber as row size and columnNumber as column size
INIT two dimensional array transMatricesA with columnNumber as row size and rowNumber as column size
FOR each row of matricesA
FOR each column of matricesA
GET value for matricesA(row, column)
END FOR
END FOR
FOR each i from zero to row size of transMatricesA
FOR each j from zero to column size of transMatricesA
SET transMatricesA(i, j) to matricesA(j, i)
END FOR
END FOR
FOR each row of transMatricesA
FOR each column of transMatricesA
SHOW value of transMatricesA(row, column)
END FOR
END FOR

8. How to define Matrices Inverse
INIT two dimensional array matricesA with row size equal to two and column size equal to two
INIT two dimensional array inverseMatrices with row size equal to two and column size equal to two
INIT determinant
INIT constantX
FOR each row of matricesA
FOR each column of matricesA
GET value for matricesA(row, column)
END FOR
END FOR
CALCULATE determintant as matricesA(1,1) * matricesA(2,2) – matricesA(1,2) * matricesA(2,1)
CALCULATE constantX as one divided by determinant
SET tempValue to matricesA(1,1)
SET matricesA(1,1) to matricesA(2,2)
SET matricesA(2,2) to tempValue
SET tempValue to matricesA(1,2)
SET matricesA(1,2) to matricesA(2,1)
SET matricesA(2,1) to tempValue
SET matricesA(1,2) as minus matricesA(1,2)
SET matricesA(2,1) as minus matricesA(2,1)
FOR each i from zero to row size of inverseMatrices
FOR each j from zero to column size of inverseMatrices
CALCULATE inverseMatrices(i,j) as matricesA(i,j) multiplied by constantX
END FOR
END FOR
FOR each row of inverseMatrices
FOR each column of inverseMatrices
CALCULATE inverseMatrices(row,column)
END FOR
END FOR

9. How to calculate Matrices Determinant
INIT two dimensional array matricesA with row size equal to two and column size equal to two
INIT determinant
FOR each row of matricesA
FOR each column of matricesA
GET value for matricesA(row, column)
END FOR
END FOR
CALCULATE determinant as matricesA(1,1) * matricesA(2,2) – matricesA(1,2) * matricesA(2,1)SHOW determinant


  • Share/Bookmark

Leave a Reply

(required)

(required)

© 2010 IMS' Blog Suffusion WordPress theme by Sayontan Sinha