Documentation can be found at http://tcllib.sourceforge.net/doc/math.html
This package is a part of the Tcllib distribution.
It contains:
(null) choose a number between 0 and 1 val choose a number between 0 and val val1 val2 choose a number between val1 and val2
Things to keep in mind:
If you pick tcllib up from its CVS repository, you will be able to get access to even more functionality:
FF - 2007-06-11 - I implemented some missing features of math::linearalgebra. (If they are going to be included in tcllib -I hope for that- you can delete this comment.)
package require math::linearalgebra namespace eval ::math::linearalgebra { namespace export joinMatrix cancelrow cancelcol namespace export cofactor cofactorMatrix namespace export adjointMatrix namespace export determinant invert } # joinMatrix -- # Join two matrices along the specified dimension # Arguments: # dim Dimension to join [1,2] # mv1,mv2 Matrices to be treated # # Result: # Matrix result of the join # proc ::math::linearalgebra::joinMatrix { dim mv1 mv2 } { set result $mv1 switch -exact -- $dim { 1 { foreach r $mv2 {lappend $result $r} } 2 { set l [llength $mv1] for {set i 0} {$i < $l} {incr i} { lset result $i [concat [lindex $mv1 $i] [lindex $mv2 $i]] } } default { return -code error "do we work on ${dim}D matrices?" } } return $result } # cancelrow -- # Return a matrix minus the specified row # Arguments: # matrix Matrix to work on # row to delete # # Result: # Matrix result of the operation # proc ::math::linearalgebra::cancelrow { matrix row } { return [concat [lrange $matrix 0 $row-1] [lrange $matrix $row+1 end]] } # cancelrow -- # Return a matrix minus the specified column # Arguments: # matrix Matrix to work on # col to delete # # Result: # Matrix result of the operation # proc ::math::linearalgebra::cancelcol { matrix col } { set result {} foreach r $matrix { lappend result [concat [lrange $r 0 $col-1] [lrange $r $col+1 end]] } return $result } # cofactor -- # Compute the cofactor of the specified element # Arguments: # matrix Matrix to work on # row # col # # Result: # The cofactor of element at a{row,col} # proc ::math::linearalgebra::cofactor { matrix row col } { set submatrix [cancelcol [cancelrow $matrix $row] $col] return [determinant $submatrix] } # cofactorMatrix -- # Compute the cofactor of the specified matrix # Arguments: # matrix Matrix to work on # # Result: # The cofactor of specified matrix # proc ::math::linearalgebra::cofactorMatrix { matrix } { set result {} lassign [shape $matrix] rows cols for {set i 0} {$i < $rows} {incr i} { set newrow {} for {set j 0} {$j < $cols} {incr j} { lappend newrow [cofactor $matrix $i $j] } lappend result $newrow } return $result } # adjointMatrix -- # The adjoint matrix is the transpose of the cofactor matrix # Arguments: # matrix # # Result: # The adjoint matrix # proc ::math::linearalgebra::adjointMatrix {matrix} { return [transpose [cofactorMatrix $matrix]] } # determinant -- # Compute the cofactor of the specified element # Arguments: # matrix Matrix to work on # row # col # # Result: # The cofactor of element at a{row,col} # proc ::math::linearalgebra::determinant { matrix } { set shape [shape $matrix] if { [lindex $shape 0] != [lindex $shape 1] } { return -code error "determinant only defined for a square matrix" } switch -exact -- [join $shape x] { 1x1 { return [lindex [lindex $matrix 0] 0] } 2x2 { lassign [getrow $matrix 0] a b lassign [getrow $matrix 1] c d return [expr {($a*$d)-($c*$b)}] } default { set det 0 set sign 0 set row_no 0 foreach row $matrix { set sign [expr {($sign==1)?(-1):(1)}] set det [expr { $det+$sign*[lindex $row 0]*[cofactor $matrix $row_no 0] }] incr row_no } return $det } } } # invert -- # Perform the matrix inversion using the adjoint method # Note: probably the Gauss-Jordan elimination over an # augmented matrix is *much* faster. # Arguments: # matrix Matrix to work on # # Result: # The inverted matrix # proc ::math::linearalgebra::invert { matrix } { set det [determinant $matrix] if { $det == 0 } { return -code error "cannot invert a singular matrix" } return [expr pow($det,-1)*[adjointMatrix $matrix]] }
Category Package, subset Tcllib, Category Mathematics