Post Reply 
Detect number entry on HP-35s?
03-04-2015, 02:37 PM (This post was last modified: 03-04-2015 02:39 PM by Dieter.)
Post: #27
RE: Detect number entry on HP-35s?
(03-02-2015 02:26 AM)mbrethen Wrote:  The user puts the starting register on the stack. Executing the "matrix writer" program, it queries each element, column by column. When the user presses R/S the first time, that signals the end of first column and there are "m" rows. It then queries additional columns. When the user presses R/S a second time, that signals the end of the nth column and the program "learns" "m" rows and "n" columns. It finishes by placing a "control number" on the stack: bbb.eeerr

where
bbb = beginning register
eee = end register
rr = number of rows

This control number will be used by other programs that operate on the matrix.

OK, now I get what you want. The following code should be able to do this. Try it and see what you get.

Code:
W001  LBL W
W002  ABS
W003  IP
W004  STO B    // base register#
W005  0,9      // add 0,9 so that ISG increments, but always tests true
W006  +
W007  STO I    // start with entered base register
W008  1
W009  +
W010  STO J    // j=i+1 is used to prestore a non-zero value
W011  1,9    
W012  STO D    // d = 1,mmm. If m is not yet known, assume m is very large (e.g. 900)
W013  SF 1     // set flag 1 to indicate that no empty entry occured yet
W014  1,9
W015  STO C    // column index
W016  RCL D
W017  STO R    // row index
W018  EQN [IP(R), IP(C)]
W019  STO A
W020  CLSTK
W021  ALL
W022  INPUT A
W023  ENTER    // another way of checking whether
W024  ABS      // x is scalar or vector
W025  LASTx
W026  [1,0]
W027  x
W028  ABS
W029  x≠y?     // is x a vector (i.e. no entry was made?)
W030  GTO W041 // then determine #rows resp. #columns
W031  1
W032  STO(J)   // otherwise store non-zero value in variable (i+1)
W033  R↑
W034  STO(I)   // store input in variable (i)
W035  ISG I    // increment both i
W036  ISG J    // and j
W037  ISG R    // increment row index
W038  GTO W018 // get next row
W039  ISG C    // increment column index
W040  GTO W016 // get next column
W041  FS? 1    // first occurence of R/S without entry?
W042  GTO W063 // then determine m = #rows
W043  RCL C    // otherwise matrix is complete
W044  IP
W045  1
W046  -
W047  STO N    // determine n = #columns
W048  VIEW N
W049  PSE
W050  RCL M
W051  1E5
W052  ÷
W053  RCL M
W054  RCLx N
W055  RCL+ B
W056  1
W057  -
W058  1E3
W059  ÷
W060  +
W061  RCL+ B   // compute control number bbb.eeemm
W062  RTN      // and quit
W063  CF 1     // reset "first empty input" flag
W064  RCL R
W065  IP
W066  1
W067  -
W068  STO M    // determine m = #rows
W069  1E3
W070  ÷
W071  1
W072  +
W073  STO D    // compute 1,mmm
W074  VIEW M    
W075  PSE    
W076  ISG C    // increment column index
W077  GTO W016 // get next column

However, I think this method of entering a matrix is not a good idea. After the number of rows is known, the user has to enter complete columns. What happens if he doesn't? For instance, if there are m=3 rows but the user quits in column 5 after entering just one value? Are the following elements A[5,2] and A[5,3] assumed zero? Should the program throw an error? This would require some additional code after W043.

That's why I would prefer the classic approach: simply have the user enter m and n.

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Detect number entry on HP-35s? - mbrethen - 02-25-2015, 03:37 AM
RE: Detect number entry on HP-35s? - d b - 02-26-2015, 06:31 AM
RE: Detect number entry on HP-35s? - Dieter - 03-04-2015 02:37 PM



User(s) browsing this thread: 20 Guest(s)