Page 1 of 1

[Example] Cubic equations and Newton's iteration method

Posted: Wed Sep 17, 2025 7:20 pm
by Lupp
@MrProgrammer:
I didn't thoroughly study your example. Sorry!
But I felt tempted to try a different approach (and wasted a lot of time doing so. Too old brain.)
My approach tries to find a first solution by Newton-iteration which converges rapidly if applcable, and to apply then a division of the x^3-polynom by the linear factor of the first solution leading to a quadratic equation which gives the other real solutions if they exist.
(Cells O5:Q5 of my Sheet3.)
You may be interested, and you can surely tell me how I get remedy if the iteration fails.
My example was made with LibO V 25.8.1.1. It also worked under AOO V 4.1.7.
_playCubicEquationSolver.ods
(48.5 KiB) Downloaded 10 times

Re: Cubic equations (second topic as requested by MrProgrammer for unknown reasons)

Posted: Wed Sep 17, 2025 11:33 pm
by MrProgrammer
Lupp wrote: Wed Sep 17, 2025 7:20 pm I didn't thoroughly study your example.
I didn't attempt to explain in the spreadsheet how it determines the roots, since that is described in detail in the Cubic equation article. I found this material to be quite interesting since it was not presented in any of my college mathematics courses. When the discriminant is zero, the equation has Multiple roots, and the spreadsheet uses the simple expressions for them. When the discriminant is positive, the spreadsheet uses the Trigonometric Solution for three real roots. Otherwise it uses Cardano's formula. I worked on optimizing that method for Calc to handle two difficulties:
• Calc can't evaluate the cube root N^(1/3) when N is negative
• Calc's operators do not support complex numbers
I preferred to do the complex arithmetic with formulas instead of using the IMxxxxx functions.

Lupp wrote: Wed Sep 17, 2025 7:20 pm You can surely tell me how I get remedy if the iteration fails.
The situation seems to be complicated. I don't know of any good method to choose a starting point for Newton's Method which guarantees that the iteration will converge. When it does find a root, the cubic can be reduced to a quadratic and the other two roots are then easy to determine. However that may not happen. I suspect there is a good chance the iteration may not converge when two of the roots are a complex conjugate pair and the starting point is near half of their sum. The spreadsheet below shows Newton's method with starting value 0 for three equations:
• 1.0x³-6x²+x-6 = 0, roots: 3.00 2.00 1.00
• .95x³-6x²+x-6 = 0, roots: 3.56 1.72 1.03
• .50x³-6x²+x-6 = 0, roots: 9.90 1.05±.331i

The first two have three real roots. The iteration successfully finds 1 and 1.03. The last one has a complex conjugate pair 1.05±0.331i and it seems that the iteration is trying to find a root near the real number 1.05 (half their sum) when that root doesn't exist. If I start put starting value 8 in E12, the iteration finds the only real root at 9.90.
202509171652.ods
Newton's method
(20.11 KiB) Downloaded 14 times

Lupp wrote: Wed Sep 17, 2025 7:20 pm as requested by MrProgrammer for unknown reasons
Having a separate topic keeps this discussion about Newton's method separate from the example which does not use it.