Post Reply 
root of a quadratic equation
08-22-2015, 09:41 AM (This post was last modified: 08-22-2015 06:18 PM by tigger.)
Post: #1
root of a quadratic equation
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?
Find all posts by this user
Quote this message in a reply
08-22-2015, 12:03 PM
Post: #2
RE: root of a quadratic equation
Why not using PROOT?
Code:
\<< { 3 } \->ARRY PROOT OBJ\-> DROP \>>

Cheers
Thomas
Find all posts by this user
Quote this message in a reply
08-22-2015, 05:17 PM
Post: #3
RE: root of a quadratic equation
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?
Find all posts by this user
Quote this message in a reply
08-22-2015, 06:55 PM
Post: #4
RE: root of a quadratic equation
e.g. for -x^2+3x+1=0
input:
-1 3 1
<< 3 →ARRY PROOT OBJ→ DROP >> EVAL
output:
1: -.302775637732
2: 3.30277563773
Find all posts by this user
Quote this message in a reply
08-22-2015, 07:01 PM
Post: #5
RE: root of a quadratic equation
I was using tri-graphs to write the code. This makes it easy to transfer it to the calculator.

HTH
Thomas
Find all posts by this user
Quote this message in a reply
08-22-2015, 07:28 PM
Post: #6
RE: root of a quadratic equation
(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.
Find all posts by this user
Quote this message in a reply
08-22-2015, 07:33 PM (This post was last modified: 08-22-2015 07:37 PM by Gerson W. Barbosa.)
Post: #7
RE: root of a quadratic equation
(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.
Find all posts by this user
Quote this message in a reply
08-22-2015, 07:35 PM
Post: #8
RE: root of a quadratic equation
(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
Find all posts by this user
Quote this message in a reply
08-22-2015, 08:07 PM
Post: #9
RE: root of a quadratic equation
(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.
Find all posts by this user
Quote this message in a reply
08-22-2015, 08:18 PM
Post: #10
RE: root of a quadratic equation
(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
Find all posts by this user
Quote this message in a reply
08-22-2015, 11:06 PM
Post: #11
RE: root of a quadratic equation
(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}
Find all posts by this user
Quote this message in a reply
08-23-2015, 12:43 AM
Post: #12
RE: root of a quadratic equation
(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
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)