|Nth order solver|
Message #6 Posted by Tizedes Csaba on 26 Aug 2003, 5:26 a.m.,
in response to message #3 by Steven Soto
this is a solution for your problem. This program can solve polinom-equations ANY of order (limited by mem). It's not too long, only 92 byte ;). It work fast with built-in solver, and use Horner-method:
Only one problem with it, it's solve JUST REAL ROOTS... But in the real problems, like mechanical stress calculations, the roots are reals.
This is the HP32SII version:
E01 LBL E #prepare of 'i'
P01 LBL P #the 'dinamical polynom'
H01 LBL H #Horner's method
RCL mul X
RCL add (i)
X01 LBL X #polynom solver
GTO R #if found root goto 'R'
SF 0 #no real root, set flag 0
D01 LBL D #decrement polynom order,
J01 LBL J #use a little modified Horner method
RCL mul X
RCL add (i)
STO (i) #overwrite coefficients
ISG i #with decremented polyn.'s coefficients
J07 GTO X
S01 LBL S #start-routine
S05 XEQ E
I01 LBL I #coefficient input-routine
I06 GTO X
R01 LBL R #we found a root
STO sub N
VIEW N #number of roots, what we dont found yet
x<>0? #more root?
GTO D #go decrement order, and solve again
SF 1 #no more root, and all was REAL: set flag 1
'add', 'sub', 'mul' and 'div' mean 'add', 'substract', 'multiply' and 'divide' in this order.
E:CK=0BE8 27.5 byte
P:CK=E452 3.0 byte
H:CK=3E78 9.0 byte
X:CK=3894 7.5 byte
D:CK=11DF 3.0 byte
J:CK=C765 10.5 byte
S:CK=BB8E 7.5 byte
I:CK=32B5 9.0 byte
R:CK=E775 15.0 byte
solve this polynom with this program:
-2*x^6 -6*x^5 +82*x^4 +174*x^3 -800*x^2 -888*x +1440 =0
A*X^6 +B*X^5 +C*X^4 +D*X^3 +E*X^2 +F*X +G=0
In the program the coefficients are A, B, C, ... The limit of order N=12, because the 14th variable is N, and we use this variable for the order of solved polynom. If you replace it with Z, you can solve the 24th order of polynomials. And it's not a joke...
Now, start the program: [XEQ S] the calc prompting for order of polynom:
N? type 6 [R/S].
Then the program prompts for all of coefficients, type it in decrease order:
A? -2 [R/S]
B? -6 [R/S]
C? 82 [R/S]
D? 174 [R/S]
E? -800 [R/S]
F? -888 [R/S]
G? 1440 [R/S]
Then you will see the 'RUNNING/SOLVING' message, and the program stops with one of six roots: for example X=1. Press [R/S], and you'll see N=5 this mean, the polynom's got 5 root yet. Press [R/S] and repeat this method until all of roots founded.
When N=0 press [R/S], the 'flag1' anunciator set and program end. 'flag1' set mean, all of roots was real.
This polynom got 6 real roots: 1, -2, 3, -4, 5, -6, and the simplyfied form is: -2*(x-1)*(x+2)*(x-3)*(x+4)*(x-5)*(x+6)
I hope it help to you and anybody, who want to solve polynomials. The roots are 'more exacts' if the round off error is not a very big.