WP34s: linear equation system « Next Oldest | Next Newest »

 ▼ fhub Posting Freak Posts: 1,216 Threads: 75 Joined: Jun 2011 08-14-2011, 08:52 AM Now that we have an extended quadratic equation solver, what about a simple linear equation system solver for 2 variables? I know this would be handled by a matrix package, but for 2 variables/equations it's just a few bytes and would fit quite well to SLVQ. ;-) Here's my code for this (SLVL, SLVS or SLVLS ?): ```/* Linear Equation System a*x + b*y = c d*x + e*y = f Mode: SSIZE8 Input: a [ENTER] b .... e [ENTER] f Output: X:x Y:y Z:det (or "Invalid data" if det=0) Used: Stack */ 001 LBL'LS' 002 RCL B 003 RCL[times] Z 004 RCL B 005 RCL[times] A 006 - 007 x=0? 008 ERR 18 009 RCL C 010 RCL[times] Z 011 RCL B 012 RCL[times] B 013 - 014 RCL/ Y 015 RCL B 016 RCL[times] A 017 RCL D 018 RCL[times] A 019 - 020 RCL/ Z 021 0 022 ENTER[^] 023 [cmplx]R[v] 024 RTN ``` It preserves the coefficients of the 2nd equation (d,e,f), puts the coefficient determinant to Z and the solution x,y to X,Y. Of course it works only in SSIZE8 mode! With the use of Pauli's 'private' ;-) internal registers it could even preserve ALL coefficients, if e.g. the determinant would be stored to register L (or simply ignored). If you want you can include it in the XROM, if not then it's just one more little user program ... ;-) Franz Edited: 14 Aug 2011, 8:54 a.m. ▼ Paul Dale Posting Freak Posts: 3,229 Threads: 42 Joined: Jul 2006 08-14-2011, 07:00 PM Quote:Of course it works only in SSIZE8 mode! and Quote:If you want you can include it in the XROM are exclusive. So a library routine it will have to be. - Pauli ▼ fhub Posting Freak Posts: 1,216 Threads: 75 Joined: Jun 2011 08-14-2011, 07:24 PM Yes, I was already afraid that SSIZE8 might be a problem for XROM. But I can't store 6 values on a 4-level stack - and using registers instead is no good idea IMO, because it's much more complicated to input. Now for another idea I had today: ;-) Currently register "I" is only used in complex operations and stores the previous imaginary part (Y-value). What if the same would be done also for real (duadic) operations, i.e. before executing any of these operations the Y-value is stored in I (together with X in L)? So also for real operations the I-register would work like a "LastY" - this would almost allow a kind of "UNDO" function: after any duadic operation (e.g. done by mistake) you could just do DROP, RCL I, RCL L, and you have the previous stack back again. I think this would be very easy to implement (if I don't overlook something?), because such a "STO Y to I" could simply be done whenever X is stored in L. Good idea or not? ;-) Franz Paul Dale Posting Freak Posts: 3,229 Threads: 42 Joined: Jul 2006 08-14-2011, 07:13 PM Is there a reason you've got three cross products (of the form a b - c d) here but aren't using complex multiply to maintain accuracy? - Pauli ▼ fhub Posting Freak Posts: 1,216 Threads: 75 Joined: Jun 2011 08-14-2011, 07:38 PM Quote: Is there a reason you've got three cross products (of the form a b - c d) here but aren't using complex multiply to maintain accuracy? Yes, there are even a few reasons! ;-) 1) I would have to put all 4 values (used in [cpx]*) at the right position on the stack, which would cost a lot of program steps 2) this correct positioning would also need much more than the 8 stack registers, because the values used for any [cpx]* are used in the following step(s), too (and without actually trying it I doubt that I could use both the real and imaginary part of the complex product, so one of them would always be useless) 3) last but not least I don't care SO much about EXTREMELY high precision (anywhere at 16 digits) like you - when do you (in every-day-problems) really have a linear equation system (2x2) with coefficients which would give wrong results if you don't use your favoured "super-high-precision-tricks"? ;-) Franz ▼ Marcus von Cube, Germany Posting Freak Posts: 3,283 Threads: 104 Joined: Jul 2005 08-15-2011, 05:19 AM Franz, neat little program. One more idea which might even allow for Pauli's idea to compute the determinant with a complex multiply: Why not enter the complete system column wise or coefficients first, then right hand side? If the routine would preserve the coefficients in stack levels Z, T, A & B and a allow to enter another set of values for the right hand side to solve a similar system without reentering the matrix. Pauli, even if in XROM the stack mechanics a nailed to 4 levels, all 8 registers are still available so that a program which expects data in registers A to D can still be written. It may consume more steps but we have some room left. ▼ Paul Dale Posting Freak Posts: 3,229 Threads: 42 Joined: Jul 2006 08-15-2011, 05:36 AM Quote:Pauli, even if in XROM the stack mechanics a nailed to 4 levels, all 8 registers are still available so that a program which expects data in registers A to D can still be written. It may consume more steps but we have some room left. XROM is for built in commands. Playing games like this with the stack & registers really isn't appropriate :-( The command has to work regardless of the stack size and the user's settings. In a library, things are very different however. - Pauli fhub Posting Freak Posts: 1,216 Threads: 75 Joined: Jun 2011 08-15-2011, 05:45 AM Quote: One more idea which might even allow for Pauli's idea to compute the determinant with a complex multiply: Why not enter the complete system column wise or coefficients first, then right hand side? If the routine would preserve the coefficients in stack levels Z, T, A & B and a allow to enter another set of values for the right hand side to solve a similar system without reentering the matrix. Yes Marcus, the idea with preserving the coefficients is indeed a very good one, and also using the complex multiply would be preferable, but both ideas require to use additional registers Rnn - it's just not possible to do this with an 8-level stack (at least not without dozens of "stack-swappings"). So if you would say using additional registers is ok, then I would certainly give it a try ... ;-) But what surprises me a bit more at the moment: my idea above (having an additional "LastY" (i.e. storeing Y in "I") to the usual "LastX" in L) doesn't even seem to be worth any answer!? - And this although such a "LastY" after a duadic operation would certainly be just as useful as "LastX" for further calculations. - And this although it would just need an internal "Y -> I" command whenever X is backup'ed in L. Franz ▼ Marcus von Cube, Germany Posting Freak Posts: 3,283 Threads: 104 Joined: Jul 2005 08-15-2011, 05:52 AM For me your suggestion about LastY sounds reasonable. Let's wait what the others think about it. Paul Dale Posting Freak Posts: 3,229 Threads: 42 Joined: Jul 2006 08-15-2011, 05:54 AM Since you are pushing the point, I hope you can deal with a bit of negativity :-) We considered a last Y a long time back. It doesn't work and introduces inconsistencies. Ignoring the lack of RAM for extra registers for a moment... Complex dyadic operations would require a complex equivalent of last Y. Triadic operations would require a last Z. Fortunately, there are no complex triadic operations yet or we'd require more. We simply can't stay consistent treading this path. Now think about the number of times you've used register I as a temporary (& I've seen your code doing just this and I've done the same many times). Users can and will do this. Adding a last Y using "I" will impact this use of the register. So, yes we considered this and rejected it. Now, we could use our final bit in the mode word to specify an optional stack backup before every operation or not. That would achieve pretty much the same thing. Is this worthwhile? I really don't know. - Pauli ▼ Marcus von Cube, Germany Posting Freak Posts: 3,283 Threads: 104 Joined: Jul 2005 08-15-2011, 05:59 AM Quote: Now, we could use our final bit in the mode word to specify an optional stack backup before every operation or not. That would achieve pretty much the same thing. Is this worthwhile? I really don't know. This reminds me of the "Last Stack" feature of the RPL machines. I think it's overkill. We should consider to put STOS and RCLS on the keyboard instead (where ITOA and ATOI reside now) and to allow register A as the destination if in SSIZE4 mode. ▼ Paul Dale Posting Freak Posts: 3,229 Threads: 42 Joined: Jul 2006 08-15-2011, 06:02 AM Quote:This reminds me of the "Last Stack" feature of the RPL machines. I think it's overkill. We should consider to put STOS and RCLS on the keyboard instead (where ITOA and ATOI reside now) and to allow register A as the destination if in SSIZE4 mode. Allowing A is problematic and would require some work in the argument processing code. I also think it is overkill. - Pauli ▼ Marcus von Cube, Germany Posting Freak Posts: 3,283 Threads: 104 Joined: Jul 2005 08-15-2011, 07:10 AM Quote: Allowing A is problematic and would require some work in the argument processing code. Yes, I know. But I still thinks it's worth the effort. So with a 4 level stack, A to D can assume the role of a quick backup. ▼ Paul Dale Posting Freak Posts: 3,229 Threads: 42 Joined: Jul 2006 08-15-2011, 07:12 AM What about a SWAP4 command? Swaps X, Y, Z & T with A, B, C, & D. Not quite as good as a STO/RCL of the stack but useful I think. - Pauli ▼ fhub Posting Freak Posts: 1,216 Threads: 75 Joined: Jun 2011 08-15-2011, 07:26 AM Quote: What about a SWAP4 command? LOL, that's funny: exactly my idea from a few days ago ... All 3 features (Save/Restore/Swap-stack between the lower- and upper-stack were my suggestions a few days ago (and I've even provided user-code for all 3 commands), and what answer did I get? "not needed, you can use STOS and RCLS instead" And now when Marcus (and even Pauli himself) 'suggest' exactly the same features, they are now suddenly "useful"? Sorry, but I couldn't resist ... ;-) Edited: 15 Aug 2011, 7:44 a.m. after one or more responses were posted ▼ Marcus von Cube, Germany Posting Freak Posts: 3,283 Threads: 104 Joined: Jul 2005 08-15-2011, 08:26 AM Some suggestions just take their time... ;-) Paul Dale Posting Freak Posts: 3,229 Threads: 42 Joined: Jul 2006 08-15-2011, 05:44 PM I've figured out the "best" way to do the swap4 command: ``` LBL'SW4' [cpx]SWAP C [cpx]SWAP Z [cpx]SWAP C [cpx]SWAP A RTN ``` Seven instructions = 14 bytes. To introduce an internal command table entry takes 12 bytes and to add a function that does nothing pushes things closer to 40 bytes. To add the relevant swaps pushes this higher. So this is the most compact implementation I can think of. The question is to do this as a user subroutine -- no extra flash bytes but 7 user steps -- or put it in xrom as is -- 14 bytes -- or to put it in xrom with an internal command to call it -- 30+ bytes -- or to write a dedicated command -- 60+ bytes. I'm leaning towards letting the user do this one. - Pauli ▼ Marcus von Cube, Germany Posting Freak Posts: 3,283 Threads: 104 Joined: Jul 2005 08-16-2011, 02:10 AM Now add another label, LBL 32, and XEQ x<>y does the swap from the keyboard as long as the PC is positioned in the correct region. fhub Posting Freak Posts: 1,216 Threads: 75 Joined: Jun 2011 08-15-2011, 06:10 AM Quote: Since you are pushing the point, I hope you can deal with a bit of negativity :-) Well, a bit of negativity won't be a problem for me, but as far as I can remember each and every idea or suggestion from me to improve the 34s has been rejected by you so far - either "not useful" or "not possible"! So since it seems that all my ideas are in fact that bad, I guess it's better for me (and you) if I completely resign from the 34s project. Franz Edited: 15 Aug 2011, 6:11 a.m. ▼ Paul Dale Posting Freak Posts: 3,229 Threads: 42 Joined: Jul 2006 08-15-2011, 06:53 AM Grow up. We've taken several of your suggestions on board and I expect we'll accept more in the future. Just not this one. You're the one who pushed for a comment about this one. - Pauli ▼ fhub Posting Freak Posts: 1,216 Threads: 75 Joined: Jun 2011 08-15-2011, 07:23 AM Quote: Grow up. I would rather say you should grow up! Your usual stubborn argument "because it won't work for all functions, we don't implement it at all" is pure nonsense, and I really can't hear it anymore! Because you won't have a LastZ for a few single 'exotic' triadic functions (or for complex functions), you don't implement such an extremely useful LastY feature at all? Just because a few percent of functions (certainly used very seldom) can't profit from such a feature, all other (maybe 95%) functions shouldn't profit from a LastY, too? Sorry, but that's just ridiculous. (I guess you would also reject a 2nd prize in a lottery just because you didn't win the 1st prize?) Quote: We've taken several of your suggestions on board May I laugh? Yes, I'm good enough for you to improve and optimize some code (crossproduct, TVM, SOLVQ), but when it comes to ideas or suggestions your opinion is that I should better shut up. Thanks, but I'm not your slave - it's really enough now! Goodbye - an my best wishes to the WP34s team, Franz ▼ Walter B Posting Freak Posts: 4,587 Threads: 105 Joined: Jul 2005 08-15-2011, 03:54 PM Number 13 and counting ;-)

 Possibly Related Threads... Thread Author Replies Views Last Post HP prime: linear solver app Alberto Candel 1 1,068 11-21-2013, 01:57 AM Last Post: Michael Carey HP Prime: Linear Solver app bug BruceH 0 811 11-15-2013, 06:36 PM Last Post: BruceH PRIME: re-format the flash drive to recover the operating system Harold A Climer 2 1,373 11-06-2013, 12:22 AM Last Post: Michael de Estrada Equation Library/App for the Prime Harold A Climer 3 1,372 10-30-2013, 10:14 AM Last Post: CompSystems Equation Library on the PRIME Harold A Climer 0 845 10-26-2013, 10:01 AM Last Post: Harold A Climer Meltiple Equation Solver PRIME Vs. HP 50G Harold A Climer 5 1,417 10-07-2013, 05:11 PM Last Post: CR Haeger HP Prime Solving Nonlinear System of Equations for Complex Results Helge Gabert 11 3,360 09-30-2013, 03:44 AM Last Post: From Hong Kong EOT--TI N-Spire Equation Limit Matt Agajanian 2 1,059 09-22-2013, 12:37 PM Last Post: Matt Agajanian Does Prime Have a Multiple Equation Solver? Norman Dziedzic 2 1,062 09-20-2013, 09:43 AM Last Post: Norman Dziedzic Equation of the parabola given three points Gerson W. Barbosa 27 5,120 09-18-2013, 01:58 PM Last Post: Gerson W. Barbosa

Forum Jump: