Post Reply 
LIN-BAIRSTOW ALGORITHM for HP67/97 UPDATE!
08-14-2024, 01:46 PM (This post was last modified: 08-14-2024 05:42 PM by Thomas Klemm.)
Post: #4
RE: LIN-BAIRSTOW ALGORITHM for HP67/97
Here's a program that uses 112 lines.
A program B to solve the quadratic equation is also included.

Lin-Bairstow

This program is based on the Lin-Bairstow method to find the roots of a polynomial of degree \(n\):

\(P(x) = a_n x^n + a_{n-1} x^{n-1} + \cdots + a_2 x^2 + a_1 x + a_0 = 0\)

Code:
001: 31 25 11 : f LBL A
002: 00       : 0
003: 33 03    : STO 3
004: 33 04    : STO 4
005: 33 06    : STO 6
006: 33 07    : STO 7
007: 01       : 1
008: 00       : 0
009: 35 33    : h ST I
010: 31 25 00 : f LBL 0
011: 34 06    : RCL 6
012: 34 04    : RCL 4
013: 33 05    : STO 5
014: 34 02    : RCL 2
015: 71       : *
016: 51       : -
017: 34 03    : RCL 3
018: 33 04    : STO 4
019: 34 01    : RCL 1
020: 71       : *
021: 51       : -
022: 33 03    : STO 3
023: 34 24    : RCL (i)
024: 34 07    : RCL 7
025: 34 02    : RCL 2
026: 71       : *
027: 51       : -
028: 34 06    : RCL 6
029: 33 07    : STO 7
030: 34 01    : RCL 1
031: 71       : *
032: 51       : -
033: 33 06    : STO 6
034: 31 34    : f ISZ
035: 34 00    : RCL 0
036: 35 34    : h RC I
037: 32 71    : g x<=y
038: 22 00    : GTO 0
039: 34 03    : RCL 3
040: 34 07    : RCL 7
041: 71       : *
042: 34 04    : RCL 4
043: 34 06    : RCL 6
044: 71       : *
045: 51       : -
046: 34 05    : RCL 5
047: 34 06    : RCL 6
048: 71       : *
049: 34 04    : RCL 4
050: 34 07    : RCL 7
051: 71       : *
052: 51       : -
053: 34 05    : RCL 5
054: 34 03    : RCL 3
055: 71       : *
056: 34 04    : RCL 4
057: 32 54    : g x^2
058: 51       : -
059: 81       : /
060: 33 61 01 : STO + 1
061: 35 52    : h x<->y
062: 35 82    : h LSTx
063: 81       : /
064: 33 61 02 : STO + 2
065: 32 72    : g R->P
066: 31 24    : f RND
067: 31 61    : f x!=0
068: 22 11    : GTO A
069: 02       : 2
070: 33 51 00 : STO - 0
071: 01       : 1
072: 00       : 0
073: 35 33    : h ST I
074: 00       : 0
075: 41       : ENTER
076: 41       : ENTER
077: 41       : ENTER
078: 31 25 01 : f LBL 1
079: 35 53    : h Rv
080: 35 53    : h Rv
081: 34 24    : RCL (i)
082: 34 02    : RCL 2
083: 35 54    : h R^
084: 71       : *
085: 51       : -
086: 34 01    : RCL 1
087: 35 54    : h R^
088: 71       : *
089: 51       : -
090: 33 24    : STO (i)
091: 31 34    : f ISZ
092: 34 00    : RCL 0
093: 35 34    : h RC I
094: 32 71    : g x<=y
095: 22 01    : GTO 1
096: 35 22    : h RTN

Registers

\(\begin{matrix}
R_0 & 10 + n \\
R_1 & p \\
R_2 & q \\
R_3 & c = c_j \\
R_4 & {c}′ = c_{j+1} \\
R_5 & {c}'' = c_{j+2} \\
R_6 & b = b_i \\
R_7 & {b}′ = b_{i+1} \\
R_8 & \\
R_9 & \\
R_{10} & a_n \\
R_{11} & a_{n-1} \\
R_{12} & a_{n-2} \\
R_{13} & \cdots \\
R_{14} & \cdots \\
\end{matrix}\)

Quadratic Solver

This program solves the quadratic equation: \(T(x)=x^2+px+q=0\)

Code:
097: 31 25 12 : f LBL B
098: 34 01    : RCL 1
099: 02       : 2
100: 42       : CHS
101: 81       : /
102: 41       : ENTER
103: 41       : ENTER
104: 32 54    : g x^2
105: 34 02    : RCL 2
106: 51       : -
107: 31 54    : f sqrt
108: 51       : -
109: 35 52    : h x<->y
110: 35 82    : h LSTx
111: 61       : +
112: 35 22    : h RTN

Just be aware that this program can't find complex roots. Instead an Error will be displayed.
However it's easy to find the complex solutions. Just use:

CHS
\(\sqrt{x}\)

The solutions then are: \(Y \pm iX\)


Example

\(P(x)=2x^5-9x^4+15x^3+65x^2-267x+234=0\)

Insert coefficients

Code:
CL REG
2      STO 0
-9     STO 1
15     STO 2
65     STO 3
-267   STO 4
234    STO 5
P<>S

Initialization

Store \(10 + n\) in register \(0\) and initialize \(p = q = 1\).

Code:
15  STO 0
1   STO 1
    STO 2

Run program

Code:
A            14.0000

RCL 1         1.5000
RCL 2        -4.5000

P<>S
RCL 0         2.0000
RCL 1       -12.0000
RCL 2        42.0000
RCL 3       -52.0000
P<>S

Code:
B             1.5000
x<>y         -3.0000

Conclusion

\(2x^5-9x^4+15x^3+65x^2-267x+234=\)
\((x^2+1.5x-4.5)(2x^3-12x^2+42x-52)\)

Solutions

For \(x^2+1.5x-4.5=0\):
\(x_1=1.5\)
\(x_2=-3\)

Initialize guess

Code:
1   STO 1
    STO 2

Run program again

Code:
A             12.0000

RCL 1         -4.0000
RCL 2         13.0000

P<>S
RCL 0          2.0000
RCL 1         -4.0000
P<>S

Code:
B               Error
CLx           -9.0000
CHS            9.0000
√x             3.0000
x<>y           2.0000

Code:
P<>S
RCL 1         -4.0000
RCL 0          2.0000
÷             -2.0000
CHS            2.0000
P<>S

Conclusion

\(2x^3-12x^2+42x-52=\)
\((x^2-4x+13)(2x-4)\)

Solutions

For \(x^2-4x+13=0\):
\(x_3=2+3i\)
\(x_4=2-3i\)

For \(2x-4=0\):
\(x_5=2\)

Summary

Factors

\(2x^5-9x^4+15x^3+65x^2-267x+234=\)
\((x^2+1.5x-4.5)(x^2-4x+13)(2x-4)=\)
\((x-1.5)(x+3)(x^2-4x+13)2(x-2)=\)
\((2x-3)(x+3)(x^2-4x+13)(x-2)\)

Solutions

\(x_1=1.5\)
\(x_2=-3\)
\(x_3=2+3i\)
\(x_4=2-3i\)
\(x_5=2\)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: LIN-BAIRSTOW ALGORITHM for HP67/97 - Thomas Klemm - 08-14-2024 01:46 PM



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