1
3.21 A new method for solving a nonlinear equation is proposed. The method is a combination
of the bisection and the regula falsi methods. The solution starts by defining an interval that brackets
the solution. Then estimated numerical solutions are determined once with the bisection method and once
with the regula falsi method. (The first iteration uses the bisection method.) Write a MATLAB user-defined
function that solves a nonlinear equation with this new method. Name the function Xs = BiRe-
gRoot(Fun,a,b,ErrMax), where the output argument Xs is the solution. The input argument Fun is a
name for the function that calculates for a given x (it is a dummy name for the function that is
imported into BiRegRoot), a and b are two points that bracket the root, and ErrMax is the maximum
error according to Eq. (3.9).
The program should include the following features:
•
Check if points a and b are on opposite sides of the solution. If not, the program should stop and dis-
play an error message.
•
The number of iterations should be limited to 100 (to avoid an infinite loop). If a solution with the
required accuracy is not obtained in 100 iterations, the program should stop and display an error mes-
sage.
Use the function RegulaRoot to solve the equation in Problem 3.3 (use , ). For
ErrMax use 0.00001.
Solution
function Xs = BiRegRoot(Fun,a,b,ErrMax)
% BiRegRoott finds the root of Fun = 0 using a combination of the bisection
% and regula falsi methods