Showing posts with label roots. Show all posts
Showing posts with label roots. Show all posts

Saturday, November 1, 2025

fx-3650P and TI-68: Quadratic Equation and Arc Length between Roots of a Quadratic Curve

fx-3650P and TI-68: Quadratic Equation and Arc Length between Roots of a Quadratic Curve


Two approaches using two well-liked, classic calculators. The fx-3650P uses Basic like language while the TI-68 handles formulas.



Quadratic Equation


Solve for A x^2 + B x + C = 0, with the discriminant D = B^2 – 4 * A * C.


We know the solutions: X = (-B ± √(B² – 4 * A * C)) / (2 * A)


fx-3650P Program

? → A : ? → B : ? → C :

B² – 4 A C → D ◢

-B ÷ ( 2 A ) → M :

√ ( √ ( D² ) ) ÷ ( 2 A ) → Y :

D ≥ 0 ⇒ Goto 1 : M ◢ Y ◢ Goto 2 :

Lbl 1 : M + Y → X ◢ M – Y → Y ◢ Lbl 2


D: discriminant

If D<0; roots are in the form of M ± Yi

Else, the roots are real and are stored in X, Y


TI-68 Formula


X = 0 × A + (-B + √(B² – 4 × C × A) × J) ÷ (2 × A)


The 0 × A is added to force A to be prompted for first.

J = -1 for one root, J = 1 for the other

TI-68 takes care of both real and complex roots, no worries.

The coefficients can be complex!


Examples

A

B

C

D

Roots

2

-3

-9

81

3, -1.5

1

0

25

-100

5i, -5i

-48

64

28

9472

-0.347127088, 1.680464022



Arc Length of a Quadratic Equation between its Real Roots


Give roots X, Y: (t – X) * (t – Y) = t^2 – (X + Y )* t + X * Y

f(t) = t^2 – (X + Y) * t + X * Y

f’(t) = 2 * t – (X + Y)

arc = ∫( √(1 + f’(t)^2) dt


TI-68 will set up for the outside integral function, while the fx-3650P can use the integral function inside of the program.


We are going to assume that X < Y.


fx-3650P Program

? → A : ? → B : ∫ ( √ (1 + (2 X – A – B) ² ), A, B)


This is the direct approach.


TI-68 Formula

ARC = √(1 + (2 × X – A – B)²)


for X use the integral function (dx)

[ 3rd ] [ Σ+ ] (dx) [ = ]

Enter low, high, and the number of intervals.

The more intervals, generally, the more accurate the integral is.


Examples

I compared results against the fx-991CW.


A

B

TI-68, intv = 16

fx-3650P

fx-991 CW

2

9

26.070832160

26.070800000

26.070797720

0

5

13.903768900

13.904000000

13.903767950

-2

2

9.293567375

9.293568000

9.293567525



Eddie

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


The author does not use AI engines and never will.


Saturday, September 16, 2023

Integrating Absolute Value Functions

Integrating Absolute Value Functions



Calculating ∫ abs(f(x)) dx


The function abs(f(x)) can be broken into two parts, depending on the sign of f(x):


abs(f(x)) = 

{   f(x)  when f(x) > 0

{  -f(x)  when f(x) < 0



General procedure:


1.  Find the roots of f(x).  

2.  Split the integral at the roots.

3.  For areas where f(x)>0, calculate the sub-area ∫ f(x) dx.

4.  For areas where f(x)<0, calculate the sub-area ∫ -f(x) dx.

5.  Total all the sub-areas.



Let's illustrate this with examples.  Screen shots are made with the HP Prime emulator.  The absolute value function |f(x)| is graphed in blue, while f(x) is graphed in red (for illustrative purposes).  



Example 1:  ∫ |4x- 2| dx from x = 0 to x = 5





∫ |4x- 2| dx from x = 0 to x =5


The root of (4x - 2) is x = 1/2.     

When x < 1/2, (4x - 2) < 0.   

When x > 1/2, (4x - 2) > 0.


Break down the integral into:


∫ (|4x- 2| dx from x = 0 to x =5)

= ∫ ( -(4x- 2) dx from x = 0 to x =1/2) + ∫ (4x- 2 dx from x = 1/2 to x =5)

=  1/2 + 81/2

=  82/2

=  41


We can type in the entire integral into a calculator or app.  Depending on the function and the advanced engine of the calculator, the accuracy may be affected.   Calculators and apps with advanced engines include the HP Prime, Wolfram Alpha, and Desmos.   (Your mileage may vary)



Example 2:  ∫ |x^3 - 28x + 48| dx from x = 0 to x = 3





∫ |x^3 - 28x + 48| dx from x = 0 to x = 3


The roots of x^3 - 28x + 48 are at x = -6, x = 2, and x = 4.   Since the root x = 2 is the only root in the interval [0, 3], this is the one root we are working with.  


With root x = 2, 

When x < 2, x^3 - 28x + 48 > 0

When x > 2, x^3 - 28x + 48 < 0


Then:

∫ ( |x^3 - 28x + 48| dx from x = 0 to x = 3 ) 

= ∫ ( (x^3 - 28x + 48) dx from x = 0 to x = 2 ) 

+ ∫ ( -(x^3 - 28x + 48) dx from x = 2 to x = 3 ) 

= 44 + 5.75

= 49.75



Example 3:  ∫ |e^(2x) - 2| dx from x = 0 to x = 2





The root of e^(2x) - 2 is x = ln 2 ÷ 2 ≈ 0.34657


Let A = ln 2 ÷ 2, and with root x = A,

When x < A, e^(2x) - 2 < 0

When x > A, e^(2x) - 2 > 0


∫ ( |e^(2x) - 2| dx from x = 0 to x = 2 )

=  ∫ ( -(e^(2x) - 2) dx from x = 0 to x = A ) + ∫( (e^(2x) - 2) dx from x = A to x = 2)

≈ 0.193147 + 22.99222

≈ 23.18537


Where is where this method returns approximates and using different calculators and apps may not produce the same results.  


HP Prime:  23.1853693777

Desmos:  23.1853693777

Wolfram Alpha:  23.1853693776920

TI-30X Pro MathPrint:  23.18537052



Hope this technique helps, 


Eddie



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


Saturday, May 14, 2022

The Sum and Product of Roots of a Quadratic Equation

The Sum and Product of Roots of a Quadratic Equation


Introduction


Let s, t be the roots of the equation a*x^2 + b*x + c = 0.


Let:


s = (-b + √(b^2 - 4*a*c)) / (2 * a)

t = (-b - √(b^2 - 4*a*c)) / (2 * a)


Then


s + t = -b / a

s * t = c / a


We see this topic a lot in algebra, let's see how these properties are derived. Fairly simple.  


Sum of the Roots


s + t

=  (-b + √(b^2 - 4*a*c)) / (2 * a) + (-b - √(b^2 - 4*a*c)) / (2 * a)

= (-2 * b) / (2 * a)

= -b / a


Product of the Roots


s * t 

=  (-b + √(b^2 - 4*a*c)) / (2 * a) * (-b - √(b^2 - 4*a*c)) / (2 * a)

= (b^2 + b * √(b^2 - 4*a*c) - b * √(b^2 - 4*a*c) - (b^2 - 4*a*c)) / (4*a^2)

= (b^2 - b^2 + 4*a*c) / (4*a^2)

= (4*a*c) / (4*a^2)



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. 


Monday, February 17, 2020

Retro Review: TI-30 (1976)

Retro Review:  TI-30 (1976) 

One more quick blog posts before I head off into surgery this week.






Quick Facts

Model:  TI-30
Company:  Texas Instruments
Type:  Scientific
Years:  1976-1982
Display:  8 digits, 5 digits with 2 digit 10^xx in scientific notation, red LED lights
Batteries:  Battery, 9 V
Original Retail Price:  $24.95
Logic:  AOS (Algebraic)

History

The TI-30 is one of the first scientific calculators to cost less than $50.00 retail, making one of the first scientific calculators to be sold to a wide audience.

The TI-30 model name is carried to present day, with the latest incarnation being the TI-30xa with a gray keyboard and wide digit display.

TI-30 from 1976 (left), TI-30Xa from 2015 (right)
Features

The first TI-30 is a simple, basic scientific calculator.  It's features include:

*  Trigonometric functions and inverse
*  Logarithmic functions and inverse
*  Powers and Roots
*  Parenthesis
*  One memory register with sum and exchange commands
*  Arithmetic, percent, reciprocal

There is a DRG key where it cycles through Degrees mode, Radians mode (indicator of I), and Gradians mode (indicator of II).

Buyers had an option of purchasing one of three carrying pouches to carry the TI-30.  The one I purchased on eBay had a denim carrying pouch and it's really nice!

The display had a few indicators which was pretty advance for its time:

When a calculation is in progress, the right-most digit displays a "twirling eight".

If an error occurs, the word "Error." is spelled out.

If the calculator is left on for a few seconds, it goes into a screen saver mode.  The screen saver has a decimal point scrolling across the screen left to right.  This is designed to save battery usage.

The TI-30 also had a power adapter, I would imagine that those would be hard to find today. 

Keyboard

I am very pleased with the keyboard:  the keys are well maintained.  The keys are easy to press.  The LED screen is clear and easy to read.  The keys are responsive, don't just try to be a speed typist and everything will be fine.  The calculator is nice and lightweight.

The only thing I had a hard time with was trying to attach the 9-V battery and closing the case.

Verdict

I'd say yes; if you are a calculator collector, it is worth collecting, even if it is only historic value.  It also doesn't cost too much, I paid $17 for mine. 

Routine Goodies

Absolute Value:  | n |
n  [ x^2 ] [ √x ]

Sign:  sgn(n) = -1 for negative, 1 for positive (does not work for n = 0)
n [ STO ] [ * ] [ x^2 ] [ √x ] [ ÷ ] [ RCL ] [ = ]

Modulus:  n mod m  with n > m, n > 0, m > 0.
n [ ÷ ] m [ STO ] [ = ] [ - ] (integer part of the result) [ = ] [ * ] [ RCL ] [ = ]

Convert to Scientific Notation:
[ * ] 1 [ EE ] [ = ]

Convert to Floating Numbers:
[ * ] 1 [ INV ] [ EE ] [ = ]

The next blog post will be on March 7, 2020.  Take care!

Eddie

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

Tuesday, March 19, 2019

Algebra: Solving Simple Non-Linear Systems

Algebra: Solving Simple Non-Linear Systems




System I:  

x + y = a
x^2 + y = b

Solving for y:
x + y = a
y = a - x

Subtracting the two equations from the system:
x + y = a
- [x^2 + y] = -[ b ]

x - x^2 = a - b
x^2 - x = b - a
x^2 - x - (b - a) = 0

Solving for x:
x = ( 1 ± √(1 - 4*(b - a) ) / 2

Summary for System I:
x = ( 1 ± √(1 - 4*(b - a) ) / 2
y = a - x

If a and b are real numbers, then 1 - 4*(b - a) ≥ 0, and
1 ≥ 4*(b - a)

System II:

x + y = a
x + y^2 = b

Solving for x:
x + y = a
x  = a - y

Subtracting the two equations from the system:
x + y = a
- [ x + y^2 ] = -[ b ]

y - y^2 = a - b
y^2 - y = b - a
y^2 - y - (b - a) = 0

Solving for y:
y = ( 1 ± √(1 - 4*(b - a) )/2

Summary for System II:
x  = a - y
y = ( 1 ± √(1 - 4*(b - a) )/2

System III:

x + y = a
x^2 + y^2 = b

Solving for y:
y = a - x

Solving for x:
x^2 + (a - x)^2 = b
x^2 + a^2 - 2*a*x + x^2 = b
2*x^2 - 2*a*x + (a^2 - b) = 0

x = ( 2*a ± √(4*a^2 - 4*2*(a^2 - b) ) / 4
x = ( 2*a ± √(4*a^2 - 8*(a^2 - b) ) / 4
x = ( 2*a ± √(4*a^2 - 8*a^2 + 8*b) ) / 4
x = ( 2*a ± √(8*b - 4*a^2) ) / 4
x = ( a ± √(2*b - a^2) ) / 2

Summary for System III:
x = ( a ± √(2*b - a^2) ) / 2
y = a - x

System IV:

x^2 + y^2 = a
x * y = b

Solving for y:
y = b / x 

I'm assuming that x ≠0 and y ≠0.

x^2 + y^2 = a
x^2 + (b / x)^2 = a
x^4 + b^2 = a * x^2
x^2 - a * x^2 + b^2 = 0

Let w = x^2, then w^2 = x^4

Then:
w^2 - a*w + b^2 = 0

Then:
w = (a ± √(a^2 - 4 * b^2) )/ 2

And:
x = ± √( (a ± √(a^2 - 4 * b^2) )/ 2 )

We have four answers to the system.

Summary for System IV:
x = ± √( (a ± √(a^2 - 4 * b^2) )/ 2 )
y = b / x 

A lot of fun,

Eddie

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

Sunday, December 16, 2018

DM 41L and HP 41C: Generating a Polynomial Given Its Roots

DM 41L and HP 41C:  Generating a Polynomial Given Its Roots

Introduction

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

01  LBL^T POLY4
02 1
03 STO 04
04 PSE 
05 RCL 00
06 CHS
07 RCL 01
08 -
09 RCL 02
10 -
11 RCL 03
12 -
13 STO 05
14 PSE
15 RCL 01
16 RCL 02
17 +
18 RCL 03
19 +
20 RCL 00
21 * 
22 RCL 02
23 RCL 03
24 +
25 RCL 01
26 *
27 +
28 RCL 02
29 RCL 03
30 *
31 +
32 STO 06
33 PSE
34 RCL 01
35 RCL 02
36 *
37 RCL 01
38 RCL 03
39 *
40 +
41 RCL 02
42 RCL 03
43 *
44 +
45 RCL 00
46 *
47 CHS
48 RCL 01
49 RCL 02
50 *
51 RCL 03
52 *
53 -
54 STO 07
55 PSE
56 RCL 00
57 RCL 01
58 *
59 RCL 02
60 *
61 RCL 03
62 *
63 STO 08
64 RTN

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

Eddie

All original content copyright, © 2011-2018.  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.  Please contact the author if you have questions.

Saturday, December 15, 2018

DM 41L and HP 41C: Schur-Cohn Algorithm

DM 41L and HP 41C:  Schur-Cohn Algorithm

Introduction

The Schur-Cohn Algorithm tests whether the roots of a polynomial p(x) lies with in the unit circle.  That is for the polynomial p(x):

p(x) = a_0 * x^n + a_1 * x^(n - 1) + a_2 * x^(n - 2) + ... + a_n

For all the roots of p(x), r_0, r_1, r_2, ... , r_n ,   |r_k| < 1.    The test covers both real and complex roots.  Keep in mind that this test doesn't tell us what the roots are, only a clue to whether the roots lie in the unit circle or not.

The Schur-Cohn Algorithm returns the test answers b_0, b_1, etc.  If |b_k| < 1 holds true for each b_k for k = 0 to n, then we can conclude that |r_k| <  1.

The following program is adopted from Peter Henrici's book Computational Analysis With the HP-25 Pocket Calculator [Henrici, 111] for the HP 41C and the Swiss Micros DM 41L.  The program deals with polynomials up to the fourth order, but can be expanded on an RPN calculator with more program space and memory registers.

Instructions:

For the fourth order polynomial:

p(x) = a_0 * x^4 + a_1 * x^3 + a_2 * x^2 + a_1 * x + a_4

To the coefficients in the following registers:

R00 = a_0
R01 = a_1
R02 = a_2
R03 = a_3
R04 = a_4

The test results will pop momentarily during execution.  The program is done when after four test values, 4 is in the display.  The last test value is stored in R05.

DM 41L and HP 41C Program:  SCHUR (77 bytes, 11 registers of memory) 

01  LBL^T SCHUR
02  CLX
03  STO 07
04  LBL 03
05  STO 06
06  RCL 04
07  RCL 00 
08  /
09  STO 05    
10 PSE   // show test values
11 RCL 04
12  *
13 ST- 00
14 RCL 01
15 RCL 02
16 RCL 03
17 LBL 15
18 RCL 06
19 X=0?
20 GTO 24
21 RDN   // R↓
22 RCL 04
23 1
24 ST- 06
25 RDN
26 GTO 15
27 LBL 24
28 RDN
29 RCL 05
30 *
31 ST- 01
32 RDN
33 RCL 05
34 *
35 ST- 02
36 RDN
37 RCL 05
38  *
39 ST- 03
40 RCL 03
41 STO 04
42 RCL 02
43 STO 03
44 RCL 01
45 STO 02
46 RCL 00
47 STO 01
48 1
49 ST+ 07
50 4
51 RCL 07
52 X
53 GTO 03

Example

p(x) = 20 * x^4 - 16 * x^3 - 2 * x^2 + 2.08 * x + 0.21

Store the following values:
R0 = 20
R1 = -16
R2 = -2
R3 = 2.08
R4 = 0.21

Test Values:
0.0105
0.1124
-0.0090
-0.8074

For the record the roots of p(x) are 0.5, -0.1, 0.7, and -0.3.

This blog entry is not for use for commercial purposes.

Source:

Henrici, Peter.  Computational Analysis With the HP-25 Calculator  A Wiley-Interscience Publication. John Wiley & Sons: New York 1977 .  ISBN 0-471-02938-6

Eddie

Tuesday, January 16, 2018

TI-74: Extrema of a Cubic Polynomial

TI-74: Extrema of a Cubic Polynomial

Introduction

The program finds the extrema points of a cubic polynomial where the roots A, B, and C are known.  The cubic polynomial is defined as:

y = (x – A) * (x – B) * (x – C)




Expanded to:

y = x^3 – (A + B + C)*x^2 + (A*B + B*C + A*C)*x – (A*B*C)

The extrema can be found by taking the derivative and then solving for x when dy/dx=0.

dy/dx = 3*x^2 – 2*(A + B + C)*x + (A*B + B*C + A*C) = 0

Solving for x:

x = (2*W ± √(4*W^2 – 12*V))/6

Where:

W = A + B + C
V = A*B + A*C + B*C

TI-74 Program: Extrema of Cubic Polynomials

100 PRINT “y=(x-a)(x-b)(x-c)”: PAUSE 1
110 INPUT “a: “;A
112 INPUT “b: “;B
114 INPUT “c: “;C
120 W=A+B+C
122 V=A*B+A*C+B*C
130 X1=(2*W+SQR(4*W^2-12*V))/6
132 X2=(2*W-SQR(4*W^2-12*V))/6
140 Y1=(X1-A)*(X1-B)*(X1-C)
142 Y2=(X2-A)*(X2-B)*(X2-C)
150 IMAGE “######.######, ######.######”
152 PRINT USING 150,X1,Y1: PAUSE
154 PRINT USING 150,X2,Y2: PAUSE
160 END

Example

A = 0, B = 3, C = 5

Results:
4.119633, -4.06067
1.213700, 8.20882

Eddie


This blog is property of Edward Shore, 2018

Thursday, August 21, 2014

Pythonista 2.7 and HP 35S: Given roots of a polynomial, find the coefficients of a polynomial

General

Variables:
Number of Roots: N
Roots: R, S, T, U
Coefficients: A, B, C, D, E

N = 2, roots R and S:
(x - R) * (x - S) → A * x^2 + B * x + C

Formulas:
A = 1
B = -(R + S)
C = R * S

N = 3, roots R, S, and T:
(x - R) * (x - S) * (x - T) → A * x^3 + B * x^2 + C * x + D

Formulas:
A = 1
B = -(R + S + T)
C = R * S + R * T + S * T

N = 4, roots R, S, T, and U:
(x - R) * (x - S) * (x - T) * (x - U) → A * x^4 + B * x^3 + C * x^2 + D * x + E

Formulas:
A = 1
B = -(R + S + T + U)
C = R * S + R * T + R * U + S * T + S * U + T * U
D = -(R * S * T + R * S * U + R * T * U + S * T * U)
E = R * S * T * U


HP-35S: Coefficients To Roots

Program:
C001 LBL C
C002 SF 10 // SF, decimal point, 0
C003 NO OF ROOTS // enter message as an equation
C004 CF 10 // CF, decimal point, 0
C005 INPUT N
C006 4 // error checking
C007 xC008 GTO C113
C009 R-down
C010 2
C011 x>y?
C012 GTO C113
C013 1 // main routine
C014 STO A
C015 INPUT R
C016 INPUT S
C017 RCL N
C018 3
C019 x=y?
C020 GTO C033
C021 R-down
C022 4
C023 x=y?
C024 GTO C054
C025 RCL R // two roots
C026 RCL+ S
C027 +/-
C028 STO B
C029 RCL R
C030 RCLx S
C031 STO C
C032 GTO C101
C033 INPUT T // three roots
C034 RCL R
C035 RCL+ S
C036 RCL+ T
C037 +/-
C038 STO B
C039 RCL R
C040 RCLx S
C041 RCL R
C042 RCLx T
C043 +
C044 RCL S
C045 RCLx T
C046 +
C047 STO C
C048 RCL R
C049 RCLx S
C050 RCLx T
C051 +/-
C052 STO D
C053 GTO C101
C054 INPUT T // four roots
C055 INPUT U
C056 +
C057 RCL+ S
C058 RCL+ R
C059 +/-
C060 STO B
C061 RCL R
C062 RCLx S
C063 RCL R
C064 RCLx T
C065 +
C066 RCL R
C067 RCLx U
C068 +
C069 RCL S
C070 RCLx T
C071 +
C072 RCL S
C073 RCLx U
C074 +
C075 RCL T
C076 RCLx U
C077 +
C078 STO C
C079 RCL R
C080 RCLx S
C081 RCLx T
C082 RCL R
C083 RCLx S
C084 RCLx U
C085 +
C086 RCL R
C087 RCLx T
C088 RCLx U
C089 +
C090 RCL S
C091 RCLx T
C092 RCLx U
C093 +
C094 +/-
C095 STO D
C096 RCL R
C097 RCLx S
C098 RCLx T
C099 RCLx U
C100 STO E
C101 VIEW A // results
C102 VIEW B
C103 VIEW C
C104 RCL N
C105 3
C106 x≤y?
C107 VIEW D
C108 RCL N
C109 4
C110 x=y?
C111 VIEW E
C112 RTN
C113 0 // invoking the error condition
C114 1/x





Pythonista

Input: Enter a vector of coefficients, up to 4 roots
Output: A list of coefficients, in descending order

Note: the triple periods indicate a tab (...)

# let roots be the list of roots, up to 4
# EWS 2014-08-20
import math
roots=input('List of Roots (up to 4):')
n=len(roots)
poly=[1]
# check for order
if n==2:
...# quadratic
...poly.append(-(roots[0]+roots[1]))
...poly.append(roots[0]*roots[1])
...print('List of coefficients: ',poly)
elif n==3:
...# cubic
...temp=-(roots[0]+roots[1]+roots[2])
...poly.append(temp)
...temp=roots[0]*roots[1]+roots[0]*roots[2]+roots[1]*roots[2]
...poly.append(temp)
...temp=-roots[0]*roots[1]*roots[2]
...poly.append(temp)
...print('List of coefficients: ',poly)
elif n==4:
...# quartic
...temp=-(roots[0]+roots[1]+roots[2]+roots[3])
...poly.append(temp)
...temp=roots[0]*roots[1]+roots[0]*roots[2]+roots[0]*roots[3]+roots[1]*roots[2]+roots[1]*roots[3]+roots[2]*roots[3]
...poly.append(temp)
...temp=-(roots[0]*roots[1]*roots[2]+roots[0]*roots[1]*roots[3]+roots[0]*roots[2]*roots[3]+roots[1]*roots[2]*roots[3])
...poly.append(temp)
...temp=roots[0]*roots[1]*roots[2]*roots[3]
...poly.append(temp)
...print('List of Coefficients: ',poly)
else:
...print('Error: not a valid list')


Examples:

Quadratic:
R = 2, S = -4
A = 1, B = 2, C = -8

Cubic:
R = 3, S = -1, T = -3
A = 1, B = 1, C = -9, D = -9

Quartic:
R = 3, S = -1, T = -3, U = 4
A = 1, B = -3, C = -13, D = 27, E = 36

Eddie


This blog is property of Edward Shore. 2014

Python in Numworks: Duplicating and Grayscale

Python in Numworks: Duplicating and Grayscale All three scripts presented today use the math, random, and the Numworks specific ...