Quadratic formula program help  Printable Version + HP Forums (https://archived.hpcalc.org/museumforum) + Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum1.html) + Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum2.html) + Thread: Quadratic formula program help (/thread224906.html) 
Quadratic formula program help  Chris C  06142012 I found this short program here: Q001 LBL Q Q002 CF 10 Q003 INPUT A Q004 INPUT B Q005 INPUT C Q006 B÷(2xA) <the "divided by" symbol I input here seems to have been changed to a "?" by the forum's system Q007 ENTER Q008 ENTER Q009 B^24xAxC Q010 x>=0? Q011 GTO Q017 Q012 +/ Q013 sqrt ;press k key Q014 i Q015 x Q016 GTO Q018 Q017 sqrt Q018 2xA Q019 ÷ <the "divided by" symbol I input here seems to have been changed to a "?" by the forum's system Q020 + Q021 x<>y Q022 LASTx Q023  Q024 RTN It keeps erroring out on line Q006. It seems to have a problem with using the negative/minus sign to make B negative in the line. I've tried everything I can think of. It runs fine after I remove the negative/minus sign from that line. How should I enter this line? Also, line Q014 is just the the "i" key, right? Thanks!
Edited: 14 June 2012, 11:46 p.m.
Re: Quadratic formula program help  LHH  06152012 I'm no expert but I would suggest: 1 check syntax for the calc being used 2 maybe it needs apostrophes 'b/(2*a)' 3 be sure a not= 0 of course
Same may apply to other lines as well.
Re: Quadratic formula program help  Matt Agajanian  06152012 Hi there. If you're writing an HP35S app, my suggestion is to put 0i1 (keystrokes '0,' 'i,' '1') in line Q014 if you're trying to put the value of 1i (1 * 1) on the stack. I think just 'i' on line Q014 is what may be generating an execution or syntax error. Secondly, for line Q006, the B should be entered as using the +/ key as that is the negation function. Using the  key is only for the subtraction operation. So, to negate a value, the  symbol should be entered with the +/ key.
Edited: 15 June 2012, 1:35 a.m.
Re: Quadratic formula program help  Chris C  06152012 Thanks, Matt. All I had to do to make it work was use the +/ key for the negative sign. No other changes were necessary. Anyone know whey some of these quadratic equation solver programs are so long, but this one is tiny and works great (and even finds imaginary roots)?
Re: Quadratic formula program help  Paul Dale  06152012 I'm not sure why all these solvers are longer, however the 34S's is longer because it cares about numeric stability and avoids the cancellations inherent in the naïve formula. The 34S also uses complex multiplication to evaluate b^2  4ac in extra precision. There have been several attempt to produce very short quadratic solvers. I don't remember the shortest anyone has produced, but it was very concise. Palmer Hanson's Cadillac solver is instructive and has some nice examples at the end to validate your code with  it is possible to get the correctly rounded answer to all of these with care.
Re: Quadratic formula program help  Chris C  06152012 My apologies to everyone. I neglected to specify that I am using a 35s, and so was asking about the programs for it...
But the reason I ask is because this program is very short compared to every other program for the 35s I've seen, that also found imaginary roots. (I've seen ones that didn't find imaginary roots that were short.) It's a singlefunction program, but it's goooood. My compliments to the author if he (you?) ever see this thread.
Re: Quadratic formula program help  Gerson W. Barbosa  06152012 Quote:
The 16step Quadratic Equation for the 42S in the Software Library is essentially Michael Harwood's very short quadratic solver for the HP41C. Were the former labeled "Q" instead of "QUAD" it would be 26 bytes long (25 if the final RTN is replaced with END). Mine (Message #3 in this thread) is one step shorter and preserves the stack register X, but it is 28 bytes long. Gerson.
Re: Quadratic formula program help  Walter B  06162012 Thanks. Just for the record, it's called SLVQ.
Re: Quadratic formula program help  Matt Agajanian  06162012 You're welcome. Glad to help.
Re: Quadratic formula program help  Paul Dale  06162012 The 34S quadratic solver in full:
XLBL"QUAD" /* Entry: QUADRATIC SOLVER */
Re: Quadratic formula program help  Gerson W. Barbosa  06162012 Sorry for the typo. Won't happen agian!
Re: Quadratic formula program help  Katie Wasserman  06162012 Very nice piece of code! I especially like your clever use of the stack shuffle function, [<>]. This is one of the best features of this machine, I wish HP would have put this into their RPN calculators long ago, it's extremely powerful yet simple to use.
Katie
Re: Quadratic formula program help  Paul Dale  06162012 The shuffle here is saving two instructions. e.g. x<>y DROP x<>y but I'm sure there are other sequences too. Early on, I had a shuffle instruction that included L and shuffled XYZT and L. Probably better without the extra unnecessary complexity.
Re: Quadratic formula program help  Palmer O. Hanson, Jr.  06162012 In late 2008 I was working with Rodger Rosenbaum on testing of quadratic solvers and wrote Quote:But I note that I never did add the test case to the article. Maybe that was an early indication of things to come where recently I was unable to remember that Grand Forks is in North Dakota not in Minnesota.
I was also doing some work with my TI89 using the approximate and exact modes. Again, from some correspondence with Rodger: Quote: Re: Quadratic formula program help  Katie Wasserman  06162012 It's the completeness of the shuffle function that I like. There are 256 combinations of stack arguments that a user might need and this instruction covers them all with a very readable syntax. Having L included in the mix is debatable as it's not really part of the stack. Did you not allow ABCD because the instruction would require 2 more bytes to encode?
Re: Quadratic formula program help  Paul Dale  06162012 A, B, C and D weren't part of the stack at the time.
Re: Quadratic formula program help  Walter B  06182012 Quote:Hmmmh ... Anyway, the display does not feature sufficient pixels for a shuffle command <>XYZTABCD in full size. Re: Quadratic formula program help  Paul Dale  06182012 And we don't have opcode space for eight or nine arguments :)
Re: Quadratic formula program help  Marcus von Cube, Germany  06192012 We would need 3 bits for each of the possible 8 destination positions, resulting in 24 bits as the argument. This is theoretically possible with the double length commands but there are restrictions which would make some combinations illegal. Walter has mentioned the argument entry and display restrictions which make an implementation complicated if not impossible. 128 KB of flash and the limited ASCII display are constraints we cannot overcome. (We've come a long way already.)
