HP Forums
(71B) Polynomial Coefficients from a given list of roots -- for the HP-71B - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (71B) Polynomial Coefficients from a given list of roots -- for the HP-71B (/thread-12027.html)



(71B) Polynomial Coefficients from a given list of roots -- for the HP-71B - Namir - 12-26-2018 12:11 AM

Here is an HP-71B program that converts the list of roots into the coefficients of the polynomial that has these roots. The DATA statement(s) 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
20 DIM A(101),C(101)
25 REM DATA NUMBER_OF_ROOTS
30 DATA 3
35 REM DATA STMT HAS LIST OF ROOTS
40 DATA 1,2,3
50 READ M, B
60 A(1) = 1@ C(1) = 1
70 A(2) = -B@ C(2) = -B
80 N = 1
90 FOR K=2 TO M
100 READ B @ B=-B
110 FOR I = 2 TO N + 1
120 C(I) = A(I) + B * A(I - 1)
130 NEXT I
140 C(N + 2) = A(N + 1) * B
150 N = N + 1
160 FOR I = 1 TO N + 1
170 A(I) = C(I)
180 NEXT I
190 NEXT K
195 M = N
200 FOR I=1 TO N
210 DISP A(I);"* X^";M @ WAIT 3
215 M = M - 1
220 NEXT I
230 DISP A(N+1)
240 END



RE: Polynomial Coefficients from a given list of roots -- for the HP-71B - C.Ret - 06-13-2021 03:28 PM

HI,

Here is the same task without DATA/READ structure, only one FOR TO NEXT loop and a more convivial interface for output and input :

10 DESTROY A,D,I,R @ OPTION BASE 0 @ DIM A(29) @ A(0)=1
12 INPUT "Add root x.=";R @ D=D+1
14 FOR I= D TO 0 STEP -1 @ IF I>0 THEN A(I)=A(I-1)-R*A(I) ELSE A(0)=-R*A(0)
16 GOSUB 20 @ NEXT I @ PAUSE @ GOTO 12

20 IF A(I)>0 AND I<D THEN DISP "+"; ELSE IF A(I)<0 THEN DISP "-";
22 IF A(I)=0 THEN RETURN ELSE IF ABS(A(I))#1 OR I=0 THEN DISP STR$(ABS(A(I));
24 IF I<1 THEN RETURN ELSE DISP "x"; @ IF I>1 THEN DISP "^"&STR$(I);
26 RETURN


Usage :
New polynomials coefficients are deduce at each step by multiplying the previous polynomial by (x-r). This increase its degree by one unit (variable D indicate polynomial's degree)
  1. Start the program with [RUN] or any appropriate method.
  2. When prompt, enter value of the root to add and press [END LINE]
  3. The actual polynomial is displayed.
  4. To continue adding a root from step #2, press [f][CONT]
  5. To clear the actual polynomial and restart with a new set of roots, press [RUN]


Example 1:
Code:
>                                 (RUN)
Add root x.=                     1 (END`LINE)
x-1                               (f)(CONT)
Add root x.=                     2 (END`LINE)
x^2-3x+2                          (f)(CONT)
Add root x.=                     3 (END LINE)
x^3-6x^2+11x-6
Example 2:
Code:
x^3-6x^2+11x-6                    (RUN)
Add root x.=                     -1-SQRT(3) (END`LINE)
x+2.73205080757                   (f)(CONT)
Add root x.=                     -1+SQRT(3) (END`LINE)
x^2+2x-2                          (ON)
>_