Visualize how newton's method works for real numbers and it's effects when applied in complex plane by displaying colors depending on which root individual pixel (represented as number in complex plane) converges to.
real plane:
- Take last saved x-position (if first take random). Find the first derivative of the function at that point and turn it into linear function.
- Find next x-position where this linear function crosses x-axis (root) and save that point.
complex plane:
Each pixel depending on it's position on screen is represented as a complex number.
Each complex root is represented as a point in 2d space and with random color.
Program for each pixel calculates
The entire code is written in Rust, a compiled language which provides the required computational speed.
In order to display values of function or complex numbers to screen, the program uses a camera abstraction.
real plane:
Define value
When 'space' is pressed perform next iteration by saving x-value where tangent line to our function at previous x-value crosses the x-axes.
complex plane:
In order to use complex numbers I use a library called num.
User specifies the number of roots he wants and program places the roots
Then it calculates function coefficients from roots using permutation method.
From these coefficients we can easily construct derivative of this function.
User can then press arrows to decrease/increase the number of iterations applied to each pixel or shift roots of the function using mouse.