Example #1
0
<?php

/**
 * Example of using the Math_Matrix class
 * @author Jesus M. Castagnetto
 * 
 * $Id: ex_math_matrix.php,v 1.1 2003/11/01 23:35:26 jmcastagnetto Exp $
 */
require_once 'Math/Matrix.php';
//require_once '../Matrix.php';
$data = array(array(1.0, 2.0, 3.0, 4.0), array(5.0, 6.0, 7.0, 8.0), array(1.0, 4.0, 5.0, 7.0), array(2.0, 3.0, -3.0, 4.0));
$m = new Math_Matrix($data);
//print_r($m);
echo $m->toString() . "\n";
$det = $m->determinant();
echo "Determinant = {$det}\n";
echo "Trace = " . $m->trace() . "\n";
echo "Euclidean Norm = " . $m->norm() . "\n";
echo "Normalized Determinant = " . $m->normalizedDeterminant() . "\n";
echo "\nSubmatrix(1,1,2,2)\n";
$n = $m->getSubMatrix(1, 1, 2, 2);
echo $n->toString() . "\n";
$det = $n->determinant();
echo "Determinant = {$det}\n";
echo "Euclidean Norm = " . $n->norm() . "\n";
echo "Normalized Determinant = " . $n->normalizedDeterminant() . "\n";
echo "\nWriting original matrix\n";
$e = Math_Matrix::writeToFile($m, 'writetest.mat', 'csv');
echo "... Reading from file\n";
$p = Math_Matrix::readFromFile('writetest.mat', 'csv');
echo $p->toString() . "\n";