This code defines a function `solveByIteration` that uses the Newton-Raphson...
This code defines a function solveByIteration
that uses the Newton-Raphson method to find the root of a given equation. The equation and its derivative are passed as function pointers to the solveByIteration
function.
The solveByIteration
function takes an initial guess x0
, a desired precision epsilon
, and a maximum number of iterations maxIterations
. It iteratively updates the value of x
using the formula x = x - f(x) / df(x)
, where f(x)
is the equation and df(x)
is its derivative. It stops iterating when the absolute value of the change in x
is less than epsilon
, and returns the final value of x
.
The main
function prompts the user to enter the initial guess, precision, and maximum number of iterations. It then calls the solveByIteration
function with the equation and derivative functions, and prints the result if it is not NaN.