HP Forums
root of a quadratic equation - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: General Forum (/forum-4.html)
+--- Thread: root of a quadratic equation (/thread-4554.html)



root of a quadratic equation - tigger - 08-22-2015 09:41 AM

These two equations help to solve a root of a quadratic equation:
<< 2 ->LIST SWAP / EVAL SWAP -2 / DUP SQ ROT - v/ DUP2 + ROT ROT - >>
<< 3 PICK / SWAP ROT -2 * / DUP SQ ROT - SQRT DUP2 * ROT ROT - >>



[quote='tigger' pid='40913' dateline='1440236517']
<< 2 ->LIST SWAP / EVAL SWAP -2 / DUP SQ ROT - v/ DUP2 + ROT ROT - >>

The calculator put a blank between the - and the 2 automatically. This could have been the mistake in the program.
<< 2 ->LIST SWAP / EVAL SWAP - 2 / DUP SQ ROT - v/ DUP2 + ROT ROT - >>

<< 3 PICK / SWAP ROT -2 * / DUP SQ ROT - SQRT DUP2 * ROT ROT - >>


Is there a sign for SQRT on this page?
When I punched the keys in the calculator itself made a blank between the - and the 2. How could I know that the calculator made this mistake?
Does the HP always makes mistakes like this?
How can I avoid this kind of mistakes?

There might be any hope and help to rectify these short programs?


RE: root of a quadratic equation - Thomas Klemm - 08-22-2015 12:03 PM

Why not using PROOT?
Code:
\<< { 3 } \->ARRY PROOT OBJ\-> DROP \>>

Cheers
Thomas


RE: root of a quadratic equation - tigger - 08-22-2015 05:17 PM

When I type the first "\" before << I get "Invalid Syntax".
Without the first "\" I get: Error "Can't find Selection.

Could you write me what I did wrong?


RE: root of a quadratic equation - Hlib - 08-22-2015 06:55 PM

e.g. for -x^2+3x+1=0
input:
-1 3 1
<< 3 →ARRY PROOT OBJ→ DROP >> EVAL
output:
1: -.302775637732
2: 3.30277563773


RE: root of a quadratic equation - Thomas Klemm - 08-22-2015 07:01 PM

I was using tri-graphs to write the code. This makes it easy to transfer it to the calculator.

HTH
Thomas


RE: root of a quadratic equation - Gerson W. Barbosa - 08-22-2015 07:28 PM

(08-22-2015 12:03 PM)Thomas Klemm Wrote:  Why not using PROOT?
Code:
\<< { 3 } \->ARRY PROOT OBJ\-> DROP \>>

Well, for this example PROOT will give ugly approximations:

1
'-√2-√3'
'√6'

« { 3 } →ARRY PROOT OBJ→ DROP
»

EVAL


-->

1.41421356237
1.73205080757


For exact results, in exact mode I would prefer something like

« ROT NEG SWAP OVER
/ UNROT / 2 / SWAP
OVER SQ + √ DUP2 -
FACTOR UNROT +
FACTOR
»

-->

'√2'
'√3'


Cheers,

Gerson.


RE: root of a quadratic equation - Gerson W. Barbosa - 08-22-2015 07:33 PM

(08-22-2015 09:41 AM)tigger Wrote:  There might be any hope and help to rectify these short programs?

While these aren't fixed, you can try

« ROT NEG SWAP OVER / UNROT / 2. / SWAP OVER SQ + √ DUP2 - UNROT + »

Not sure whether this is shorter, though.

Sizewise, Thomas Klemm's suggestion above is a much better option.

Regards,

Gerson.


RE: root of a quadratic equation - Thomas Klemm - 08-22-2015 07:35 PM

(08-22-2015 09:41 AM)tigger Wrote:  Is there a sign for SQRT on this page?
  • \v/ (tri-code)
  • √ (unicode)
  • \(\sqrt{}\) (LaTeX)
Quote:When I punched the keys in the calculator itself made a blank between the - and the 2. How could I know that the calculator made this mistake?
Does the HP always makes mistakes like this?
How can I avoid this kind of mistakes?

To enter -2 you have to punch the [2] and then the [±] key.

Cheers
Thomas


RE: root of a quadratic equation - Gerson W. Barbosa - 08-22-2015 08:07 PM

(08-22-2015 09:41 AM)tigger Wrote:  These two equations help to solve a root of a quadratic equation:

<< 3 PICK / SWAP ROT -2 * / DUP SQ ROT - SQRT DUP2 * ROT ROT - >>

* and - at the end should be - and +, respectively:

<< 3 PICK / SWAP ROT -2 * / DUP SQ ROT - SQRT DUP2 - ROT ROT + >>

On the HP 50g, we can use

<< PICK3 / SWAP ROT -2 * / DUP SQ ROT - SQRT DUP2 - UNROT + >>

and save a few bytes. This is 50-byte long, 5 bytes shorter than my attempt at this above.

Gerson.


RE: root of a quadratic equation - Thomas Klemm - 08-22-2015 08:18 PM

(08-22-2015 09:41 AM)tigger Wrote:  There might be any hope and help to rectify these short programs?

Here's a variant from a previous thread using local variables:

Code:
« → a b c
  « b a / -2 /
    c a / → p q
    « p SQ q - √ → D
      « p D -
        p D +
      »
    »
  »
»

Cheers
Thomas


RE: root of a quadratic equation - Hlib - 08-22-2015 11:06 PM

(08-22-2015 07:28 PM)Gerson W. Barbosa Wrote:  Well, for this example PROOT will give ugly approximations:

1
'-√2-√3'
'√6'

« { 3 } →ARRY PROOT OBJ→ DROP
»

EVAL


-->

1.41421356237
1.73205080757


For exact results, in exact mode I would prefer something like

« ROT NEG SWAP OVER
/ UNROT / 2 / SWAP
OVER SQ + √ DUP2 -
FACTOR UNROT +
FACTOR
»

-->

'√2'
'√3'


Cheers,

Gerson.

The simple way to obtain result:
'x²+(-√2-√3)*x+√6=0'
SOLVEVX
SIMPLIFY
=>>
{x=√2 x=√3}


RE: root of a quadratic equation - Gerson W. Barbosa - 08-23-2015 12:43 AM

(08-22-2015 11:06 PM)Hlib Wrote:  
(08-22-2015 07:28 PM)Gerson W. Barbosa Wrote:  Well, for this example PROOT will give ugly approximations:

1
'-√2-√3'
'√6'

« { 3 } →ARRY PROOT OBJ→ DROP
»

EVAL


-->

1.41421356237
1.73205080757


For exact results, in exact mode I would prefer something like

« ROT NEG SWAP OVER
/ UNROT / 2 / SWAP
OVER SQ + √ DUP2 -
FACTOR UNROT +
FACTOR
»

-->

'√2'
'√3'


Cheers,

Gerson.

The simple way to obtain result:
'x²+(-√2-√3)*x+√6=0'
SOLVEVX
SIMPLIFY
=>>
{x=√2 x=√3}

Well, live and learn! Smile