Question

In: Advanced Math

7. Finding Roots Using the Bisection Method Write a function that implements the "bisection method" for...

7. Finding Roots Using the Bisection Method

Write a function that implements the "bisection method" for finding the roots of function. The signature of your function should look like

def find_root(f,a,b,n):

where n is the maximum number of iterations of to search for the root.

The code should follow this algorithm:

  • We are given a continuous function f and numbers a and b and with a<b with f(a)<0<f(b). From the intermediate value theorem we know that there exists a c with a<c<b with f(c)=0. We want to find c.

  • Set a1=a and b1=b and m=12(a+b).

  • For i=1 to n do

    • If f(m)=0, then c=m so break and return m.
    • Else If f(m)>0 then set ai+1=ai and bi+1=m.
    • Else If f(m)<0, then set ai+1=mi and bi+1=bi.

Solutions

Expert Solution


%%Matlab code for finding root using Bisection method
clear all
close all


%Function for which root have to find
fun=@(x) sin(x)-1/2;

%displaying the function
fprintf('\tFor the function\n')
disp(fun)


%Root using Bisection method
x0=0; x1=1; %Initial guess
n=100; %maximum iteration
[root]=find_root(fun,x0,x1,n);
fprintf('Root using Bisection method for initial guess[%f,%f] is %2.15f with iteration count %d.\n\n',x0,x1,root,n);

%Matlab function for Bisection Method
function [root]=find_root(f,a,b,n)
if f(a)<=0
    t=a;
    a=b;
    b=t;
end
%f(x1) should be positive
%f(x0) should be negative
for i=1:n
    xx(i)=(a+b)/2;
    mm=double(f(xx(i)));
    if mm>=0
        a=xx(i);
    else
        b=xx(i);
    end
end
root=xx(end);
end

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


Related Solutions

Write one a MATLAB function that implements the Bisection method, Newton’s method and Secant Method (all...
Write one a MATLAB function that implements the Bisection method, Newton’s method and Secant Method (all in one function). Your function must have the following signature function output = solve(f,options) % your code here end where the input is • f: the function in f(x) =0. options: is a struct type with the following fields o method: bisection, newton or secant tol: the tolerance for stopping the iterations. maximum_iterations: the maximum number of iterations allowed. initial_guess: that is P_0; if...
I am asked to find the square roots using the bisection method for x * x...
I am asked to find the square roots using the bisection method for x * x - a = 0. I was wondering how the bisection method is performed. Let's suppose a = 9, so I would need to find the roots of x * x - 9 = 0. Also, from the 1st equation, when would the bisection method NOT output a root?
excel problem Find the roots of the functions given using the bisection method. Use the graph...
excel problem Find the roots of the functions given using the bisection method. Use the graph of each function to choose points that bracket the root of interest. a. f(x) x-x^1/3-2 b.f(x)=xtanx-1 c.f(x)=x^4-e^x+1 d.f(x)x^2e^x-1
Using the bisection method:     Make a program to use this method using the following three...
Using the bisection method:     Make a program to use this method using the following three functions and use it to find the root of this function f (x) = x * x * x-8. a) A function so that the user between xlower and xupper that meets the value of the function has a different sign and if he does not ask for new values. b) A function to find the root and call it bisection and perform a...
How could a root finding algorithm like the bisection method be used to approximate a value...
How could a root finding algorithm like the bisection method be used to approximate a value such as sqrt(3). In other words how can a root finding algorithm find an x value with a given y value? Write a script to illustrate this usage scenario. Compare the output of your script with the result from a calculator. You must use matlab!! using a while loop.
Using Python write a function that implements the following two-dimensional objective function: F (x, y) =...
Using Python write a function that implements the following two-dimensional objective function: F (x, y) = (x^2 + y − 11)^2 + (x + y^2 − 7 )^22 . Determine how many local minimums and maximums and their location for this objective function.
To find a positive root for , write a MATLAB script file that uses Bisection method....
To find a positive root for , write a MATLAB script file that uses Bisection method. Choose any initial value that is needed. Use absolute relative approximate error to be less than 0.01. Your code should report the number of iteration and the value of x.
Using Google sheets: On a spreadsheet show how to use the bisection method to solve the...
Using Google sheets: On a spreadsheet show how to use the bisection method to solve the equation cos⁡(x)=x numerically to at least four decimal place accuracy
USING BISECTION METHOD, FIND THE ROOT OF 0.5e^x - 5x + 2 = 0 ON THE...
USING BISECTION METHOD, FIND THE ROOT OF 0.5e^x - 5x + 2 = 0 ON THE INTERVAL [ 0 , 1 ] UP TO 3 DECIMAL PLACES. USE NEWTON'S METHOD TO APPROXIMATE THE ROOT OF f(x)=x^2-5    IN THE INTERVAL  [ 2 , 3 ] UP TO 4 DECIMAL PLACES.
write a procedure that implements the Pollard rho factorization method in Mathematica.
write a procedure that implements the Pollard rho factorization method in Mathematica.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT