Question

In: Advanced Math

Write a Matlab function for: 1. Root Finding: Calculate the root of the equation f(x)=x^3 −5x^2...

Write a Matlab function for:

1. Root Finding: Calculate the root of the equation f(x)=x^3 −5x^2 +3x−7

Calculate the accuracy of the solution to 1 × 10−10. Find the number of iterations required to achieve this accuracy. Compute the root of the equation with the bisection method.

Your program should output the following lines:

• Bisection Method: Method converged to root X after Y iterations with a relative error of Z.

Solutions

Expert Solution


%Matlab function for Bisection Method
clear all
close all

%function for which root have to find
fun=@(x) x.^3-5*x.^2+3*x-7;
fprintf('function for which root have to find\n')
disp(fun)

x0=0; x1=10; tol=10^-10;
[root,iter]=bisection(fun,x0,x1,tol);
fprintf('Method converged to root %f after %d iterations with a relative error of %e.\n',root,iter,tol)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [root,iter]=bisection(fun,x0,x1,tol)
  
    if fun(x0)<=0
        t=x0;
        x0=x1;
        x1=t;
    end
    %f(x1) should be positive
    %f(x0) should be negative
    k=10; count=0; maxit=1000;
    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));
        %k=abs(x0-x1);
        if count>=maxit
            break
        end
    end
    root=xx(end);
    iter=count;
end

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


Related Solutions

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 .
Write a program to compute the root of the function f(x) = x3 + 2 x2...
Write a program to compute the root of the function f(x) = x3 + 2 x2 + 10 x - 20 by Newton method ( x0 =2 ). Stop computation when the successive values differ by not more than 0.5 * 10-5 . Evaluate f(x) and f '(x) using nested multiplication. The output should contain: (1) A table showing at each step the value of the root , the value of the function,and the error based upon successive approximation values...
2. Let f(x)=2x^2−4x+7/5x^2+5x−9, evaluate f '(x) at x=3 rounded to 2 decimal places. f '(3)= 3....
2. Let f(x)=2x^2−4x+7/5x^2+5x−9, evaluate f '(x) at x=3 rounded to 2 decimal places. f '(3)= 3. Let f(x)=(x^3+4x+2)(160−5x) find f ′(x). f '(x)= 4. Find the derivative of the function f(x)=√x−5/x^4 f '(x)= 5. Find the derivative of the function f(x)=2x−5/3x−3 f '(x)= 6. Find the derivative of the function g(x)=(x^4−5x^2+5x+4)(x^3−4x^2−1). You do not have to simplify your answer. g '(x)= 7. Let f(x)=(−x^2+x+3)^5 a. Find the derivative. f '(x)= b. Find f '(3)= 8. Let f(x)=(x^2−x+4)^3 a. Find the...
Using MATLAB, Consider the polynomial f(x) = 3x^3 + 5x^2 − 58x − 40. Find the...
Using MATLAB, Consider the polynomial f(x) = 3x^3 + 5x^2 − 58x − 40. Find the three roots of the polynomial, i.e, x where f(x) = 0, using: (i) Bisection method, and (ii) Newton’s method. Report the number of iterations taken by each algorithm using a tolerance of 10^−8 .
Question1: Find the interval of increase and decrease of given function f(x)=3x^5-5x^3 f(x)=1/3 x^3-9x+2
Question1: Find the interval of increase and decrease of given function f(x)=3x^5-5x^3 f(x)=1/3 x^3-9x+2
Given the function f(x) on the right solve the following root finding questions: a) Find a...
Given the function f(x) on the right solve the following root finding questions: a) Find a positive root (x > 0) of f(x) using the Bisection Method . b) Find a negative root (x < 0) of f(x) using the Bisection Method. c) Find a positive root (x > 0) of f(x) using the False Position Method. d) Find a negative root (x < 0) of f(x) using the False Position Method. Find your initial Bracket via Trial-and-Error. Use |...
If f(x)=2x^2−5x+3, find f'(−4).      Use this to find the equation of the tangent line to the...
If f(x)=2x^2−5x+3, find f'(−4).      Use this to find the equation of the tangent line to the parabola y=2x^2−5x+3 at the point (−4,55). The equation of this tangent line can be written in the form y=mx+b where m is: ???? and where b is: ????
Use the secant Method to find a root for the function: f(x) = x^3 + 2x^2...
Use the secant Method to find a root for the function: f(x) = x^3 + 2x^2 + 10x -20, with x_0 = 2, and x_1 = 1.
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...
consider the function f(x)=3x-5/sqrt x^2+1. given f'(x)=5x+3/(x^2+1)^3/2 and f''(x)=-10x^2-9x+5/(x^2+1)^5/2 a) find the local maximum and minimum...
consider the function f(x)=3x-5/sqrt x^2+1. given f'(x)=5x+3/(x^2+1)^3/2 and f''(x)=-10x^2-9x+5/(x^2+1)^5/2 a) find the local maximum and minimum values. Justify your answer using the first or second derivative test . round your answers to the nearest tenth as needed. b)find the intervals of concavity and any inflection points of f. Round to the nearest tenth as needed. c)graph f(x) and label each important part (domain, x- and y- intercepts, VA/HA, CN, Increasing/decreasing, local min/max values, intervals of concavity/ inflection points of f?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT