Zolo
Zolo

Reputation: 27

How can I use TCL linear algebra package for setting the elemnt of a matrix

I am trying to use the ::math::linearalgebra:: package to do some simnple eigenvalue calculation for testing. The following code works and produces the desired result:

package require math
package require math::linearalgebra    
set Mat [::math::linearalgebra::mkMatrix 8 8 0.0]
puts "a single row is: [::math::linearalgebra::getrow $Mat 0 ] "

However when I try to chnage an element of matrix Mat I get an error:

set Mat [::math::linearalgebra::mkMatrix 8 8 0.0]
 ::math::linearalgebra::setelem $Mat 0 1 1.0]
puts "a single row is: [::math::linearalgebra::getrow $Mat 0 ] "

The error is:

can't read "mat": no such variable while executing "lset mat $row $col $newvalue" (procedure "::math::linearalgebra::setelem" line 4)

How do I modify the elements of the created matrix if not with ::setelem?

Thanks

Upvotes: 0

Views: 146

Answers (1)

Jerry
Jerry

Reputation: 71598

Per the manual, you have to give the name of the matrix. Thus you should do:

set Mat [::math::linearalgebra::mkMatrix 8 8 0.0]
::math::linearalgebra::setelem Mat 0 1 1.0

Upvotes: 1

Related Questions