MATFUN
by Jonathan duSaint
jon@wpi.edu
Matfun is a collection of very useful matrix oriented functions.

To install, download matfun.lib. RCL to the stack and purge the
variable. Then type 0 STO and warmstart (ON-C) the calculator
to configure the library.
Any changes made should be mailed to the above email address.

Stack diagrams will be shown as:
  3  2  1 -> 3  2  1
Various symbols are used:
%    real number
C%   complex number
[]   array
::   program
SYMB equation

IARR
 %s  %i  %f -> []
This program creates an incremented array from %s to %f in
steps of %i.
For example:
0 .1 1 <IARR> ->  [[ 0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1 ]]
The stepsize can also be negative:
1 -.1 0 <IARR> -> [[ 1 .9 .8 .7 .6 .5 .4 .3 .2 .1 0 ]]

->2D
[2d] -> [2d]
[1d] -> [2d]
This program turns a one dimensional vector into a two dimensional
array without changing the elements. If a two dimensional array is
entered, it will be unchanged.

LENGTH
[] -> %
Returns the length of an array.

FLIPLR
[] -> []'
Flips an array from left to right.

FLIPUD
[] -> []'
Flips an array upside down.

MTXELM
[]  ::  -> []'
[] SYMB -> []'
Applies a program or an equation to each element of an array. The program
should take one real or complex argument and return one real or
complex argument. Errors for invalid programs. If an equation is used,
then it should only contain one variable.

MMIN
[] -> % ... %
Returns the smallest element of each column of an array.

MMAX
[] -> % ... %
Returns the largest element of each column of an array.

MPLOT
[] ->
This program plots an array columnwise. For an Nx1 real array,
the elements are plotted versus their indices. For an Nx2
real array, column two is plotted versus column one, For an NxM
real array, columns two through M are plotted individually versus
column one. For an Nx1 complex array, the plot is of imag versus
real. For an NxM complex array, the plot is imag versus real for
each column of the array. For an example, try:
[[ (1,1)][(-1,1)][(-1,-1)][(1,-1)][(1,1)]] MPLOT
This should draw a square. Or, try:
0 .1 2 \pi * IARR 'SIN(2*X)' MTXELM MTRN MPLOT
This will draw two cycles of a sine wave.

FILTER
[] [] -> []'
This program runs the level two array through the filter
represented by the level one array.

CONV
[] [] -> []'
Convolution. This program convolves the two arrays with each
other. A practical application of which is polynomial multiplication. For example, the two equations x-1 and x+1 can be represented
by [1 -1] and [1 1]. Convolving these two vectors returns
[1 0 -1], or x^2-1 which is (x-1)(x+1).

INTERP
[] % -> []'
Interpolation. This program interpolates the input array to
be % times larger.

MPLUS
[] [] -> []'
[] %  -> []'
%  [] -> []'
[] C% -> []'
C% [] -> []'
This program extends the built in + function to include arrays and
real or complex numbers.

MMINUS
[] [] -> []'
[] %  -> []'
%  [] -> []'
[] C% -> []'
C% [] -> []'
This program extends the built in - function to include arrays and
real or complex numbers.

MMULT
[] [] -> []'
[] %  -> []'
%  [] -> []'
[] C% -> []'
C% [] -> []'
This implements element by element multiplication between two arrays.
Other combinations (as shown above) merely use the built in *
command. The implementation is in assembly language for speed and
accuracy.

MDIV
[] [] -> []'
[] %  -> []'
%  [] -> []'
[] C% -> []'
C% [] -> []'
This implements element by element division in assembly language for
accuracy and speed.

SINC
%  -> %'
C% -> C%'
[] -> []'
The sinc function is sin(x)/x. This function find the sinc of
real numbers, complex numbers, and the elements of arrays, real
or complex.

MTRN
[] -> []'
When the array is real, this function behaves in the same way as
the built in TRN command. When it is complex it transposes the array
without changing to the complex conjugates. To see this at work, try:
[[ (1,1) ]] TRN  -> [[ (1,-1) ]]
For this routine:
[[ (1,1) ]] MTRN -> [[ (1,1) ]]


In the future, the FILTER, CONV, and INTERP commands are going to
be converted to assembly language to hopefully increase their speed
and numerical accuracy. (Right now, they are fairly fast and exceedingly
 accurate, but more never hurts.)


