[comp.sys.handhelds] TI 81 better than HP48SX??

ron@vpnet.chi.il.us (Ron Winograd) (04/03/91)

Hello people,
I just went out and bought myself a nice shiny new HP48sx calculator.

I was kind of disappointed when I discovered it can't do something that
the $90 TI 81 can do.

So, someone PLEASE tell me that I am wrong:
Can the HP48SX do matrix row operations, aka: Multiply row 1 by 5 and add to
row 2?

I searched both volumes of the documentation, and found nothing. I really like
the 48sx, but I really need matrix row operations.

If it isn't supported, has anyone programmed it yet?
-- Ron

sjthomas@cup.portal.com (Stephen J Thomas) (04/04/91)

The TI-81 probably includes the matrix row multiplication (etc) functions
to facilitate solving a system of simultaneous equations -- on the HP 48,
this can be done more easily using the divide function (check the manual).
The TI-81 does not provide this easy method to solve a system.  Clearly,
the 48 can be easily programmed to do such row/column multiplications.
  
Stephen J Thomas    sjthomas@cup.portal.com

wes@kuhub.cc.ukans.edu (04/04/91)

 
CMAT is an HP48 program for performing operations on columns of a
matrix. CMAT iterates over each row of the matrix, treating the n
columns of the matrix as if they were variables named C1, C2, ...
Cn, or, optionally, as if they were named with user-specified
names. The operations can be be limited to selected rows of the
matrix by supplying a boolean condition that must be met before
the computation is peformed. If the result column is not in the
original matrix, the matrix will be expanded to include the new
column.
 
Before executing CMAT, you must place on level two of the stack
the matrix object to process, and on level one of the stack either
an algebraic object that specifies the compuation to perform or a
list that specifies a series of variable names, conditions, and
computations.
 
For example, place the matrix
 
[[ 1 5 ]
 [ 2 4 ]
 [ 3 6 ]]
 
on the stack.
 
Next place the algebraic object
 
'C4=C2^2+C1'
 
on the stack. It specifies computing a new column, column four, as
column two squared plus column one. Since column three is not part
of the original matrix, it is filled with zeros.
 
Executing CMAT will replace these objects with the matrix:
 
[[ 1 5 0 26 ]
 [ 2 4 0 18 ]
 [ 3 6 0 39 ]]
 
 
The Evaluation List
 
For computations to complex to specify with a single equation, CMAT
allows an evaluation list instead of an equation.  The list can contain
name assignment lists and conditional expression lists as well as
equations.  Each list begins with a string.  "Names", "If', or "Compute".
The first character is sufficient (e.g. "N" for "Names).  A name list
consists of one or more lists whose first item is a column number and
whose second item is a name for the column.  A conditional list contains
and algebraic object specifying a condition that must be true for a row
in order for the following equation to be processed.  An imperative
list contains an equation, and is equivalent to an equation by itself
not contained in a list (e.g. {"C" 'equation'} and 'equation' are
treated identically.
 
  Name List    {"Names" {2 'Age'} {3 'Income'}}
  Conditional  {"If" 'boolean' 'equation'}
  Imperative   {"Compute" 'equation'}
 
If a column is not explicitly named, it has a default of of Cn where
'n' is the column number, but 'Cn' cannot be used to specify a column
that has been named.  It must be called by its name.
 
An example list:
  { { "N" {4 'Sum'} {5 Mean'}}
    'Sum=C1+C2+C3'
    { "If" 'C1>0' 'Mean=Sum/3' } }
 
 
Immediate Execution Functions
 
Functions that are available only for immediate execution from the
keyboard can be placed into programs by saving them in a program.
For example, RAND cannot be used directly in an algebraic
expression, but
 
<< RAND >> 'RANDOM' STO
 
creates a random number function that can then be used in an
algebraic expression such as
 
'C1=TRNC(10*RANDOM,0)'
 
to create a column of random numbers in the range 0 through 9.
 
 
Missing Value Indicators
 
To handle missing data, filter column variables with functions
such VALID and VALUE in the example below. In this example,
negative values indicate invalid data. The function VALID returns
1 if its argument is in the valid data range, 0 otherwise. The
function VALUE returns the original data value if it is in the
valid data range, 0 otherwise. Using these functions, C4 counts
the number of valid data points, C5 the total of valid data
values, and C6 the mean of the valid data.
 
<< << n | IF 'n>-1' THEN 1 ELSE 0 END >> >> 'VALID' STO
 
<< << n | IF 'n>-1' THEN n ELSE 0 END >> >> 'VALUE' STO
 
{ 'C4=VALID(C1)+VALID(C2)+VALID(C3)'
  'C5=VALUE(C1)+VALUE(C2)+VALUE(C3)'
  {"IF" 'C4>0' 'C6=C5/C4'} }
 
The condition 'C4>0'prevents dividing by zero when evaluating the
expression for C6 if there are no valid values in a row.
 
 
 
 
%%HP: T(3)A(R)F(.);
@ CMAT: HP48 program to apply expressions to columns of a matrix.
@       03/22/91 Version 1.0
@       Wes Hubert <wes@kuhub.cc.ukans.edu>
@
@ CMAT provides operations on matrix columns.  To use it, place a matrix on
@ level 2 of the stack, and an algebraic equation object or command list
@ on level 1 of the stack.  (See external documentation for information
@ about command lists.)  The equation should be of the form:
@ 'Ci=expression', where "Ci" specifies the column where the
@ result should be placed, and "expression" uses "C1, C2, ... Cn" to
@ specify columns 1, 2, ... n of the matrix.  For example:
@   [[1 2] [3 4] [5 6]]
@   'C1=C2^2+C1'
@ would return:
@   [[5 2] [19 4] [41 6]]
@
@ If the output column is not in the original matrix, the matrix will be
@ expanded to include enough new columns to store it, filling any new
@ unreferenced columns with zero.  For example, if the equation for
@ the input matrix above were 'C4=C2^2+C1', the result would be:
@   [[1 2 0 5] [3 4 0 19] [5 6 0 41]]
@
@ CMAT creates a working directory, stores variables into it, and
@ purges the directory when it finishes.  It includes rudimentary error
@ trapping to purge the working directory even if it does not run to
@ completion.
@
DIR
CMAT                                @ Protect environment from data errors
    \<< 'WRKTAB' CRDIR WRKTAB
      IFERR CMAIN
      THEN UPDIR 'WRKTAB' PGDIR ERRM DOERR
      ELSE UPDIR 'WRKTAB' PGDIR
      END
    \>>
CMAIN                               @ Main program for column processing
   \<<
     { } 'NAMES' STO
     IF DUP TYPE 5 \=/
     THEN 1 \->LIST
     END
     'FLIST' STO
     1 FLIST SIZE
     FOR elt FLIST elt GET
       IF CPARSE
       THEN CCOND
           CRESULT
           CADJUST
           1 NR
           FOR ir
               ir 'CASEID' STO 1 NC
               FOR ic ir ic 2 \->LIST
                   GETI SWAP DROP
                   NAMES ic GET STO
               NEXT
               IF CTST
               THEN FORM EVAL \->NUM ir
                    RESULT 2 \->LIST SWAP PUT
               END
           NEXT
        END
     NEXT
   \>>
CPARSE                              @ Scan item from command list.
    \<<
      IF DUP TYPE 5 \=/                      @ If not a list,
      THEN 1                                 @   treat as algebraic equation
      ELSE DUP 1 GET 1 1 SUB                 @ Check first char of keyword
        CASE DUP "N" ==                      @ "NAMELIST"
          THEN DROP 2 99 SUB CNL 0           @   Process in CNL, return 0
          END DUP "I" ==                     @ "IF"
          THEN DROP DUP 3 GET SWAP 2 GET 1   @   Return equation & condition
          END "C" ==                         @ "COMPUTE"
          THEN 2 GET 1                       @   Return equation only
          END
        END
      END
    \>>
CNL                                 @ Process namelist {{position name}...}
    \<<
      IF DUP TYPE 5 ==
      THEN 1 OVER SIZE
        FOR i DUP i GET 1 GETI
          IF DUP NAMES SIZE >
          THEN NAMES SIZE 1 + OVER
            FOR i NAMES "C" i +              @ Default name C+column#
              # 5B15h SYSEVAL + 'NAMES' STO  @ String to variable name
            NEXT
          END
          ROT ROT GET NAMES ROT
          ROT PUT 'NAMES' STO
        NEXT
      END DROP
    \>>
CCOND                              @ Process conditional part, if present
    \<<
      IF DUP \->STR DUP "=" POS SWAP
         "==" POS NOT AND
      THEN 1                                 @ Default is TRUE (1)
      END 'CTST' STO
    \>>
CRESULT                            @ Save result column # in RESULT
    \<<
      OBJ\-> DROP2 'FORM' STO
      IF NAMES OVER POS DUP
      THEN SWAP DROP
      ELSE DROP \->STR 3 OVER
      SIZE 1 - SUB OBJ\->
      END 'RESULT' STO
    \>>
CADJUST                            @ Add columns to matrix and names
    \<<
      DUP SIZE DUP 1 GET 'NR' STO
      2 GET 'NC' STO
      IF NC RESULT <
      THEN TRN RESULT NR 2
           \->LIST RDM TRN
      END
      NAMES DUP SIZE 1 + NC
      FOR i
          "C" i + # 5B15h SYSEVAL +
      NEXT
     'NAMES' STO
    \>>
END