Question: Write a MATLAB function, root = newton(x, stop, func), to solve for the root of any general user-defined function using the Newton-Raphson method. The newton
Write a MATLAB function, root = newton(x, stop, func), to solve for the root of any general user-defined function using the Newton-Raphson method.
The newton function should accept as input arguments the initial guess, x, the stopping criterion, stop, and the userdefined anonymous function called func.
The user-defined function should be defined at the command line prior to invoking the newton function. The derivative of the function should be calculated by a function called deriv(x, h), using the Forward Difference formula, double precision, and an appropriate step size (h) for double precision variables, which will be passed to it from the newton function. Use your program to solve the equation below, using an initial guess of x = 2.0 and a stopping criterion of stop = 0.001:
f(x) = x + 2 (e^x) = 0.

x, h, func x, stop, Cmd func Line K newton deriv func root f(x) f(x) Figure 1 - Data Flow Diagram
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
