ppetto@NCoast.ORG (Peter Petto) (03/09/91)
An HP-48SX question ... I would like to combine two vectors
into an array as follows
[ 2 4 6 8 ] plus [ 2 9 27 81 ]
to get
[[ 2 4 6 8 ]
[ 3 9 27 81 ]]
I have been able to do this manually (via the MatrixWriter
application) but not under progam control. Can anyone offer
any advice? (Thanks.)
---
Peter Petto | ppetto@ncoast.org
Bay Village, Ohio | 73125.617@compuserve.combson@fruit-and-fibre.ai.mit.edu (Jan Brittenson) (03/09/91)
In a posting of [8 Mar 91 21:10:04 GMT] ppetto@NCoast.ORG (Peter Petto) writes: >An HP-48SX question ... I would like to combine two vectors >into an array as follows > > [ 2 4 6 8 ] plus [ 2 9 27 81 ] > > to get > > [[ 2 4 6 8 ] > [ 3 9 27 81 ]] How about: << SWAP ARRY-> LIST-> DROP DUP 2 + ROLL ARRY-> LIST-> DROP DUP 2 + ROLL + 2 SWAP OVER / OVER ->LIST ->ARRY >> Assuming the sum of the vector sizes is even. -- Jan Brittenson bson@ai.mit.edu Read my lisp: no new classes!
rouben@math13.math.umbc.edu (Rouben Rostamian) (03/10/91)
In article <13845@life.ai.mit.edu> bson@fruit-and-fibre.ai.mit.edu (Jan Brittenson) writes: @ In a posting of [8 Mar 91 21:10:04 GMT] @ ppetto@NCoast.ORG (Peter Petto) writes: @ @ >An HP-48SX question ... I would like to combine two vectors @ >into an array as follows @ > @ > [ 2 4 6 8 ] plus [ 2 9 27 81 ] @ > @ > to get @ > @ > [[ 2 4 6 8 ] @ > [ 3 9 27 81 ]] @ @ How about: @ @ << SWAP ARRY-> LIST-> DROP @ DUP 2 + ROLL ARRY-> LIST-> DROP @ DUP 2 + ROLL + 2 SWAP OVER / OVER @ ->LIST ->ARRY @ >> Here is a somewhat shorter version (53 bytes compared to 73) of the program above: Checksum: #23189d Bytes: 53 << SWAP OBJ-> OBJ-> DROP 1 + ROLL OBJ-> OBJ-> DROP 2 SWAP 2 ->LIST ->ARRY >> -- Rouben Rostamian Telephone: (301) 455-2458 Department of Mathematics and Statistics e-mail: University of Maryland Baltimore County bitnet: rostamian@umbc.bitnet Baltimore, MD 21228, U.S.A. internet: rouben@math9.math.umbc.edu
jurjen@cwi.nl (Jurjen NE Bos) (03/11/91)
In a posting of [8 Mar 91 21:10:04 GMT] ppetto@NCoast.ORG (Peter Petto) writes: >An HP-48SX question ... I would like to combine two vectors >into an array as follows > > [ 2 4 6 8 ] plus [ 2 9 27 81 ] > > to get > > [[ 2 4 6 8 ] > [ 3 9 27 81 ]] This is one of the more useful functions of \GS+ (\GS means the capital sigma) how about? \<< CL\GS SWAP \GS+ \GS+ RCL\GS \>> It this short, or what? There is one problem: it doesn't work with complex numbers. Happy Hacking,
TDSTRONG%MTUS5.BITNET@VM1.NoDak.EDU (Tim Strong) (03/12/91)
> >In a posting of [8 Mar 91 21:10:04 GMT] > ppetto@NCoast.ORG (Peter Petto) writes: > >>An HP-48SX question ... I would like to combine two vectors >>into an array as follows >> >> [ 2 4 6 8 ] plus [ 2 9 27 81 ] >> >> to get >> >> [[ 2 4 6 8 ] >> [ 3 9 27 81 ]] > >This is one of the more useful functions of \GS+ (\GS means the capital sigma) >how about? >\<< CL\GS SWAP \GS+ \GS+ RCL\GS \>> >It this short, or what? >There is one problem: it doesn't work with complex numbers. >Happy Hacking, How about CATARRY << OBJ-> 1 GET DROP 1 + ROLL OBJ-> 2 SWAP + ->ARRY >> Longer and not exactly elegant but it should work for complex arrays. It also has a deficiency in that it can't continue concatenating arrays to vectors. For example one's next step might be: [[ 2 4 6 8 ] [ 2 9 27 81 ]] [ 4 5 8 6 ] CATARRY hoping for [[ 2 4 6 8 ] [ 2 9 27 81 ] [ 4 5 8 6 ]] But it will probably give you a mess on the stack along with a two row array. I'm not sure my calculator ain't here so I can't check what happens but it will screw up. If I had my calculator I'm sure that with some work the above routine could be reworked to fix the problem.
seroussi@hplred.HP.COM (Gadiel Seroussi) (03/13/91)
I've been using the following "off the wall" programs for converting
a set of vectors to a matrix and vice versa:
V2MX:
----
Takes an integer n from level 1, and n vectors from levels 2..(n+1),
and produces a n-row matrix (works for reals and complexes, and doesn't mess up
your statistics):
\<<
\->LIST \->STR 1 "[" REPL DUP SIZE "]" REPL OBJ\->
\>>
MX2V:
-----
Does the inverse of V2MX:
\<<
DEPTH \-> d
\<<
\->STR DUP SIZE 1 - 2 SWAP SUB OBJ\-> DEPTH d
- 1 +
\>>
\>>
I'll leave it to others to optimize and squeeze the last nibble out
of the above.
Gadiel Seroussi
HP Labsjmorriso@ee.ubc.ca (John Paul Morrison) (03/15/91)
Well, here is yet another vector to array type of program.
I use it extensively. It works on both HP28S and HP48SX machines.
It is quick, as it uses the stack.
A2V
@ Extracts the COLUMN vectors of a matrix
@ Hit TRN first if you want the ROW vectors
@ leaves them on the stack, whith the number of vectors in level 1
%%HP: T(3)A(D)F(.);
\<< TRN ARRY\-> LIST\->
DROP DUP 1 - NEG \->
n m m1
\<< m n 1 - * 1 + n
FOR i m \->ARRY i
ROLLD m1
STEP n
\>>
\>>
V2A
@ The inverse of A2V
@ Takes n vectors, and the number n and leaves a matrix on the stack
%%HP: T(3)A(D)F(.);
\<< OVER SIZE 1 GET
DUP 1 - \-> n m m1
\<< n m n 1 - * 1 +
FOR i i ROLL
ARRY\-> DROP m1
STEP { n m }
\->ARRY TRN
\>>
\>>
If you're really picky, these do not work for 1 dimesional vectors or n * 1
matrices. Big deal. One dimesional vectors are SCALARs anyways.
The bug is in the HP STUPID_FOR loop. I'll fix it when I need the extra
"correctness".
In case you haven't noticed, HP STUPID_FOR loops ALWAYS execute at least
once. I know that's
documented, but it's still STUPID (especially if you program in C).