Solving for the roots of a cubic polynomial
|
06-30-2024, 08:46 PM
(This post was last modified: 07-01-2024 09:47 PM by Namir.)
Post: #1
|
|||
|
|||
Solving for the roots of a cubic polynomial
This is a Free42 printout of an HP-41C program that uses the instructions found on page 75 of the HP-4 Application Book. The program calculates the real and complex roots of a cubic polynomial:
x^3 + a*x^2 + b^x + c = 0 The program prompts you for the coefficients, b, a, and c in that order. The HP-41C adaptation uses labels and flags 00 and 01 to direct the flow of the calculations. The output includes the determinant d and the roots x1, x2, and x3. When the roots are complex the output appears as <real,imaginary>. The listing (revised from HP-42s to HP-41C) is: Code: 01 LBL "CUBE" |
|||
06-30-2024, 11:49 PM
Post: #2
|
|||
|
|||
RE: Solving for the roots of a cubic polynomial
Hi, Namir
x^3 + x^2 = 0, but did not get back roots -1, 0, 0 Instead, I get d=0, X1 = X2 = X3 = -1/3 Try its depressed cubic, with x = y - 1/3 y^3 - y/3 + 2/27 = 0 Sure enough, I get d=0, X1 = X2 = X3 = 0 |
|||
07-01-2024, 04:13 AM
(This post was last modified: 07-01-2024 04:18 AM by Namir.)
Post: #3
|
|||
|
|||
RE: Solving for the roots of a cubic polynomial
(06-30-2024 11:49 PM)Albert Chan Wrote: Hi, Namir I think the HP author of the program assumed that parameter c should not be 0, because in this case the cubic equation s easily reduced to a quadratic or linear equation (as is your example). |
|||
07-01-2024, 06:14 PM
(This post was last modified: 07-02-2024 05:14 PM by Albert Chan.)
Post: #4
|
|||
|
|||
RE: Solving for the roots of a cubic polynomial
(07-01-2024 04:13 AM)Namir Wrote:(06-30-2024 11:49 PM)Albert Chan Wrote: Try its depressed cubic, with x = y - 1/3 Depressed cubic does not look easily reduced to quadratic. Fix should not be hard. Here is the trig solution. |
|||
07-02-2024, 05:36 AM
(This post was last modified: 07-02-2024 05:37 AM by Namir.)
Post: #5
|
|||
|
|||
RE: Solving for the roots of a cubic polynomial
As I mentioned before the original HP-45 key sequence that I translated into HP-41C code seem to have been meant to solve a cubic equation x^3+a*x^2+b*x+c =0, for typical cases where a, b, and c are not zero. You are welcome to enhance the HP-41C code for various combinations of zeros in these three parameters. You can download the HP-45 Application Book from Eric Rechlin's documents web pages and look at pages 74 and 75 to see the equations used and the keystroke sequence. An alternative to all this is to use Lin-Bairstow's algorithm that solves for real and complex roots of polynomials with real coefficients.
|
|||
07-02-2024, 07:57 PM
Post: #6
|
|||
|
|||
RE: Solving for the roots of a cubic polynomial
Hi, Namir
It is not zeros that caused the problem. You could even try x^3 = 0, and it still work. The problem is cube root of negative numbers. (note: all coefficients are real) Code seems to assume first cube root is always positive. 2nd cube root use flag 01 to get sign(x) * ³√|x| This is why y^3 - y/3 + 2/27 = 0 roots are 0 y1 = ³√(-1/27+0) + ³√(-1/27−0), mistakenly calculated as 1/3 - 1/3 = 0 We could reuse flag 01 for both cube roots, or do without. ³√(x) = sign(x) * ³√|x| Note: I only touched cube roots. (LINE 65 .. 71, copy/paste to LINE 76 .. 82) Code: 00 { 281-Byte Prgm } |
|||
07-04-2024, 04:18 AM
Post: #7
|
|||
|
|||
RE: Solving for the roots of a cubic polynomial
Thanks Albert for the updated code.
Namir |
|||
07-04-2024, 05:21 PM
Post: #8
|
|||
|
|||
RE: Solving for the roots of a cubic polynomial
What is the mathematical background? like Page 8 of https://arxiv.org/pdf/2206.03855 ?
HP71B 4TH/ASM/Multimod, HP41CV/X/Y & Nov64d, PILBOX, HP-IL 821.62A & 64A & 66A, Deb11 64b-PC & PI2 3 4 w/ ILPER, VIDEO80, V41 & EMU71, DM41X |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)