Write a MATLAB function, root- newton(x, stop, func), to solve for the root of a
ID: 3167346 • Letter: W
Question
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.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.