HP Forums

Full Version: root of a quadratic equation
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
Why not using PROOT?
Code:
\<< { 3 } \->ARRY PROOT OBJ\-> DROP \>>

Cheers
Thomas
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?
e.g. for -x^2+3x+1=0
input:
-1 3 1
<< 3 →ARRY PROOT OBJ→ DROP >> EVAL
output:
1: -.302775637732
2: 3.30277563773
I was using tri-graphs to write the code. This makes it easy to transfer it to the calculator.

HTH
Thomas
(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.
(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.
(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
(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.
(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
(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}
(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
Reference URL's