There are currently SWs able to perform symbolic calculations and get results in short time. However having the ability to have a programmable calculator is still important during the exams. One of the programmable calculators that had a great story was the HP 48G. Below all the codes I did when examining the Systems Theory.
MATRIX RANGE
This HP48 program determines the range of a matrix. It outputs the basis vectors and handles matrices up to 4 dimensions.
1: MATRIX
«
TRN NUCLEO DROP
DUP
IF { } == THEN
"IL RANGE RAPPRESENTA TUTTO LO SPAZIO" MSGBOX DROP
ELSE
DUP SIZE 'DIM' STO
IF DIM(2) == 2 THEN
{ x1 x2 } 'vet' STO
[ 0 0 ] 'NUL' STO
END
IF DIM(2) == 3 THEN
{ x1 x2 x3 } 'vet' STO
[ 0 0 0 ] 'NUL' STO
END
IF DIM(2) == 4 THEN
{ x1 x2 x3 x4 } 'vet' STO
[ 0 0 0 0 ] 'NUL' STO
END
DIM(1) EVAL 'DIM' STO
0 'cont' STO
1 DIM EVAL
FOR j DUP
IF NUL == THEN
DROP DIM 1 - 'DIM' STO
ELSE
HOME RANGE vet
*
END
ROLLD cont 1 + 'cont' STO
NEXT
END
{ cont NUL vet DIM n } PURGE
»
MATRIX CORE
This code is able to perform the matrix core in both vector form and equations
1: MATRIX
«
'Fr' STO \ Store the input matrix in 'Fr'
Fr Fr
SIZE 'DIM' STO \ Get the size of 'Fr' and store it in 'DIM'
{ 'DIM(1)' } 0 CON 'DIM(2)+1' EVAL COL+ \ Adjust dimensions
'Fr' STO \ Store the adjusted matrix back in 'Fr'
\ Handle different dimensions
IF 'DIM(2)==2' THEN
{ x1 x2 } 'vet' STO
[ 0 0 ] 'NUL' STO
END
IF 'DIM(2)==3' THEN
{ x1 x2 x3 } 'vet' STO
[ 0 0 0 ] 'NUL' STO
END
IF 'DIM(2)==4' THEN
{ x1 x2 x3 x4 } 'vet' STO
[ 0 0 0 0 ] 'NUL' STO
END
Fr RREF \ Reduced row echelon form of 'Fr'
COL SWAP DROP 1 - COL ROW DROP 'DIM(1)' EVAL 'DIM' STO \ Adjust matrix dimensions
1 DIM 0 'cont' STO
\ Loop through dimensions
FOR j DUP
IF NUL == THEN
DROP DIM 1 - 'DIM' STO
ELSE
DUP HOME
HURWI UTILITY A~~L
HOME RANGE vet *
LIST 0 = Q DIM 1 +
ROLLD DIM 1 +
ROLLD cont 1 + 'cont' STO
END
NEXT
cont LIST 'eqz' STO
cont ROW 'matr' STO
{ NUL vet cont Fr } PURGE
matr SIZE 'DIM' STO
'DIM(2)-DIM(1)' EVAL 'DIM3' STO
\ Handle the case where DIM3 > 0
IF DIM3 0 > THEN
0 'n' STO
DO
{ DIM3 'DIM(2)' } 0 CON 'matr2' STO
matr ROW DROP
IF n 0 < THEN
1 DIM3 FOR q DROP NEXT
END
matr2 ROW DROP 'DIM(2)' EVAL ROW 'matr' STO
n 1 + 'n' STO
n 'm' STO
'DIM(1)' EVAL 1 + 'DIM(2)' EVAL
FOR j
IF n > DIM(2) THEN
1 'n' STO
END
matr {j n} 1 PUT 'matr' STO
n 1 + 'n' STO
NEXT
m 'n' STO
UNTIL matr RANK 'DIM(2)' EVAL == END
{ matr2 m } PURGE
'DIM(1)' EVAL 1 + 'DIM(2)' EVAL
FOR j
{ 'DIM(2)' } 0 CON { j } 1 PUT
matr LSQ 4 RND
NEXT
DIM3 ROW
ELSE
{ }
END
eqz { DIM DIM3 matr eqz n } PURGE
»
EIGENVECTORS GENERALIZED
AUTGEN
This cose is able to perform generalized eigenvectors
3: autovalore
2: autovettore generalizzato di ordine appena minore
1: matrice
'Fr' STO
'avt' STO
'avl' STO
Fr SIZE 'DIM' STO
HEAD IDN avl * Fr -
'Fr' STO
Fr avt NEG STO
DIM HEAD 1 + COL+
'Frplus' STO
IF Fr RANK Frplus RANK ==
THEN
Frplus 'Fr' STO
END
IF 'DIM(2)==2'
THEN
[ 0 0 ] 'NUL' STO
END
IF 'DIM(2)==3'
THEN
[ 0 0 0 ] 'NUL' STO
END
IF 'DIM(2)==4'
THEN
[ 0 0 0 0 ] 'NUL' STO
END
Fr RREF
COL SWAP 'avt' STO
1 - COL DROP ROW DROP
'DIM(1)' EVAL 'DIM' STO
1 DIM FOR j
DUP IF NUL ==
THEN
DROP DIM 1 - 'DIM' STO
ROW DROP 'avt' STO
ELSE
DIM ROLLD 'avt' STO
nue ROW 'avt' STO
END
NEXT
DIM ROW 'matr' STO
SIZE 'DIM' STO
(2)-DIM(1) EVAL 'DIM3' STO
IF DIM3 0 > THEN
0 'n' STO
DO
DIM3 'DIM(2)' 0 CON 'matr2' STO
DIM3 0 CON 'avt2' STO
matr ROW DROP
IF n 0 <
THEN
1 DIM3 FOR q DROP NEXT
END
avt ROW DROP 'nue' STO
IF n 0 <
THEN
1 DIM3 FOR q DROP nue 1 - 'nue' STO NEXT
END
nue ROW 'avt' STO
matr2 ROW DROP 'DIM(2)' EVAL ROW 'matr' STO
avt ROW DROP avt2 ROW DROP 'DIM(2)' EVAL ROW 'avt' STO
n 1 + 'n' STO
'm' STO 'DIM(1)' EVAL 1 + 'DIM(2)' EVAL FOR j
matr { j n } 1 PUT 'matr' STO n 1 + 'n' STO NEXT
m 'n' STO UNTIL matr RANK 'DIM(2)' EVAL ==
END
'DIM(1)' EVAL 1 + 'DIM(2)' EVAL FOR j
avt { j } 1 PUT 'matr' STO NEXT
DIM3 ROW
ELSE
{ } "Non ci sono altri autovettori generalizzati" MSGBOX
END
{ DIM Fr avt2 nue Frplus avl matr2 m NUL vet cont DIM3 eqz n matr avt } PURGE
La lista completa di tutti le funzioni create sono presenti nel seguente file:
programmi-HP-1