Text: Python code only!
(A screenshot if possible)
A. Newton Raphson method
Write a function called ntnraf that takes the following inputs:
- f: the equation whose root is to be determined
- df: the derivative of the equation whose root is to be determined
- x0: the initial guess
- eTolerance: the error tolerance in percentages
- maxlteration: the maximum number of iterations
It then returns a Pandas DataFrame called result which contains the results from all iterations and has the following columns:
- iteration: the iteration number
- x0: the old value
- xr: the new root
- relative error: the calculated relative error
Your function needs to compute the root iteratively using the Newton Raphson method until the error tolerance condition has been met or the number of iterations has exceeded the maximum number of iterations. f(xi)
Write a python script to find the root of the equation: x^3 + 4x^2 + 7x - 4.3 = 0
Get the input parameters from the file called "datasaved.csv". Save the resulting data frame, called result, to a file called "ntnraf.csv".
B. Secant method
Write a function called Ethnin that takes the following inputs:
- f: the equation whose root is to be determined
- xMinus1: the first initial guess
- x0: the second initial guess
- eTolerance: the error tolerance in percentages
- maxiteration: the maximum number of iterations
It then returns a Pandas DataFrame called result which contains the results from all iterations and has the following columns:
- iteration: the iteration number
- xMinus1: the first guess
- x0: the second guess
- xr: the new root
- relative error: the calculated relative error
Your function needs to compute the root iteratively using the Secant method until the error tolerance condition has been met or the number of iterations has exceeded the maximum number of iterations. fx(x-1) - fx(x) / (x-1) - x
Write a python script to find the root of the equation: x^3 + 4x^2 + 7x - 4.3 = 0
Get the input parameters from the file called "datasave.csv". Save the resulting data frame, called result, to a file called "Ethnin.csv".