PHP Classes

File: test.php

Recommend this page to a friend!
  Classes of zinsou A.A.E.Moïse   PHP Matrix Arithmetic Library   test.php   Download  
File: test.php
Role: Example script
Content type: text/plain
Description: example script
Class: PHP Matrix Arithmetic Library
Perform math operations with matrices
Author: By
Last change: Test for new version 2.0.0
Date: 6 years ago
Size: 1,846 bytes
 

Contents

Class file image Download
<?php
require_once('./matrix.class.php');
echo
'<h2>Example of matrix:<img src="./example.png"/></h2>';
echo
'<pre>';
$hous=new Matrix(array(array(4,-30,60,-35),array(-30,300,-675,420),array(60,-675,1620,-1050),array(-35,420,-1050,700)));
echo
'<h2>Calculation of the determinant</h2>';
var_dump($hous->getDet());

echo
'<h2>Calculation of eigenvalues</h2>';

var_dump($hous->getEigens());
echo
'<h2>Calculation of the inverse</h2>';

var_dump($hous->lu_reversed());
echo
'<h2>Different factorizations </h2>';

echo
'<h3>LU factorization </h3>';
$op=$hous->ludcmp2();
// var_dump($op);
$u=Matrix::Op($op['L'],$op['U'],'*');
var_dump($u);

echo
'<h3>Cholesky factorization </h3>';

$op=$hous->CholeskyLLTdcmp();
// var_dump($op);
$u=Matrix::Op($op,$op->transposed(),'*');
var_dump($u);

echo
'<h3>Singular values decomposition </h3>';

$svd=$hous->svdcmp();
// var_dump($svd);

$a=Matrix::Op(Matrix::Op($svd['U'],$svd['W'],'*'),$svd['V']->transposed(),'*');

var_dump($a);

echo
'<h3>QR factorization </h3>';
$op=$hous->householdertransformations();
// var_dump($op);
$u=Matrix::Op($op['Q'],$op['R'],'*');
var_dump($u);
echo
'<h2>Eigenvalues calculation </h2>';


$hous=new Matrix(array(array(2,-2,0),array(1,5,3),array(-2,1,4)));// must not use deflation on this because of complex eigenvalues
var_dump($hous->getEigens());

$hous=new Matrix(array(array(2,0,1,2),array(0,2,2,3),array(-1,0,0,1),array(3,1,-1,2)));// must not use deflation on this because of complex eigenvalues
var_dump($hous->getEigens());

$hous=new Matrix(array(array(5,4,2,1),array(0,1,-1,1),array(-1,-1,3,0),array(1,1,-1,2)));//but on this yes even if it is not symmetric
var_dump($hous->getEigens());

var_dump($hous->deflation());


var_dump($hous->inverseandshift(3));
var_dump($hous->inversepowerIteration());