Question

In: Advanced Math

Consider the function f(x) = x - xcosx, which has a root at x = 0....

Consider the function f(x) = x - xcosx, which has a root at x = 0. Write a program to compare the rates of convergence of the bisection method (starting with a = -1, b = 1) and Newton’s method (starting with x = 1). Which method converges faster? Why?

Solutions

Expert Solution

Solution:

Newton's method converges faster

In Bisection method more iteration then converge real root but Newton's method less iteration and converge real roots

%% Bisection method
clc
clear all


%f= input('enter the function f \n')
f = @(x) [x-x*cos(x)];
a=input('enter the first initial guesse point \n')

b=input('enter the second initial guesse point b \n')

%% provide the equation you want to solve with R.H.S = 0 form.
%% Write the L.H.S by using inline function
%% Give initial guesses.
%% Solves it by method of bisection.
%% A very simple code. But may come handy

if f(a)*f(b)>0
    disp('Wrong choice Sp')
else
    p = (a + b)/2;
    err = abs(f(p));
    while err > 1e-8
   if f(a)*f(p)<0
       b = p;
   else
       a = p;         
   end
    p = (a + b)/2;
   err = abs(f(p));
    end
end

out_put = p  
   

%% matlab code ==newton Raphson methed

clc
clear all
f = @(x) [x-x*cos(x)]
g = @(x) [1+x*sin(x)-cos(x)] %% diff of function f
%g = input('enter the diff of function f = \n')
n = input('enter the number of iterations n = \n')
x0 = input('enter the inital approximation x0 \n')
for i=1:n   %% increase iterations converge real root
    x(1) = x0;
    x(i+1) = x(i) - (f(x(i))/g(x(i)));
    error_tolerance = abs(x(i) - x(i+1));
end
out_put= x(n)

***********************************************************


Related Solutions

Consider the root of function f(x) = x 3 − 2x − 5. The function can...
Consider the root of function f(x) = x 3 − 2x − 5. The function can be rearranged in the form x = g(x) in the following three ways: (a) x = g(x) = x3 − x − 5 (b) x = g(x) = (x 3 − 5)/2 (c) x = g(x) = thirdroot(2x + 5) For each form, apply fixed-point method with an initial guess x0 = 0.5 to approximate the root. Use the error tolerance = 10-5 to...
Suppose f is a twice differentiable function such that f′(x)>0 and f′′(x)<0 everywhere, and consider the...
Suppose f is a twice differentiable function such that f′(x)>0 and f′′(x)<0 everywhere, and consider the following data table. x      0       1       2 f(x)   3       A       B For each part below, determine whether the given values of A and B are possible (i.e., consistent with the information about f′and f′′ given above) or impossible, and explain your answer. a)A= 5, B= 6 (b)A= 5, B= 8 (c)A= 6, B= 6 (d)A= 6, B= 6.1 (e)A= 6, B= 9
Consider a function f(x) which satisfies the following properties: 1. f(x+y)=f(x) * f(y) 2. f(0) does...
Consider a function f(x) which satisfies the following properties: 1. f(x+y)=f(x) * f(y) 2. f(0) does not equal to 0 3. f'(0)=1 Then: a) Show that f(0)=1. (Hint: use the fact that 0+0=0) b) Show that f(x) does not equal to 0 for all x. (Hint: use y= -x with conditions (1) and (2) above.) c) Use the definition of the derivative to show that f'(x)=f(x) for all real numbers x d) let g(x) satisfy properties (1)-(3) above and let...
Consider the function f(x)f(x) whose second derivative is f''(x)=5x+10sin(x)f′′(x)=5x+10sin(x). If f(0)=4f(0)=4 and f'(0)=4f′(0)=4, what is f(5)f(5)?....
Consider the function f(x)f(x) whose second derivative is f''(x)=5x+10sin(x)f′′(x)=5x+10sin(x). If f(0)=4f(0)=4 and f'(0)=4f′(0)=4, what is f(5)f(5)?. show work
Find the root of the function f(x) = 8 - 4.5 ( x - sin x...
Find the root of the function f(x) = 8 - 4.5 ( x - sin x ) in the interval [2,3]. Exhibit a numerical solution using Newton method.
Estimate the area A between the graph of the function f(x)= square root of x and...
Estimate the area A between the graph of the function f(x)= square root of x and the interval [0,49]. Use an approximation scheme with n=2,5, and 10 rectangles. Use the right endpoints. Round your answers to three decimal places. A2= A5= A10= Click
1. Consider the following function F(x) = {2x / 25 0<x<5            {0 otherwise a) Prove...
1. Consider the following function F(x) = {2x / 25 0<x<5            {0 otherwise a) Prove that f(x) is a valid probability function. b) Develop an inverse-transformation for this function. c) Assume a multiplicative congruential random number generator with parameters: a: 23, m: 100, and xo: 17. Generate two random variates from the function for (x).
Consider the function on the interval (0, 2π). f(x) = sin(x) cos(x) + 2 (a) Find...
Consider the function on the interval (0, 2π). f(x) = sin(x) cos(x) + 2 (a) Find the open interval(s) on which the function is increasing or decreasing. (Enter your answers using interval notation.) increasing     ( )    decreasing     ( )   (b) Apply the First Derivative Test to identify all relative extrema. relative maxima     (x, y) =    (smaller x-value) (x, y) = ( )    (larger x-value) relative minima (x, y) =    (smaller x-value) (x, y) = ​   ...
Let f(x, y) be a function such that f(0, 0) = 1, f(0, 1) = 2,...
Let f(x, y) be a function such that f(0, 0) = 1, f(0, 1) = 2, f(1, 0) = 3, f(1, 1) = 5, f(2, 0) = 5, f(2, 1) = 10. Determine the Lagrange interpolation F(x, y) that interpolates the above data. Use Lagrangian bi-variate interpolation to solve this and also show the working steps.
The Polynomial f(x) = X^3 - X^2 - X -1 has one real root a, which...
The Polynomial f(x) = X^3 - X^2 - X -1 has one real root a, which happens to be positive. This real number a satisfies the following properties: - for i = 1,2,3,4,5,6,7,8,9,10, one has {a^i} not equal to zero - one has [a] = 1, [a^2] = 3, [a^3] = 6, [a^4] = 11, [a^5] = 21, [a^6] = 7, [a^7] = 71, [a^8] = 130 (for a real number x, [x] denotes the floor of x and {x}...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT