Texas Instruments TI-89 Tip List page 112

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

Advertisement

indexlst(l,v)
func
©(l,v) return list of k|l[k]=v
©3nov01/dburkett@infinet.com
local k,r,j
{}→r
1→j
for k,1,dim(l)
if l[k]=v then
k→r[j]
j+1→j
endif
endfor
return r
Endfunc
Since more than one list element may match the target value, the matching indices are returned as a
list. For example, if the list mylist is {5,4,7,3,2,1,1}, then indexlst(mylist,5) returns {1}, and
indexlst(mylist,1) returns {6,7}.
indexlst() returns an empty list {} if the target element is not in the list. So, this function could also be
used to determine if a list includes a particular element, by testing the returned result for dim() = 0.
This function can find the indices of the minimum and maximum list values, with the built-in min() and
max() functions. To find the indices of the minimum list element, use
indexlst(mylist,min(mylist))
which, for the example above, returns {6,7}. To find the indices of the maximum list element, use
indexlst(mylist,max(mylist))
which returns {3}.
Finding the indices of a particular element in a matrix is only slightly more complicated, and we can use
indexlst() to do the work, by converting the matrix to a list with
list, we must then convert the list indices to the equivalent matrix indices. This function implements
these ideas.
indexmat(m,v)
Func
©(mat,v) return matrix of [k,l]|mat[k,l]=v
©calls util\indexlst()
©4nov01/dburkett@infinet.com
local r,n,j,i,s,c
mat▶list(m)→r
util\indexlst(r,v)→r
if r={} then
return ""
else
dim(r)→c
coldim(m)→n
newmat(c,2)→s
for i,1,c
intdiv(r[i]-1,n)+1→j
©Initialize result list ...
©... and result list index
©Loop to test each list element
©If list element matches target ...
©... save index in result list
©... and update result list index
©Return result list
©Convert the matrix to a list
©Find list indices of v
©Return empty string if no matching indices
©Convert list indices to matrix indices
©... get number of matching indicex
©... get number of matrix columns
©... make result matrix
©... loop to convert indices
©... find row index
mat▶list()
. Since indexlst() returns a
3 - 30

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Ti-92+

Table of Contents