matrix math source

# matrix math source - <?php/Definiing the System of...

This preview shows pages 1–3. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: <?php //--------------------------------------- //Definiing the System of equations. \$coeffs = array () ; \$coeffs = array ( 3 , 5 , 11 ) ; \$coeffs = array ( 1 ,- 2 , 9 ) ; \$coeffs = array (- 5 , 2 , 2 ) ; \$vars = array () ; \$vars = array ( " x " ) ; \$vars = array ( " y " ) ; \$vars = array ( " z " ) ; \$rhs = array () ; \$rhs = array ( 11 ) ; \$rhs = array ( 8 ) ; \$rhs = array ( 7 ) ; //--------------------------------------- //Calling the functions to Display the problem //and solve the problem. \$problem = dispProblem ( \$coeffs , \$vars , \$rhs ) ; \$solution = solve ( \$coeffs , \$vars , \$rhs ) ; //--------------------------------------- //Printing the System of Equations and the Soltion print ( " <pre> " ) ; print ( \$problem ) ; print ( \$solution ) ; print ( " </pre> " ) ; //--------------------------------------- //Showing the details of the solution //* \$details = dispSolutionDetails ( \$coeffs , \$vars , \$rhs ) ; print ( " <pre> " ) ; //print("-------------------------------------------------<br /><br /><br />"); print ( \$details ) ; print ( " </pre> " ) ; //*/ function determinate ( \$matrix ) {{{ \$rowOne = \$matrix [ ] ; \$colsCount = count ( \$rowOne ) ; \$rowsCount = count ( \$matrix ) ; if ( \$colsCount != \$rowsCount ) { return " The specified matrix is not square. The Determinate cannot be calculated. " ; } if ( \$colsCount == 2 ) { \$rowOne = \$matrix [ ] ; \$rowTwo = \$matrix [ 1 ] ; \$a = \$rowOne [ ] ; \$b = \$rowOne [ 1 ] ; \$c = \$rowTwo [ ] ; \$d = \$rowTwo [ 1 ] ; \$det = \$a * \$d- \$c * \$b ; return \$det ; } \$detArray = array () ; for ( \$i = ; \$i < \$colsCount ; \$i ++ ) { \$coeff = \$rowOne [ \$i ] ; if ( \$i % 2 != ) { \$coeff = \$coeff * (- 1 ) ; } \$subMatrix = array () ; for ( \$j = 1 ; \$j < \$rowsCount ; \$j ++ ) { \$row = \$matrix [ \$j ] ; \$subRow = array () ; for ( \$k = ; \$k < \$colsCount ; \$k ++ ) { if ( \$i != \$k ) { \$subRow = \$row [ \$k ] ; } } \$subMatrix = \$subRow ; } \$detSub = determinate ( \$subMatrix ) ; \$number = \$coeff * \$detSub ; \$detArray = \$number ; } \$detSum = array_sum ( \$detArray ) ; return \$detSum ; }}} function inverse ( \$matrix ) {{{ \$det = determinate ( \$matrix ) ; if ( \$det == ) { return " inside the if This matrix is not invertible. " ; } if ( count ( \$matrix ) == 2 ) { \$inverse = array () ; \$rowOne = array () ; \$rowOne = \$matrix [ 1 ][ 1 ] / \$det ; \$rowOne = - 1 * \$matrix [ ][ 1 ] / \$det ; \$inverse = \$rowOne ; \$rowTwo = array () ; \$rowTwo = - 1 * \$matrix [ 1 ][ ] / \$det ; \$rowTwo = \$matrix [ ][ ] / \$det ; \$inverse = \$rowTwo ; return...
View Full Document

{[ snackBarMessage ]}

### Page1 / 8

matrix math source - <?php/Definiing the System of...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online