@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.
[Example] Cubic equations and Newton's iteration method
[Example] Cubic equations and Newton's iteration method
Last edited by MrProgrammer on Wed Sep 24, 2025 8:33 pm, edited 1 time in total.
On Windows 10: LibreOffice 25.2.4 and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
---
Lupp from München
- MrProgrammer
- Moderator
- Posts: 5347
- Joined: Fri Jun 04, 2010 7:57 pm
- Location: Wisconsin, USA
Re: Cubic equations (second topic as requested by MrProgrammer for unknown reasons)
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.
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 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.
Having a separate topic keeps this discussion about Newton's method separate from the example which does not use it.
Last edited by MrProgrammer on Thu Sep 18, 2025 7:09 pm, edited 1 time in total.
Reason: Fix broken link to Cubic Equation article
Reason: Fix broken link to Cubic Equation article
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.6, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).
AOO 4.1.7 Build 9800, MacOS 13.7.6, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).