next up previous contents
Next: Tests of slicing into Up: Getting started and examples Previous: Tests of basic operations   Contents

Tests of linear algebra operations

The file test_linear.py tests linear algebra operations, including inverse and solving equations. Results are at 3.3


#!/usr/bin/env python
# (C) 2000 Huaiyu Zhu <hzhu@users.sourceforge.net>.  Licence: GPL
# $Id: test_linear.py,v 1.4 2000/07/26 20:58:27 hzhu Exp $
"""
Test linear algebra for Matrix module
"""

from MatPy.Matrix import *
from MatPy.mfuncs import sqrtm, expm, logm

print "-"*40, "matrix functions"
A = rand((3,3))
print A.typecode, norm(A + A - 2* A)
print norm(A*A*A / A /(A*A) - eye(3))
print norm(A**2 - A*A)
B = sqrtm(A)
print B 
print B.typecode, norm(A - B*B), mnorm(A - B*B)

x = rand((3,1))
y = A*x
print solve(A,y)
print y.T/A.T

C = logm(A)
D = expm(C)
print C.typecode, D.typecode, norm(D-A)


Result obtained with
>>> from MatPy.tests import test_linear


---------------------------------------- matrix functions
d 0.0
2.17261484018e-13
1.42177919159e-15
[ 0.829  0.26   0.446
  0.587  0.631  0.101
 -0.0228  0.648  0.772 ]
d 7.79136136032e-16 1.13356978563e-15
[ 0.497
  0.223
  0.216 ]
[ 0.497  0.223  0.216 ]
d d 1.53536257996e-15



Huaiyu Zhu
2002-03-23