Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a MATLAB function, root- newton(x, stop, func), to solve for the root of a

ID: 3167346 • Letter: W

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 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. . . x, stop, x, func Cmd Line newton deriv func root f(x) Figure 1 -Data Flow Diagram

Explanation / Answer

function root=Newton(x,tol,func)

h=0.01 %step size
erorr=0.1;
while(erorr>tol&n<100)

root=x-(func(x)/deriv(x,h)); %newton method
  

erorr=abs((x-root)/root);
x=root;
n=n+1;
end
end

function df=deriv(x,h)
df=(func(x+h)-func(x))/h
end

function f=func(x)
f=x-0.8-0.2*sin(x) ;% you have to give your example, i just given my example for understanding
end

%Note: All three functions should be save in same folder.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote