Generating a Polynomial Given Its Roots
|
12-17-2018, 02:50 AM
Post: #1
|
|||
|
|||
Generating a Polynomial Given Its Roots
Generate the coefficients of a polynomial (up to the order 4) with the roots a_0, a_1, a_2, and a_3. The resulting polynomial is:
p(x) = (x - a_0) * (x - a_1) * (x - a_2) * (x - a_3) * (x - a_4) p(x) = r_4 * x^4 + r_5 * x^3 + r_6 * x^2 + r_7 * x + r_8 The default is a polynomial where the lead coefficient is positive. If you want a polynomial where the lead coefficient is negative, multiply every coefficient by -1. Instructions Store the four roots in registers R00, R01, R02, and R03 respectively. Run POLY4. Coefficients are shown briefly as they are calculated. They are can be recalled by the registers in decreasing order of x: R04, R05, R06, R07, and R08. DM 41L and HP 41C Program: POLY4 Code:
Example Roots x = -3, x = 3, x= 4, and x= 6 Coefficients: R04 = 1 R05 = -10 R06 = 15 R07 = 90 R08 = -216 Polynomial: p(x) = x^4 - 10 * x^3 + 15 * x^2 + 90 * x - 216 Blog post: https://edspi31415.blogspot.com/2018/12/...omial.html |
|||
12-22-2018, 11:44 PM
Post: #2
|
|||
|
|||
RE: Generating a Polynomial Given Its Roots
Your post and code is very interesting!! I am working on a version that will build polynomials up to order of 19. I have tested the code using Excel VBA. Next is coding the program for HP-41CX. I may also write a version for HP-71B.
Namir |
|||
12-23-2018, 08:15 AM
(This post was last modified: 12-23-2018 09:28 AM by Thomas Klemm.)
Post: #3
|
|||
|
|||
RE: Generating a Polynomial Given Its Roots
If you really only want to do that up to order 4 you can use:
Code: LBL "POLY4" Example: CLRG -3 XEQ "POLY4" 3 R/S 4 R/S 6 R/S The coefficients of the polynomial can then be found in the registers: R 00: -10.0000 R 01: 15.0000 R 02: 90.0000 R 03: -216.0000 But we can do better than loop unrolling and use for the general case: Code: 01 LBL "POLY" Example: CLRG CLST -3 XEQ "POLY" 3 R/S 4 R/S 6 R/S The coefficients of the polynomial can again be found in the registers: R 00: -10.0000 R 01: 15.0000 R 02: 90.0000 R 03: -216.0000 In both cases the leading coefficient is always 1. Cheers Thomas |
|||
12-23-2018, 02:11 PM
(This post was last modified: 12-23-2018 09:56 PM by Namir.)
Post: #4
|
|||
|
|||
RE: Generating a Polynomial Given Its Roots
Here is my version of the HP-41C program that can handle up to 19 roots.
The code basically implements repeatedly multiplying a polynomial with a simple 1st degree polynomial. The initial form of the polynomial is also a simple first degree polynomial. As you enter more roots, the degree of the polynomial increases. Code:
Run the program by executing XEQ "POLY" (you can instead press the key [A] when you are inside the program POLY): 1) The first prompt will ask you for the first root. Enter a root. 2) Subsequent prompts will ask you for additional roots OR to enter 0 when you are done. 3) The program displays the coefficients of the polynomial starting with the coefficient of the highest term. Press [R/S] to view the next coefficient of the sequentially lower term. When you have viewed all of the coefficients, the program displays END. Inspect the value in register 41 to view the degree of the resulting polynomial. Enjoy! |
|||
12-23-2018, 03:19 PM
Post: #5
|
|||
|
|||
RE: Generating a Polynomial Given Its Roots
Here's the program adapted for the HP-11C:
Code: 001-42,21,11 LBL A Example: CLEAR REG CLx STO I -3 A 3 R/S 4 R/S 6 R/S The coefficients of the polynomial can be found in the registers: R 0: -10.0000 R 1: 15.0000 R 2: 90.0000 R 3: -216.0000 Here as well the leading coefficient is always 1. Cheers Thomas |
|||
12-23-2018, 07:41 PM
Post: #6
|
|||
|
|||
RE: Generating a Polynomial Given Its Roots
(12-22-2018 11:44 PM)Namir Wrote: Your post and code is very interesting!! I am working on a version that will build polynomials up to order of 19. I have tested the code using Excel VBA. Next is coding the program for HP-41CX. I may also write a version for HP-71B. Thank you! I love your work. |
|||
12-23-2018, 09:12 PM
Post: #7
|
|||
|
|||
RE: Generating a Polynomial Given Its Roots
You have a fantastic web site too!!!
Namir |
|||
12-23-2018, 09:57 PM
Post: #8
|
|||
|
|||
RE: Generating a Polynomial Given Its Roots
I added pseudo-code to my original post.
Namir |
|||
12-26-2018, 12:09 AM
(This post was last modified: 12-26-2018 03:52 AM by Namir.)
Post: #9
|
|||
|
|||
RE: Generating a Polynomial Given Its Roots
As I promised, here is the HP-71B version of the program. The DATA statement contain the number of roots, followed by the list of roots. This data can appear on one or more DATA statements. Run the program to view the coefficients along with their associated power of X:
Code: 10 REM POLY COEFFS FROM ROOTS |
|||
12-27-2018, 10:35 PM
Post: #10
|
|||
|
|||
RE: Generating a Polynomial Given Its Roots
(12-26-2018 12:09 AM)Namir Wrote: As I promised, here is the HP-71B version of the program. I was a bit surprised that the HP-71B is missing the PCOEF command of the HP-48G: [-3 3 4 6] PCOEF [ 1 -10 15 90 -216 ] Quote: The DATA statement contain the number of roots, followed by the list of roots. So we have to modify the program for every new set of data? That's not very practical. Cheers Thomas |
|||
12-28-2018, 07:20 AM
Post: #11
|
|||
|
|||
RE: Generating a Polynomial Given Its Roots
(12-27-2018 10:35 PM)Thomas Klemm Wrote:(12-26-2018 12:09 AM)Namir Wrote: As I promised, here is the HP-71B version of the program. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 5 Guest(s)