[3.30] Singular Value Decomposition (Svd) Of A Matrix - Texas Instruments TI-89 Tip List

Graphing calculator
Hide thumbs Also See for TI-89:
Table of Contents

Advertisement

local mθ,k,l,d,dl
list▶mat(#mσ[1],1)→mθ
rowdim(mθ)→d
2→k
loop
#mσ[k]→l
dim(l)→dl
if dl=0 then
exit
elseif dl≠d then
return "datamat() err"
else
augment(mθ,list▶mat(l,1))→mθ
endif
k+1→k
endloop
EndFunc
This conversion is useful if you want to use functions on data variables, because data variables cannot
be passed as function arguments. Use datamat() to convert the data variable to a matrix, then execute
the desired function.
To convert a data variable mydata to a matrix, use
datamat("mydata")
Note that the name of the data variable is passed as a string.
The code is straightforward, but is somewhat complicated because we cannot find the number of
columns in a data variable. However, I use the fact that a data variable column can be extracted to a
list with
datavar[k]→list
and the dimension of list is zero if column k does not exist. This condition exits the loop.
The only error checking ensures that all the data variable columns have the same number of rows,
since this must be true for matrices. If the row dimensions are not equal, datamat() returns the string
"datamat() err" instead of the matrix. The calling program or function can use getType() on the result to
determine if an error occurred.

[3.30] Singular value decomposition (SVD) of a matrix

Singular value decomposition is a powerful tool for a variety of matrix-related tasks, including working
with matrices and sets of linear equations which are nearly singular. You can use SVD to remove the
singularities and get numerical results, but they may not be the results you expect. In addition, SVD
can be used for linear least-squares regression problems. A future version of this tip may demonstrate
some of those examples, but for now I will only present a good implementation of SVD, written by
Hernan Rivera. For now, if you would like to see how SVD is used, start with chapter 2.6 of Numerical
Recipes in Fortran, by Press, Teukolsky, Vetterling, and Flannery (http://www.nr.com).
SVD decomposes a matrix m with dimensions a x b (with a < b) into three matrices u, d and v such that
© Convert first data column to matrix
© Find row dimension
© Loop through remaining data columns
© Convert column to a list
© Find row dimension
© Done when row dimension is zero
© Error if row lengths not equal;
©
return error string
© Augment current column to matrix
© Process next column
© Return matrix
3 - 36

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Ti-92+

Table of Contents