Question

In: Advanced Math

Computing3√25 using MATLAB. (a) Beginning with the interval [2,3], and f(x) =x^3−25, use the error bound...

Computing3√25 using MATLAB.

(a) Beginning with the interval [2,3], and f(x) =x^3−25, use the error bound for bisection to predict how many iterates bisection would need to get error within 10^−20.

(b) Run bisection on this problem. How many iterations did it need? For some of the iterates compute the absolute error. What is happening approximately to the number of significant digits of accuracy with each iteration?

(c) Write a program to perform Newton’s method on f(x) =x^3−25 with p0= 3 to get an approximation to 3√25 that is accurate to within 10^−20. Calculate the derivative by hand and hard code it in as a new function. How many iterates did it need? Save all of the iterates.

(d) Compute the absolute error and the number of significant digits of accuracy for each iterate. What is happening to the number of significant digits with each iteration? Compare to bisection

Solutions

Expert Solution


%Matlab code for root finding
clear all
close all
%function for which root have to do
func=@(x) x^3-25;
a=2; b=3;
tol=10^-20;
fprintf('For the function \n')
disp(func)

[root,iter]=bisection_method(func,a,b,tol);
fprintf('Root using Bisection method for a=%2.2f and b=%2.2f is %f\n',a,b,root)
fprintf('Number of iterations used for 10^-20 tol is %d\n',iter)


[root,iter]=newton_method(func,3,tol);
fprintf('\nRoot using Newton method for x0=%2.2f is %f\n',b,root)
fprintf('Number of iterations used for 10^-20 tol is %d\n',iter)


%Matlab function for Newton Method
function [root,iter]=newton_method(fun,x0,tol)
syms x
g1(x) =diff(fun,x);   %1st Derivative of this function
xx=x0;            %initial guess]
maxit=100000;
fprintf('\nRoot using Newton method\n')
%Loop for all intial guesses
    n=tol; %error limit for close itteration
    for i=1:maxit
        x2=double(xx-(fun(xx)./g1(xx))); %Newton Raphson Formula
        cc=abs(fun(x2));                 %Error
        err(i)=cc;
        xx=x2;
        if cc<=n
            break
        end
        fprintf('\tAfter %d iteration root using Newton method is %f\n',i,xx)
    end
    %fprintf('\tAfter %d iteration root using Newton method is %f\n',i,xx)
    root=xx;
    iter=i;
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Matlab function for Bisection Method
function [root,iter]=bisection_method(fun,x0,x1,tol)
if fun(x0)<=0
    t=x0;
    x0=x1;
    x1=t;
end
fprintf('\nRoot using Bisection method\n')
%f(x1) should be positive
%f(x0) should be negative
k=10; count=0; maxit=100000;
while k>tol
    count=count+1;
    xx(count)=(x0+x1)/2;
    mm=double(fun(xx(count)));
    if mm>=0
        x0=xx(count);
    else
        x1=xx(count);
    end
    err(count)=abs(fun(x1));
    k=abs(fun(x1));
    if count>=maxit
        break
      
    end
    %
end
fprintf('\tAfter %d iteration root using Bisection method is %f\n',count,xx(count))
root=xx(end);
iter=count;
end


%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%


Related Solutions

Using Matlab, consider the function f(x) = x^3 – 2x + 4 on the interval [-2,...
Using Matlab, consider the function f(x) = x^3 – 2x + 4 on the interval [-2, 2] with h = 0.25. Write the MATLAB function file to find the first derivatives in the entire interval by all three methods i.e., forward, backward, and centered finite difference approximations. Could you please add the copiable Matlab code and the associated screenshots? Thank you!
Write matlab program to compute ∫f(x)dx lower bound a upper bound b using simpson method and...
Write matlab program to compute ∫f(x)dx lower bound a upper bound b using simpson method and n points. Then, by recomputing with n/2 points and using richardson method, display the exact error and approximate error. (Test with a=0 b=pi f(x)=sin(x))
Refer to f(x)=1/x^2 1)Give an upper bound for the error you get when using the fourth...
Refer to f(x)=1/x^2 1)Give an upper bound for the error you get when using the fourth degree Taylor polynomial centered at c = 2 to approximate f(2.1) 2)What is the actual error of your approximation? (Use a calculator.)
Matlab Consider f(x) = x^3 - x. Plot it. (a) Use Newton's method with p_0 =1.5...
Matlab Consider f(x) = x^3 - x. Plot it. (a) Use Newton's method with p_0 =1.5 to find an approximation to a root with tolerance TOL = 0.01. (b) Use secant method with p_0 = 0.5 , p_1 =1.5, to answer same question as (a). (c) Use Method of False position with initial approximate roots as in (b).
a MATLAB script that: • Prompts the user for - a lower-bound for the plot interval...
a MATLAB script that: • Prompts the user for - a lower-bound for the plot interval and stores it in a variable named Lbound - an upper-bound for the plot interval and stores it in a variable named Ubound, and - the number of points at which a function is to be evaluated to generate a plot of the function over the specified range and stores it in a variable named npoints. • Generates a plot of f(x) = x3...
f(x)=e^x/(3+e^x) Find the first derivative of f. Use interval notation to indicate where f(x) is increasing....
f(x)=e^x/(3+e^x) Find the first derivative of f. Use interval notation to indicate where f(x) is increasing. List the x coordinates of all local minima of f. If there are no local maxima, enter 'NONE'. List the x coordinates of all local maxima of f. If there are no local maxima, enter 'NONE'. Find the second derivative of f: Use interval notation to indicate the interval(s) of upward concavity of f(x). Use interval notation to indicate the interval(s) of downward concavity...
Estimate the area (A) between the graph of the function F(X)=3/X  and the interval [1,2]. Use an...
Estimate the area (A) between the graph of the function F(X)=3/X  and the interval [1,2]. Use an approximation scheme with N= 2, 5 rectangles. Use the right endpoints. If your calculating utility will perform automatic summations, estimate the specified area using N=50 and N=100 rectangles. Round your answers to three decimal places. A2= A5= A10= A50= A100=
Consider the polynomial f(x) = 3x 3 + 5x 2 − 58x − 40. Using MATLAB....
Consider the polynomial f(x) = 3x 3 + 5x 2 − 58x − 40. Using MATLAB. Find the three roots of the polynomial, i.e, x where f(x) = 0, using Newton’s method. Report the number of iterations taken by each algorithm using a tolerance of 10−8 .
use a Taylor series to get the diverivative of f(x)=arctanx^3 and check for the interval of...
use a Taylor series to get the diverivative of f(x)=arctanx^3 and check for the interval of convergence. Is the interval of convergence for f' the same as the interval for f or different? Why?
The average value of a function f over the interval [-2,3] is -6, and the average...
The average value of a function f over the interval [-2,3] is -6, and the average value of f over the interval [3,5] is 20. What is the average value of f over the interval [-2,5]?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT