Showing posts with label monic quadratic equation. Show all posts
Showing posts with label monic quadratic equation. Show all posts

Saturday, August 1, 2026

DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues

DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues




The programs are listed for the Swiss Micros DM42 and Hewlett Packard 42S.



All examples are on rounded to four decimal places and complex mode turned on (CPXRES).



Monic Quadratic Equation: quad2.raw



The program QUAD2 solves the equation for w:

w² + Y * w + X = 0

Y: contents of stack Y

X: contents of stack X



Code:

00 { 35-Byte Prgm }

01▸LBL "QUAD2"

02 X<>Y

03 ENTER

04 2

05 ÷

06 +/-

07 ENTER

08 X↑2

09 X<>Y

10 R↓

11 X<>Y

12 -

13 SQRT

14 R↑

15 X<>Y

16 ENTER

17 ENTER

18 R↑

19 ENTER

20 R↓

21 X<>Y

22 +

23 R↓

24 -

25 R↑

26 RTN

27 .END.



Example 1: w² + 7 * w + 5 = 0

Stack: Y: 7, X: 5

Results: -6.1926, -0.8074



Example 2: w² – 4 = 0

Stack: Y: 0, X: -4

Results: -2.0000, 2.0000



Characteristic Polynomial: char2.raw



The program CHAR2 find the coefficients of 2 x 2 matrix:

[ [ A, B ] [ C , D ] ]

Result: λ² – T1 * λ + T2 = 0 where

T1 = A + D

T2 = det([[ A, B ] [ C, D ]]) = A * D – C * B



The program provides prompts and results in messages.



Code:

00 { 81-Byte Prgm }

01▸LBL "CHAR2"

02 "[[A,B][C,D]]"

03 AVIEW

04 PSE

05 PSE

06 "L↑2-T1×L+T2=0"

07 AVIEW

08 PSE

09 PSE

10 INPUT "A"

11 ENTER

12 ENTER

13 INPUT "D"

14 ENTER

15 R↓

16 +

17 "T1= "

18 ARCL ST X

19 AVIEW

20 STOP

21 R↓

22 ×

23 INPUT "C"

24 INPUT "B"

25 ×

26 -

27 "T2= "

28 ARCL ST X

29 AVIEW

30 RTN

31 .END.



Example 1: [ [ -6, 4 ] [ 2, 3 ] ]

Results: T1: 3, T2: -26



Example 2: [ [ 5, 8 ] [ -1, 2 ] ]

Results: T1: 7, T2: 18



Eigenvalues of 2 x 2 Matrices: egn2.raw



The program EGNV2 calculates the eigenvalues of a 2 x 2 matrix:

[ [ A, B ] [ C , D ] ]



The program provides prompts and results in messages. The command CPXRES sets the calculator to accept complex number results.



Code:

00 { 106-Byte Prgm }

01▸LBL "EGNV2"

02 CPXRES

03 "[[A,B][C,D]]"

04 AVIEW

05 PSE

06 PSE

07 INPUT "A"

08 INPUT "B"

09 INPUT "C"

10 INPUT "D"

11 RCL "A"

12 RCL "D"

13 +

14 +/-

15 RCL "A"

16 RCL "D"

17 ×

18 RCL "B"

19 RCL "C"

20 ×

21 -

22 X<>Y

23 ENTER

24 2

25 ÷

26 +/-

27 ENTER

28 X↑2

29 X<>Y

30 R↓

31 X<>Y

32 -

33 SQRT

34 R↑

35 X<>Y

36 ENTER

37 ENTER

38 R↑

39 ENTER

40 R↓

41 X<>Y

42 +

43 "E1="

44 ARCL ST X

45 AVIEW

46 PSE

47 PSE

48 R↓

49 -

50 "E2="

51 ARCL ST X

52 AVIEW

53 PSE

54 PSE

55 R↑

56 RTN

57 .END.



Example 1: [ [ -6, 4 ] [ 2, 3 ] ]

Results: 3.8151, - 6.8151



Example 2: [ [ 5, 8 ] [ -1, 2 ] ]

Results: 3.5 ± 2.37792 i


You can download the three programs here: https://drive.google.com/file/d/1SKcVIhKYHnnuhrvBJxfOmwsV8sRTSj0X/view?usp=sharing





Eddie


All original content copyright, © 2011-2026. 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.

DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues

DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues The programs are listed for the Swiss Micros DM42 an...