PHP Online Compiler
Example: Program to Find Normal and Trace of a Matrix in PHP using For loop
C
C++
C#
Java
Python
PHP
main.php
STDIN
Run
<?php // Program to Find Normal and Trace of a Matrix in PHP using For loop $x = array( array(43, 54, 4), array(3, 54, 23), array(54, 23, 5) ); // $x - To store the matrix elements of 3 x 3 dimension $sum = 0; $sum1 = 0; $a = 0; for ($i = 0; $i < count ($x); $i++) { for ($j = 0; $j < count ($x[$i]); $j++) { $a = $x[$i][$j] * $x[$i][$j]; $sum1 += $a; } $sum = $sum + $x[$i][$i]; } $normal = sqrt ($sum1); echo "The normal of the given matrix is: ".$normal; echo "\n\nThe Trace of the given matrix is: ".$sum."\n"; ?>
Output
Clear
ADVERTISEMENTS