Monday, March 21, 2022

Swiss Micros DM42/HP42S: Polynomial Solver

 Swiss Micros DM42/HP42S:  Polynomial Solver


Introduction


The solver PSOL (pmatsolver.raw) uses a two column matrix PMAT to evaluate and solve for polynomials in the form:


p(x) = a1 * x^b1 + a2 * x^b2 + a3 * x^b3 + ...


And PMAT has the matrix in the form of:


[ [ a1,  b1 ],  

[ a2, b2 ], 

[ a3, b3 ] ... ]


The PMAT Matrix


The solver uses the matrix PMAT.  It must first be created in order for the solver to work.


Creating PMAT:    

1.  Enter the number of terms, press [ENTER], type 2, press [(shift)] [ 9 ] (MATRIX), select (NEW).

2.  Select (EDIT) from the MATRIX menu.

3.  Enter the coefficients and powers.   For terms in form of a1, the power is 0.  For terms in form of x^b1, the coefficient is 1.

4.  Press [EXIT], then [STO], [(shift)] [ENTER] (ALPHA), type PMAT.


Editing PMAT:

1.  Enter the number of terms, press [ENTER], type 2, press [(shift)] [ 9 ] (MATRIX), select (DIM), select PMAT.

2.  From the MATRIX menu, select (EDITN), select PMAT.  Be sure to select EDITN (edit named matrix).


Running the Solver


To run the polynomial solver:

1.  Press [(shift)] [ 7 ] (SOLVER), select PSOL.

2.  To evaluate p(x), enter a value for X and solve for P.   

3.  To solve for x, enter a value for P, enter a guess for X, and then press X again to solve.


Note:  The solver cannot evaluate 0^0.  Hopefully you can see why in the program listing.


The best part of PSOL is that you don't have to use just integer powers, put powers in order, or fill in zero terms (0 * x^n).


Examples


Example 1:  p(x) = 2 + 3x^1.5 - x^3


Set PMAT to be this:

[ [ 2, 0 ], 

[ 3, 1.5 ]

[ -1, 3 ] ]


If X = 2.2, solving for P yields 1.141382003

If P = -1, solving for X with guess 0 yields 2.431407988


Example 2:  p(x) = -5 + 3*x + 4*x^2


Set PMAT to be this:

[ [ -5, 0 ],

[ 3, 1 ], 

[ 4, 2 ]]


If X =1.8, solving for P yields 13.36

If P = 10, solving for X with guess 0 yields 1.59746673 



DM42/HP42S (Free42) Solver Program PSOL


00 { 65-Byte Prgm }

01 LBL "PSOL"

02 MVAR "P"

03 MVAR "X"

04 0

05 STO 01

06 INDEX "PMAT"

07 RCL "PMAT"

08 DIM?

09 R↓

10 STO 02

11 LBL 00

12 RCLEL

13 RCL "X"

14 J+

15 RCLEL

16 Y↑X

17 ×

18 STO+ 01

19 RCLIJ

20 R↓

21 RCL 02

22 X=Y?

23 GTO 01

24 J-

25 I+

26 GTO 00

27 LBL 01

28 RCL 01

29 RCL- "P"

30 .END.


Eddie


All original content copyright, © 2011-2022.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Spotlight: Sharp EL-5200

  Spotlight: Sharp EL-5200 As we come on the 13 th (April 16) anniversary of this blog, I want to thank you. Blogging about mathematic...