Stefan is a HP calculator enthusiast that got himself a HP-35s and have a done a man's work providing two (so fare) rather lengthy programs for Curve Fitting and Matrix Operations on the HP-35s.
Mind you, as this thread (about Stefan's matrix program) at the MoHPC forum shows: If you need to do serious matrix work, clearly you should consider a RPL machine.
By the way, do check out Stefan web content, he is an inspiration to any kind of web author and also he turns out to be a norgesvenn!
Showing posts with label utility. Show all posts
Showing posts with label utility. Show all posts
Tuesday, November 6, 2007
Monday, October 15, 2007
HP-35s 2D to 3D vector conversion
Short program to convert a 2D vector to a 3D by placing it in the z=0 plane. Usefull when want to utilize 3D solutions to 2D data, for example taking cross product of two 2D vectors.
Stack Input/Output:
Terms of use.
Placed in the X 'library' since a vector utlity, from before have projecting to a cardinal plane, finding the component of a 3D vector with max absolute value, vector unpack routines, cross product and normalization.
Stack Input/Output:
[[u, v], Y, Z, T | L]-> XEQ 068 ->[[u, v, 0], Y, Z, T | [u, v]]Program:
X068 ABSComments:
X069 RDN
X070 eq [[1,0]xLASTX,[0,1]xLASTX,0]
X071 RTN
Terms of use.
Placed in the X 'library' since a vector utlity, from before have projecting to a cardinal plane, finding the component of a 3D vector with max absolute value, vector unpack routines, cross product and normalization.
Friday, October 12, 2007
HP-35s 3D to 2D projection utility subroutines - I
Utility 3D vector subroutine to tell which component that has the largest absolute value.
This is of use when projecting points in an arbitary plane to one of the three cardinal planes in order to reduce a 3D problem to a 2D problem (when possible). Use this subroutine on the arbitary plane's normal vector in order to decide which 3D coordinate to discard in order to avoid all points to be projected on a line if arbitary plane is perpendicular to the choosen cardinal plane or to avoid floating precision problems in case they are nearly perpendicular:
Examine the arbitary plane's normal vector (using this subroutine) and discard the coordinate that has the maximum absolute value.
Stack Input/Output:
Program:
Terms of use.
Placed in the X 'library' since a vector utlity, from before have vector unpack routines, cross product and normalization.
Change history:
20071014:1723UTC : Problem that vector lost, changed so vector now can be found in LASTX register. This also effects the X047 subroutine now X052 subroutine and those using that: Entry point address changed to X052.
This is of use when projecting points in an arbitary plane to one of the three cardinal planes in order to reduce a 3D problem to a 2D problem (when possible). Use this subroutine on the arbitary plane's normal vector in order to decide which 3D coordinate to discard in order to avoid all points to be projected on a line if arbitary plane is perpendicular to the choosen cardinal plane or to avoid floating precision problems in case they are nearly perpendicular:
Examine the arbitary plane's normal vector (using this subroutine) and discard the coordinate that has the maximum absolute value.
Stack Input/Output:
[[u, v, w], Y, Z, T | L]-> XEQ X025 ->[n, -, -, - | [u, v, w]]Where [u, v, w] is the vector in question and n is 1 if u has largest absolute value, 2 if v has and 3 if w has.
Program:
X025 XEQ X008Comments:
X026 LASTX
X027 RDN
X028 ABS
X029 RDN
X030 ABS
X031 RDN
X032 ABS
X033 X<>Y
X034 ABS
X035 X<>Y
X036 R^
X037 X>=Y?
X038 GTO X047
X039 X<>Y
X040 R^
X041 X<Y?
X042 GTO X045
X043 3
X044 RTN
X045 1
X046 RTN
X047 R^
X048 X>=Y?
X049 GTO X043
X050 2
X051 RTN
Terms of use.
Placed in the X 'library' since a vector utlity, from before have vector unpack routines, cross product and normalization.
Change history:
20071014:1723UTC : Problem that vector lost, changed so vector now can be found in LASTX register. This also effects the X047 subroutine now X052 subroutine and those using that: Entry point address changed to X052.
Thursday, October 11, 2007
Addition to the HP-35s stack save/restore program - III
Addition to the U program when in need to restore LASTX register and push two new values on the stack:
Of interest for programs that do not take stack register input but produces a result in the X and Y stack register.
Program:
Terms of use.
So now we have the subroutines:
[X, Y, Z, T | L]-> Program invoking U001 first and U070 last ->[X', Y', X, Y | L]Where X' is new content of X stack register present in the X stack register before U079 is executed and Y' is new content of Y stack register present in Y stack register before U079 is executed.
Of interest for programs that do not take stack register input but produces a result in the X and Y stack register.
Program:
U079 4Comments:
U080 STO I
U081 RDN
U082 RCL(I)
U083 ABS
U084 RDN
UO85 XEQ U041
U086 R^
U087 R^
U088 RTN
Terms of use.
So now we have the subroutines:
- XEQ U001 to save the stack and LASTX.
- XEQ U029 to restore the stack and LASTX given U001 has been used to save.
- XEQ U050 to implement operation native unary operation stack and LASTX behaviour given U001 has been used to save.
- XEQ U070 to push single value on the stack and preserve LASTX given U001 has been used to save.
- XEQ U079 to push two values on the stack and preserve LASTX given U001 has been used to save.
Sunday, October 7, 2007
HP-35s 3D and 2D vector unpack subroutines
Subroutines to unpack 3D and 2D vectors when need to work on individual components.
Stack Input/Output:
Terms of use.
Uses the X label for vector utility programs/routines, from before have cross product and normalization.
Stack Input/Output:
3D case: [[u0, u1, u2], Y, Z, T | L]-> X008 ->[u2, u1, u0, u0 | [u0, u1, u2]]Program:
2D case: [[u0, u1], Y, Z, T | L]-> X018 ->[u1, u0, Y, Y | [u0, u1]]
XOO8 [1,0,0]Comments:
X009 X<>Y
X010 x
X011 [0,1,0]
X012 LASTX
X013 x
X014 [0,0,1]
X015 LASTX
X016 x
X017 RTN
X018 [1,0]
X019 X<>Y
X020 x
X021 [0,1]
X022 LASTX
X023 x
X024 RTN
Terms of use.
Uses the X label for vector utility programs/routines, from before have cross product and normalization.
Wednesday, October 3, 2007
Addition to the HP-35s stack save/restore program - II
Extenstion to the U program for the case when a result has been produced and should be pushed on the stack:
Of interest for programs that do not take stack register input but produces a result in the X stack register.
Program:
Terms of use.
So now we have the subroutines:
[X, Y, Z, T | L]->Program invoking U001 first and U070 last ->[X', X, Y, Z | L]Where X' is new content of X stack register present in the X stack register before U070 is executed.
Of interest for programs that do not take stack register input but produces a result in the X stack register.
Program:
U070 4Comments:
U071 STO I
U072 RDN
U073 RCL(I)
U074 ABS
U075 RDN
U076 XEQ U037
U077 R^
U078 RTN
Terms of use.
So now we have the subroutines:
- XEQ U001 to save the stack and LASTX.
- XEQ U029 to restore the stack and LASTX given U001 has been used to save.
- XEQ U050 to implement operation native unary operation stack and LASTX behaviour given U001 has been used to save.
- XEQ U070 to push single value on stack and preserve LASTX given U001 has been used to save.
Tuesday, September 25, 2007
Cross product and normalizing a vector on the HP-35s
NOTE: An error has been corrected in this program listing around 20070927 16:30 UTC.
Now need to calculate the cross product of two 3D vector in the HP-35s Euclid Pack implementation. One should think that the cross product would have been a build in function on th 35s, but no, we need to roll our own: Line 001-003 in the following program.
Normalizing a vector (keeping direction but making it of unit length) is a common operation performed on directional only vectors. Subroutine X006 performs normalization.
Stack Input/Output:
Cross product:
Normalization:
Program:
Terms of use.
Now need to calculate the cross product of two 3D vector in the HP-35s Euclid Pack implementation. One should think that the cross product would have been a build in function on th 35s, but no, we need to roll our own: Line 001-003 in the following program.
Normalizing a vector (keeping direction but making it of unit length) is a common operation performed on directional only vectors. Subroutine X006 performs normalization.
Stack Input/Output:
Cross product:
[[ux, uy, uz], [vx, vy, vz], Z, T | L]-> XEQ X001 ->[[wx, wy, wz], [ux, uy, uz], [vx, vy, vz], Z | L]Where the w vector is the result of u*v.
Normalization:
[u, Y, Z, T | L]-> XEQ U004 ->[u/|u|, Y, Z, T | u]Where u is a 2D or 3D.
Program:
X001 LBL XComments:
X002 eq [([0,1,0]xREGY)x([0,0,1]xREGX)-([0,0,1]xREGY)x([0,1,0]xREGX),
([0,0,1]xREGY)x([1,0,0]xREGX)-([1,0,0]xREGY)x([0,0,1]xREGX),
([1,0,0]xREGY)x([0,1,0]xREGX)-([0,1,0]xREGY)x([1,0,0]xREGX)]
X003 RTN
X004 ABS
X005 RDN
X006 eq LASTX/REGT
X007 RTN
Terms of use.
Sunday, September 23, 2007
Addition to the HP-35s stack save/restore program - I
The following extension to the U001 subroutine allow for simulating unary operation (one that only operates on value in X stack register and saves old value in LASTX register): Get what was in the X register to LASTX, leave what is in X register in X (this is your new operation's result) and restore Y, Z and T registers.
Program:
Terms of use.
So now we have the subroutines:
20070929:2035UTC : Change because of fix in U program.
Program:
U050 0Comments:
U051 STO I
U052 RDN
U053 RCL(I)
U054 ABS
U055 RDN
U056 3
UO57 STO I
U058 RDN
U059 RCL(I)
U060 2
U061 STO I
UO62 RDN
U063 RCL(I)
U064 1
U065 STO I
U066 RDN
U067 RCL(I)
U068 R^
U069 RTN
Terms of use.
So now we have the subroutines:
- XEQ U001 to save the stack and LASTX.
- XEQ U029 to restore the stack and LASTX given U001 has been used to save.
- XEQ U050 to implement operation native unary operation stack and LASTX behaviour given U001 has been used to save.
20070929:2035UTC : Change because of fix in U program.
Saturday, September 22, 2007
Modified HP-35s stack save/restore program
Decided wanted the U program to also save/restore the LASTX register.
Modified program:
Terms of use.
LASTX is saved to register 4 and register 5 gets a non zero to allocate registers for sure.
Recall soubroutine is now U029.
Change history:
20070929:2035UTC : An error has been corrected: The error had to do with not properly allocating indirect registers if happen to store zeros in reg. 4 and downwards in sequence... See here for more on this topic.
Modified program:
U001 LBL UComments:
U002 X<> I
U003 RDN
U004 0
U005 X<> I
U006 STO(I)
U007 RDN
U008 1
U009 STO I
U010 RDN
U011 STO(I)
U012 RDN
U013 2
U014 STO I
U015 RDN
U016 STO(I)
U017 RDN
U018 3
U019 STO I
U020 RDN
U021 STO(I)
U022 4
U023 STO I
U024 LASTX
U025 STO(I)
U026 5
U027 STO I
U028 STO(I)
U029 4
U030 STO I
U031 RCL(I)
U032 ABS
U033 3
U034 STO I
U035 RDN
U036 RCL(I)
U037 2
U038 STO I
U039 RDN
U040 RCL(I)
U041 1
U042 STO I
U043 RDN
U044 RCL(I)
U045 0
U046 STO I
U047 RDN
U048 RCL(I)
U049 RTN
Terms of use.
LASTX is saved to register 4 and register 5 gets a non zero to allocate registers for sure.
Recall soubroutine is now U029.
Change history:
20070929:2035UTC : An error has been corrected: The error had to do with not properly allocating indirect registers if happen to store zeros in reg. 4 and downwards in sequence... See here for more on this topic.
Saving HP-35s' stack in indirect registers
NOTE: Program here has bugs and is no longer maintained, use program listed here.
The method of imitating native operations stack and lastx behaviour used here and here is perfect for cases when job can be done with a single equation. For longer and more traditional rpn type of programs one may want to save the stack.
The following program stores X stack register content in register 0, Y stack register in 1, Z stack register in 2 and T stack register in 3.
Program:
Terms of use.
The start is a bit tricky since we are storing in indirect registers (do not want to use high valuable variable registers for this) and need to enter index 0 in I but stack is full of stuff not to be lost. Rescue operator is X<> I: Swaps content in I with X, get old I content to T and put index O in X, swap it with old X content which then is stored in register 0. From then on it is straight forward.
This program restore the stack after it is saved (program calling propably would like that...), that is what lines 22-38 does. Note that when 22-38 execute in context of last part of saving the stack there are some redundant lines, but wrote it like this so XEQ U022 can be used in general to recall saved stack.
NOTE: I made a modification and an extension to this program.
The method of imitating native operations stack and lastx behaviour used here and here is perfect for cases when job can be done with a single equation. For longer and more traditional rpn type of programs one may want to save the stack.
The following program stores X stack register content in register 0, Y stack register in 1, Z stack register in 2 and T stack register in 3.
Program:
U001 LBL UComments:
U002 X<> I
U003 RDN
U004 0
U005 X<> I
U006 STO(I)
U007 RDN
U008 1
U009 STO I
U010 RDN
U011 STO(I)
U012 RDN
U013 2
U014 STO I
U015 RDN
U016 STO(I)
U017 RDN
U018 3
U019 STO I
U020 RDN
U021 STO(I)
U022 3
U023 STO I
U024 RDN
U025 RCL(I)
U026 2
U027 STO I
U028 RDN
U029 RCL(I)
U030 1
U031 STO I
U032 RDN
U033 RCL(I)
U034 0
U035 STO I
U036 RDN
U037 RCL(I)
U038 RTN
Terms of use.
The start is a bit tricky since we are storing in indirect registers (do not want to use high valuable variable registers for this) and need to enter index 0 in I but stack is full of stuff not to be lost. Rescue operator is X<> I: Swaps content in I with X, get old I content to T and put index O in X, swap it with old X content which then is stored in register 0. From then on it is straight forward.
This program restore the stack after it is saved (program calling propably would like that...), that is what lines 22-38 does. Note that when 22-38 execute in context of last part of saving the stack there are some redundant lines, but wrote it like this so XEQ U022 can be used in general to recall saved stack.
NOTE: I made a modification and an extension to this program.
Subscribe to:
Posts (Atom)
