Polynomial Ops Program
|
01-01-2014, 03:01 PM
(This post was last modified: 01-14-2014 01:32 PM by Namir.)
Post: #1
|
|||
|
|||
Polynomial Ops Program
Polynomial Operations
This program supports the following polynomial operations: 1) Input and viewing of polynomial coefficients. 2) Calculating polynomial value at scalar X. 3) Calculating polynomial's first derivative at scalar X. 4) Calculating polynomial's second derivative at scalar X. 5) Calculating definite integrals for polynomials. 6) Calculating real polynomial roots using Newton's method. 7) Deflating a polynomial. 8) REplacing the original polynomial with its deflated version. I included a ZIP file with a .raw file that contains the programs. You can load it into an HP-41C emulator that accepts .raw files. Synthetic Division P(x) = a0 + a1*X + a2*X^2 + ... + an*X^N Q(x) = (x-X0)(b0 + b1*X + b2*X^2 + ... + b<n-1>*X^N-1) + R Where: b<n-1> = a<n> b<k> = b<k+1> * X0 + a<k+1> for k = N-2, N-3,...,1,0 R = b0*X0 + a0 Polynomial Derivatives P'(X) = a1 + 2*a2*X + 3*a3*X^2 + ... + N*a<n>*X^N-1 P''(X) = 2*a2 + 6*a3*X + 12*a4*X^2 + ... + N*(N-1)*a<n>*X^N-2 Polynomial Integrals T(X) = Integeral(P(X),A,B) = a0*(B-A) + a1*(B^2-A^2)/2 + a2*(B^3-A^3)/3 + ... + a<n>*(B^(N+1)-A^(N+1))/(N+1) Real Polynomial Roots Root of polynomial uses Newton's method: Xnew = X - P(X) / P'(X) Memory Map R00 = N R01 = X0, counter R02 = index for a() = 10 + (n+10)/1000 or n+10 + 10/1000 R03 = index for b() = n+11 + (2n+10)/1000 or 2n+10 + (n+11)/1000 R04 = X, A R05 = Power of X, B R06 = Sum R07 = Power R08 = counter, X R09 = tolerance R10 = a(0) R11 = a(1) ... Rn+10 = a(n) Rn+11 = b(0) Rn+12 = b(1) Rn+13 = b(2) ... Rn-1+n+11 = R2n+10 = b(n-1) Flag 0 = Set means deflated polynomial exist. Flag 01 - used by root-seeking routine to calculate P(X) Flag 02 - used Listing Code: 1 LBL "POLY1" Usage 1) To enter the coefficients a(), press [A]. The program displays the polynomial order and then the value of the coefficients. To change any of these values, enter a new value. Otherwise, press [R/S] to view/edit the next value. 2) To deflate the polynomial P(x), press {B}. The program will prompt you for X0 and then display the coefficients b() of the deflated polynomial Q(x). 3) To calculate P(X), press [C]. The program prompt you for X and then calculate P(X). 4) To calculate P'(X) press [f][C]. The program prompt you for X and then calculate P'(X). 5) To calculate P''(X) press [f][D]. The program prompt you for X and then calculate P''(X). 6) To calculate the integral of P(X) press [f][E]. The program prompt you for integral range [A, B] and then calculate the integral of P(X). 7) To calculate Q(X), press [D]. The program prompt you for X and then calculate Q(X). 8) To replace P(x) with Q(x), press [E]. 9) To calculate a polynomial root, press [f][A]. The program prompts you to enter a guess and a tolerance value. The program assigns a maximum of 50 iterations. The program displays intermediate guess values for the root. If the program finds a real root it displays "RT=<root_value>" NOTE I am using B in curly braces instead of square brackets to mean the button B, because this web sites interprets B in square brackets as a directive to display bold text. Examples Input of Coefficients for P(X) Enter the following polynomial (with N=3) by pressing [A]: P(X) = X^3 - 6*X^2 + 11*X - 6 Values of P(X) Press [C] to enter any a value for X to calculate P(X). Here is a table of values: Code: X P(X) Values of P'(X) The first derivative of P(X) is: P'(X) 3*X^2 - 12*X + 11 Press [f][C] to enter any a value for X to calculate P'(X). Here is a table of values: Code: X P(X) Values of P''(X) The second derivative of P(X) is: P''(X) = 6*X - 12 Press [f][D] to enter any a value for X to calculate P''(X). Here is a table of values: Code: X P''(X) Values of Definite Integrals Press [f][E] to calculate the integral of P(X) between two points. Here is a table of values: Code: A B Integral Roots of P(X) Press [f][A] to calculate a real root near a guess you provide. The initial guess of X=4 yields the root of 3. Similarly an initial guess of X=0 yields the root 1. Deflating and Replacing P(X) Deflating P(X) with X0=1 yields: Q(X) = X^2 - 5*X + 6 and R=0, since the value of 1 is a real root of P(X) Press {B} and enter 1 for the "X0?" prompt. The program displays the above coefficients for Q(X). Press [E] to replace P(X) with Q(X). You can verify the new coefficients of P(X) by pressing [A} and viewing the new polynomial order and coefficients. |
|||
01-01-2014, 05:50 PM
(This post was last modified: 01-01-2014 06:10 PM by Thomas Klemm.)
Post: #2
|
|||
|
|||
RE: Polynomial Ops Program
Quote:2) To deflate the polynomial P(x), press [B]. The program will prompt you for X0 and then display the coefficients b() of the deflated polynomial Q(x). It appears that [B] gets interpreted as tag for bold. But I haven't figured out yet how to correctly escape that. Cheers Thomas |
|||
01-01-2014, 07:34 PM
Post: #3
|
|||
|
|||
RE: Polynomial Ops Program
I updated the text based on your note, using {B} instead of B in teh square brackets. I also added a note about this issue.
Thanks! |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)