Texas Instruments TI-89 Tip List page 95

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

Advertisement

This function shows the general expression to find the list index k for an element location {a
for an array of dimension {d
mrankni(a,d)
Func
©({loc},{dim}) return index
©Return list index for array element
©30nov00/dburkett@infinet.com; based on expression by Bhuvanesh Bhatt
Σ(when(i≠dim(a),(a[i]-1)*‹(d[j],j,i+1,dim(d)),a[i]),i,1,dim(a))
EndFunc
For example, to find the list index for the element at {1,2,3} in a 3x3x3 array, use
mrankni({1,2,3},{3,3,3})
which returns 6, meaning that the element at {1,2,3} is the 6th element in the list.
This function can be used for arrays of any rank, but it is much slower than the direct implementations
given above. For a 4x4x4x4 array, the direct expression evaluates in about 0.037 seconds to find the
list index k, while the general expression takes about 0.21 seconds.
Even though the general expression is slow, it is useful to find a symbolic expression for the list index.
For example, to find the index expression for a rank-5 array, set
{a[1],a[2],a[3],a[4],a[5]}→a
{d[1],d[2],d[3],d[4],d[5]}→d
Then, executing mrankni(a,d) returns
a5+(a[4]+a[3]*d[4]+a[2]*d[3]*d[4]+a[1]*d[2]*d[3]*d[4]-
((d[2]+1)*d[3]+1)*d[4]-1)*d[5]
The expression is not optimized in this form but it can be optimized by factoring on d with factor():
factor(a5+(a[4]+a[3]*d[4]+a[2]*d[3]*d[4]+a[1]*d[2]*d[3]*d[4]-
((d[2]+1)*d[3]+1)*d[4]-1)*d[5],d)
which returns the optimized form
(((d[2]*(a[1]-1)+a[2]-1)*d[3]+a[3]-1)*d[4]+a[4]-1)*d[5]+a[5]
For some array operations, you may need to find the array element address {a}, given the list index.
The three routines below implement this function. m3aind() finds the element address for a rank-3
array, and m4aind() finds the address for a rank-4 array. mnaind() finds the address for an array of any
rank. It is slower than m3aind() and m4aind(), but obviously more general.
Find element address for a rank-3 array:
m3aind(i,d)
Func
©(index,{d1,d2,d3}) return {a1,a2,a3}
,d
,...d
}:
1
2
n
,a
,...,a
}
1
2
n
3 - 13

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Ti-92+

Table of Contents