133. PHP Program to find Normal of the given matrix.
How does this program work?
- In this program we are going to learn about how to find Normal of the given matrix using PHP.
- Normal of a matrix is defined as square root of sum of squares of matrix elements.
- And then by using the formula we can find the normal of a matrix.
Here is the code
<html>
<head>
<title>PHP Program To find Normal of the given matrix</title>
</head>
<body>
<?php
// Elements of matrix a
$a = array
(
array(1, 2, 3),
array(4, 5, 6),
array(7, 8, 9)
);
$rows = count($a);
$cols = count($a[0]);
$sum = 0;
//Initially sum declare with 0;
$precision = 4;
echo("Original matrix is: </br>");
// to print Original matrix
for($i = 0; $i < $rows; $i++) {
for($j = 0; $j < $cols; $j++) {
echo ( $a[$i][$j] . " ");
}
echo("</br>" );
}
//Calculate normal of given matrix
for($i = 0; $i < $rows; $i++) {
for($j = 0; $j < $cols; $j++) {
$sum = $sum + $a[$i][$j]*$a[$i][$j];
$norm = sqrt($sum);
}
}
echo "Normal of the given matrix is: ".number_format($norm, $precision);
?>
</body>
</html>

