Consider the general problem of finding a root of f, that is find a solution of
ID: 3860797 • Letter: C
Question
Consider the general problem of finding a root of f, that is find a solution of the equation f(x) = 0. The Newton's method of iteration is x_n+1 = x_n - f(x_n)/f'(x_n), n = 0, 1, 2, ellipsis Write a program that will implement Newton's method and evaluate the problem by finding a solution of equations x = cos(x). Use your computer implementation of Newton's method with initial guess x_0 = 1 to compute at least the first 12 iterations. Calculate the error at each iteration e_n = alpha - x_n, where alpha is the exaction solution. Use alpha = 0.7390851332151607. Please use MATLAB and explain everything, thank you very much!Explanation / Answer
Matlab code:
format long;
exact = 0.7390851332151607;
x = 1;
f = @(x)(cos(x) - x);
g = @(x)(-sin(x) - 1);
h = (f(x))/ (g(x));
i = 1;
while(i<= 12)
iteration = i
h = f(x)/g(x);
x = x - h;
difference_from_exact_solution = exact - x
i=i+1;
end
finalroot = x
Sample Output: