Tcl Library Source Code

Changes On Branch linalg-7f082f8667
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch linalg-7f082f8667 Excluding Merge-Ins

This is equivalent to a diff from 69e306a577 to ebcc91a605

2015-04-23
20:50
Merged math::linalg fix. check-in: 837cadf794 user: aku tags: trunk
20:49
Updated docs. Closed-Leaf check-in: ebcc91a605 user: aku tags: linalg-7f082f8667
20:42
math::linearalgebra - Ticket [7f082f8667] - Fixed bungled calculation of eigenvector signs. Extended testsuite with case for this. Version bumped to 1.1.5. check-in: c7d7411746 user: andreask tags: linalg-7f082f8667
19:08
Draft integration of huddle work. Looks to be incomplete. I believe there are yaml changes missing. check-in: 4c78dcbc6f user: andreask tags: huddle-a753cade83
2015-04-21
20:35
Merged logger work into release. check-in: dbfbd27389 user: andreask tags: tcllib-1-17-rc
20:25
logger - Ticket [cf775f72ef] - Fixed handling of level default for initNamespace. Inherit from parent first, if it exists. Bumped to version 0.9.4. Extended testsuite. Updated docs. check-in: 69e306a577 user: andreask tags: trunk
2015-04-15
21:10
Refreshed the embedded docs. check-in: 4545293d4f user: aku tags: trunk

Changes to embedded/man/files/modules/math/linalg.n.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
'\"
'\" Generated from file 'linalg\&.man' by tcllib/doctools with format 'nroff'
'\" Copyright (c) 2004-2008 Arjen Markus <arjenmarkus@users\&.sourceforge\&.net>
'\" Copyright (c) 2004 Ed Hume <http://www\&.hume\&.com/contact\&.us\&.htm>
'\" Copyright (c) 2008 Michael Buadin <relaxkmike@users\&.sourceforge\&.net>
'\"
.TH "math::linearalgebra" n 1\&.1 tcllib "Tcl Math Library"
.\" The -*- nroff -*- definitions below are for supplemental macros used
.\" in Tcl/Tk manual entries.
.\"
.\" .AP type name in/out ?indent?
.\"	Start paragraph describing an argument to a library procedure.
.\"	type is type of argument (int, etc.), in/out is either "in", "out",
.\"	or "in/out" to describe whether procedure reads or modifies arg,






|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
'\"
'\" Generated from file 'linalg\&.man' by tcllib/doctools with format 'nroff'
'\" Copyright (c) 2004-2008 Arjen Markus <arjenmarkus@users\&.sourceforge\&.net>
'\" Copyright (c) 2004 Ed Hume <http://www\&.hume\&.com/contact\&.us\&.htm>
'\" Copyright (c) 2008 Michael Buadin <relaxkmike@users\&.sourceforge\&.net>
'\"
.TH "math::linearalgebra" n 1\&.1\&.5 tcllib "Tcl Math Library"
.\" The -*- nroff -*- definitions below are for supplemental macros used
.\" in Tcl/Tk manual entries.
.\"
.\" .AP type name in/out ?indent?
.\"	Start paragraph describing an argument to a library procedure.
.\"	type is type of argument (int, etc.), in/out is either "in", "out",
.\"	or "in/out" to describe whether procedure reads or modifies arg,
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
..
.BS
.SH NAME
math::linearalgebra \- Linear Algebra
.SH SYNOPSIS
package require \fBTcl  ?8\&.4?\fR
.sp
package require \fBmath::linearalgebra  ?1\&.1?\fR
.sp
\fB::math::linearalgebra::mkVector\fR \fIndim\fR \fIvalue\fR
.sp
\fB::math::linearalgebra::mkUnitVector\fR \fIndim\fR \fIndir\fR
.sp
\fB::math::linearalgebra::mkMatrix\fR \fInrows\fR \fIncols\fR \fIvalue\fR
.sp







|







274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
..
.BS
.SH NAME
math::linearalgebra \- Linear Algebra
.SH SYNOPSIS
package require \fBTcl  ?8\&.4?\fR
.sp
package require \fBmath::linearalgebra  ?1\&.1\&.5?\fR
.sp
\fB::math::linearalgebra::mkVector\fR \fIndim\fR \fIvalue\fR
.sp
\fB::math::linearalgebra::mkUnitVector\fR \fIndim\fR \fIndir\fR
.sp
\fB::math::linearalgebra::mkMatrix\fR \fInrows\fR \fIncols\fR \fIvalue\fR
.sp

Changes to embedded/www/tcllib/files/modules/math/linalg.html.

104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
| <a href="../../../../toc.html">Main Table Of Contents</a>
| <a href="../../../toc.html">Table Of Contents</a>
| <a href="../../../../index.html">Keyword Index</a>
| <a href="../../../../toc0.html">Categories</a>
| <a href="../../../../toc1.html">Modules</a>
| <a href="../../../../toc2.html">Applications</a>
 ] <hr>
<h1 class="title">math::linearalgebra(n) 1.1 tcllib &quot;Tcl Math Library&quot;</h1>
<div id="name" class="section"><h2><a name="name">Name</a></h2>
<p>math::linearalgebra - Linear Algebra</p>
</div>
<div id="toc" class="section"><h2><a name="toc">Table Of Contents</a></h2>
<ul class="toc">
<li class="section"><a href="#toc">Table Of Contents</a></li>
<li class="section"><a href="#synopsis">Synopsis</a></li>







|







104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
| <a href="../../../../toc.html">Main Table Of Contents</a>
| <a href="../../../toc.html">Table Of Contents</a>
| <a href="../../../../index.html">Keyword Index</a>
| <a href="../../../../toc0.html">Categories</a>
| <a href="../../../../toc1.html">Modules</a>
| <a href="../../../../toc2.html">Applications</a>
 ] <hr>
<h1 class="title">math::linearalgebra(n) 1.1.5 tcllib &quot;Tcl Math Library&quot;</h1>
<div id="name" class="section"><h2><a name="name">Name</a></h2>
<p>math::linearalgebra - Linear Algebra</p>
</div>
<div id="toc" class="section"><h2><a name="toc">Table Of Contents</a></h2>
<ul class="toc">
<li class="section"><a href="#toc">Table Of Contents</a></li>
<li class="section"><a href="#synopsis">Synopsis</a></li>
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<li class="section"><a href="#copyright">Copyright</a></li>
</ul>
</div>
<div id="synopsis" class="section"><h2><a name="synopsis">Synopsis</a></h2>
<div class="synopsis">
<ul class="requirements">
<li>package require <b class="pkgname">Tcl <span class="opt">?8.4?</span></b></li>
<li>package require <b class="pkgname">math::linearalgebra <span class="opt">?1.1?</span></b></li>
</ul>
<ul class="syntax">
<li><a href="#1"><b class="cmd">::math::linearalgebra::mkVector</b> <i class="arg">ndim</i> <i class="arg">value</i></a></li>
<li><a href="#2"><b class="cmd">::math::linearalgebra::mkUnitVector</b> <i class="arg">ndim</i> <i class="arg">ndir</i></a></li>
<li><a href="#3"><b class="cmd">::math::linearalgebra::mkMatrix</b> <i class="arg">nrows</i> <i class="arg">ncols</i> <i class="arg">value</i></a></li>
<li><a href="#4"><b class="cmd">::math::linearalgebra::getrow</b> <i class="arg">matrix</i> <i class="arg">row</i> <span class="opt">?imin?</span> <span class="opt">?imax?</span></a></li>
<li><a href="#5"><b class="cmd">::math::linearalgebra::setrow</b> <i class="arg">matrix</i> <i class="arg">row</i> <i class="arg">newvalues</i> <span class="opt">?imin?</span> <span class="opt">?imax?</span></a></li>







|







128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<li class="section"><a href="#copyright">Copyright</a></li>
</ul>
</div>
<div id="synopsis" class="section"><h2><a name="synopsis">Synopsis</a></h2>
<div class="synopsis">
<ul class="requirements">
<li>package require <b class="pkgname">Tcl <span class="opt">?8.4?</span></b></li>
<li>package require <b class="pkgname">math::linearalgebra <span class="opt">?1.1.5?</span></b></li>
</ul>
<ul class="syntax">
<li><a href="#1"><b class="cmd">::math::linearalgebra::mkVector</b> <i class="arg">ndim</i> <i class="arg">value</i></a></li>
<li><a href="#2"><b class="cmd">::math::linearalgebra::mkUnitVector</b> <i class="arg">ndim</i> <i class="arg">ndir</i></a></li>
<li><a href="#3"><b class="cmd">::math::linearalgebra::mkMatrix</b> <i class="arg">nrows</i> <i class="arg">ncols</i> <i class="arg">value</i></a></li>
<li><a href="#4"><b class="cmd">::math::linearalgebra::getrow</b> <i class="arg">matrix</i> <i class="arg">row</i> <span class="opt">?imin?</span> <span class="opt">?imax?</span></a></li>
<li><a href="#5"><b class="cmd">::math::linearalgebra::setrow</b> <i class="arg">matrix</i> <i class="arg">row</i> <i class="arg">newvalues</i> <span class="opt">?imin?</span> <span class="opt">?imax?</span></a></li>

Changes to modules/math/linalg.man.

1

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[comment {-*- tcl -*- doctools manpage}]

[manpage_begin math::linearalgebra n 1.1]
[keywords {least squares}]
[keywords {linear algebra}]
[keywords {linear equations}]
[keywords math]
[keywords matrices]
[keywords matrix]
[keywords vectors]
[copyright {2004-2008 Arjen Markus <[email protected]>}]
[copyright {2004 Ed Hume <http://www.hume.com/contact.us.htm>}]
[copyright {2008 Michael Buadin <[email protected]>}]
[moddesc   {Tcl Math Library}]
[titledesc {Linear Algebra}]
[category  Mathematics]
[require Tcl [opt 8.4]]
[require math::linearalgebra [opt 1.1]]
[description]
[para]
This package offers both low-level procedures and high-level algorithms
to deal with linear algebra problems:

[list_begin itemized]
[item]

>
|














|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[comment {-*- tcl -*- doctools manpage}]
[vset VERSION 1.1.5]
[manpage_begin math::linearalgebra n [vset VERSION]]
[keywords {least squares}]
[keywords {linear algebra}]
[keywords {linear equations}]
[keywords math]
[keywords matrices]
[keywords matrix]
[keywords vectors]
[copyright {2004-2008 Arjen Markus <[email protected]>}]
[copyright {2004 Ed Hume <http://www.hume.com/contact.us.htm>}]
[copyright {2008 Michael Buadin <[email protected]>}]
[moddesc   {Tcl Math Library}]
[titledesc {Linear Algebra}]
[category  Mathematics]
[require Tcl [opt 8.4]]
[require math::linearalgebra [opt [vset VERSION]]]
[description]
[para]
This package offers both low-level procedures and high-level algorithms
to deal with linear algebra problems:

[list_begin itemized]
[item]

Changes to modules/math/linalg.tcl.

1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
    # Determine the shift h so that the matrix A+hI is positive
    # definite (the Gershgorin region)
    #
    set h {}
    set i 0
    foreach row $A {
        set aii [lindex $row $i]
        set sum [expr {2.0*abs($aii) - [norm_one $row]}]
        incr i

        if { $h == {} || $sum < $h } {
            set h $sum
        }
    }
    if { $h <= $eps } {







|







1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
    # Determine the shift h so that the matrix A+hI is positive
    # definite (the Gershgorin region)
    #
    set h {}
    set i 0
    foreach row $A {
        set aii [lindex $row $i]
        set sum [expr {$aii + abs($aii) - [norm_one $row]}]
        incr i

        if { $h == {} || $sum < $h } {
            set h $sum
        }
    }
    if { $h <= $eps } {
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220

    return $result
}

#
# Announce the package's presence
#
package provide math::linearalgebra 1.1.4

if { 0 } {
Te doen:
behoorlijke testen!
matmul
solveGauss_band
join_col, join_row







|







2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220

    return $result
}

#
# Announce the package's presence
#
package provide math::linearalgebra 1.1.5

if { 0 } {
Te doen:
behoorlijke testen!
matmul
solveGauss_band
join_col, join_row

Changes to modules/math/linalg.test.

641
642
643
644
645
646
647

648
649
650
651
652
653
654
655
656
657
658
659
660
661
662


663
664













665
666
667
668
669
670
671
    set b {}
    foreach {Ar br} $Ab {
        lappend A $Ar
        lappend b $br
    }
    set x [::math::linearalgebra::leastSquaresSVD $A $b]
} -result {1.0 1.0 0.1}


test eigenvectors-1.0 "Eigenvectors solution" -match numbers -body {
    #
    # Matrix:
    #    /2   1\
    #    \1   2/
    # has eigenvalues 3 and 1 with eigenvectors:
    #    / 1\      /1\
    #    \-1/  and \1/
    # (so include a factor 1/sqrt(2) in the answer)
    #
    set A  { {2 1}
             {1 2} } ;# Note: integer coefficients!

    set result [::math::linearalgebra::eigenvectorsSVD $A]


} -result {{{0.7071068 -0.7071068} {0.7071068 0.7071068}} {3.0 1.0}}















test mkHilbert-1.0 "Hilbert matrix" -match numbers -body {
    set computed [mkHilbert 3]
    set expected {{1.0 0.5 0.333333333333} {0.5 0.333333333333 0.25} {0.333333333333 0.25 0.2}}
    set diff [sub $computed $expected]
    set norm [normMatrix $diff max]
    set result [expr {$norm<1.e-10}]







>














|
>
>


>
>
>
>
>
>
>
>
>
>
>
>
>







641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
    set b {}
    foreach {Ar br} $Ab {
        lappend A $Ar
        lappend b $br
    }
    set x [::math::linearalgebra::leastSquaresSVD $A $b]
} -result {1.0 1.0 0.1}


test eigenvectors-1.0 "Eigenvectors solution" -match numbers -body {
    #
    # Matrix:
    #    /2   1\
    #    \1   2/
    # has eigenvalues 3 and 1 with eigenvectors:
    #    / 1\      /1\
    #    \-1/  and \1/
    # (so include a factor 1/sqrt(2) in the answer)
    #
    set A  { {2 1}
             {1 2} } ;# Note: integer coefficients!

    ::math::linearalgebra::eigenvectorsSVD $A
} -cleanup {
    unset A
} -result {{{0.7071068 -0.7071068} {0.7071068 0.7071068}} {3.0 1.0}}

test eigenvectors-1.1-tkt7f082f8667 {Eigenvector signs} -setup {
    # Test case derived from the example code found in ticket [7f082f8667].
    set A {
	{2.7563361585555084  0.02600440980933252 0.0}
	{0.02600440980933252 2.785766824118953   0.0}
	{0.0                 0.0                -5.542102982674461}
    }
} -body {
    lindex [::math::linearalgebra::eigenvectorsSVD $A] 1
} -cleanup {
    unset A
} -match numbers -result {2.80093075418638 2.7411722284880806 -5.542102982674461}


test mkHilbert-1.0 "Hilbert matrix" -match numbers -body {
    set computed [mkHilbert 3]
    set expected {{1.0 0.5 0.333333333333} {0.5 0.333333333333 0.25} {0.333333333333 0.25 0.2}}
    set diff [sub $computed $expected]
    set norm [normMatrix $diff max]
    set result [expr {$norm<1.e-10}]

Changes to modules/math/pkgIndex.tcl.

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

if {![package vsatisfies [package provide Tcl] 8.4]} {return}
# statistics depends on linearalgebra (for multi-variate linear regression).
package ifneeded math::statistics        0.9.2 [list source [file join $dir statistics.tcl]]
package ifneeded math::optimize          1.0.1 [list source [file join $dir optimize.tcl]]
package ifneeded math::calculus          0.8   [list source [file join $dir calculus.tcl]]
package ifneeded math::interpolate       1.1   [list source [file join $dir interpolate.tcl]]
package ifneeded math::linearalgebra     1.1.4 [list source [file join $dir linalg.tcl]]
package ifneeded math::bignum            3.1.1 [list source [file join $dir bignum.tcl]]
package ifneeded math::bigfloat          1.2.2 [list source [file join $dir bigfloat.tcl]]
package ifneeded math::machineparameters 0.1   [list source [file join $dir machineparameters.tcl]]

if {![package vsatisfies [package provide Tcl] 8.5]} {return}
package ifneeded math::calculus::symdiff 1.0   [list source [file join $dir symdiff.tcl]]
package ifneeded math::bigfloat          2.0.2 [list source [file join $dir bigfloat2.tcl]]







|







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

if {![package vsatisfies [package provide Tcl] 8.4]} {return}
# statistics depends on linearalgebra (for multi-variate linear regression).
package ifneeded math::statistics        0.9.2 [list source [file join $dir statistics.tcl]]
package ifneeded math::optimize          1.0.1 [list source [file join $dir optimize.tcl]]
package ifneeded math::calculus          0.8   [list source [file join $dir calculus.tcl]]
package ifneeded math::interpolate       1.1   [list source [file join $dir interpolate.tcl]]
package ifneeded math::linearalgebra     1.1.5 [list source [file join $dir linalg.tcl]]
package ifneeded math::bignum            3.1.1 [list source [file join $dir bignum.tcl]]
package ifneeded math::bigfloat          1.2.2 [list source [file join $dir bigfloat.tcl]]
package ifneeded math::machineparameters 0.1   [list source [file join $dir machineparameters.tcl]]

if {![package vsatisfies [package provide Tcl] 8.5]} {return}
package ifneeded math::calculus::symdiff 1.0   [list source [file join $dir symdiff.tcl]]
package ifneeded math::bigfloat          2.0.2 [list source [file join $dir bigfloat2.tcl]]