Using C Programming Language g(xn)= x- f(xn)/f\'(xn) The function /(x) = 2 cos(5
ID: 3928746 • Letter: U
Question
Using C Programming Languageg(xn)= x- f(xn)/f'(xn)
The function /(x) = 2 cos(52) + 2 cos(42) + 6 cos(3r) + 4 cos(2x) + 10 cos(x) + 3 has two roots on the interval [0,3; one root is near 1 and the other near 2. (i) Use Newton's method rn+g) with ro1 and also with zo2 to approximate these two roots. Use the fact that the exact roots are /3 and 2n/3 to compute the error en at each iteration for n 0,1,. , 18 (ii) Use the method xn +1 = h(2n) with 20-1 and again also with 20 2 to approximate these two roots. Again use the fact that the exact roots are /3 and 2n/3 to compute the error en at each iteration for n = 0,1,… , 18 iii) Comment on the rate of convergence and the effects of rounding error in the above two computations
Explanation / Answer
function [x e] = mybisect(f,a,b,n) % function [x e] = mybisect(f,a,b,n) % Does n iterations of the bisection method for a function f % Inputs: f -- an inline function % a,b -- left and right edges of the interval % n -- the number of bisections to do. % Outputs: x -- the estimated solution of f(x) = 0 % e -- an upper bound on the error format long format compact c = f(a); d = f(b); if c*d > 0.0 error(’Function has same sign at both endpoints.’) end for i = 1:n x = (a + b)/2 y = f(x) if c*y < 0 % compare signs of f(a) and f(x) b=x; % move b else a=x; % move a end end e = (b-a)/2;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.