Here is a function written in JavaScript that returns the zeros of a polynomial formula entered by the user:
index.tsx814 chars30 lines
This function first prompts the user to enter the polynomial formula. It then parses the formula into a function using the Function
constructor.
The function then uses the Newton-Raphson method to find the zeros of the polynomial. This method uses an iterative approach to converge on the zeros. The starting value is set to 1.0, the desired accuracy is set to 1e-6 (i.e. six decimal places), and the maximum number of iterations is set to 100.
Finally, the function displays the zeros to the user using alert()
. Note that this function assumes that the polynomial formula entered by the user is valid and can be parsed into a function.
gistlibby LogSnag