Coefficients

Roots


Usage

Controls: Click and drag on the canvas to move the view, to scroll zoom in and out.

Degree: This value changes the maximum exponent in the polynomial. Adding more terms slows the view so I've limited this value to 20.

Coefficients: These are the values that each term of the polynomial is multiplied by.

Roots: Shows the current approximation of the roots. Turns from red to green when approximation is acceptable.

Circles: The two circles in the view are the minimum and maximum values for the roots of the polynomial, determined by the coefficients.

Views:

Description

This program uses the Aberth method in order to approximate the roots of some polynomial. This algorithm can be described using an electrostatic analogy where the roots of the polynomial are positive charges (with their charge equal to the multiplicity of the root) and the current approximation of the roots are negative charges, attracted to the roots and repelled from each other. The reason for this is so that two potential roots don't converge to the same root (unless it has multiplicity greater than 1).

This program steps the roots every 100 frames (roughly every 3 seconds depending on the frameRate) however they are animated to linearly transition between these steps over time, this is why you may see the roots suddenly change their speed and direction discontinuously.

In order to get this visualization to run well in the browser I had to make quite a few optimizations. Because calculating the color of any given pixel is fairly expensive my goal was to try to minimize the number of times this is performed or spread it over several frames. When the viewport is zoomed the entire screen has to be redrawn so I spread the drawing over 16 frames to spread out the calculation. For translating the viewport only the newly revealed edges have to be drawn, the rest can just be translated over, this allowed me to make viewport translations run fairly quickly in the browser.

Purpose

My original reason for implementing this method was for finding the eigenvalues of a matrix to help me with homework (because using Wolfram Alpha felt too much like cheating). While implementing this in python I was having issues with the roots not converging so I decided to write this visualization to be able to see what was happening.

Rootfinding algorithms for polynomial functions have a wide number of uses so I felt it was worth taking time to learn about this algorithm and write my own implementation.

Originally Added: October 30, 2021
Last Updated: April 13, 2022