|WP34s: linear equation system|
Message #1 Posted by fhub on 14 Aug 2011, 8:52 a.m.
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
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.
Input: a [ENTER] b .... e [ENTER] f
Output: X:x Y:y Z:det (or "Invalid data" if det=0)
002 RCL B
003 RCL[times] Z
004 RCL B
005 RCL[times] A
008 ERR 18
009 RCL C
010 RCL[times] Z
011 RCL B
012 RCL[times] B
014 RCL/ Y
015 RCL B
016 RCL[times] A
017 RCL D
018 RCL[times] A
020 RCL/ Z
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 ... ;-)
Edited: 14 Aug 2011, 8:54 a.m.