Question: clc; clear % Root lies between in the interval [ a , b ] . f = input ( ' Enter the function f (

clc; clear
% Root lies between in the interval [a,b].
f = input('Enter the function f(x): ');
% To input a function you can use either of these two methods:
% Method 1: @(x) sqrt(9.81*x/0.25)0.25/x)*4)-36
% Method 2: inline('sqrt(9.81*x/0.25)0.25/x)*4)-36')
a = input('Enter left point of interval: ');
b = input('Enter right point of interval: ');
epsilon = input('Enter the error tolerance: '); % error of tolerance
x_tilde = a;
abs_f = abs(f(x_tilde)); % Absolute value of f(x) at the estimated solution.
iter =0; % Number of iterations
fprintf(1,'Iteration: %d | Lower Interval: %2.3f | Upper Interval: %2.3f | Root:
%2.3f | f(x) Abs. Value: %1.4f
',...
iter,a,b,x_tilde,abs_f);
if(f(a)*f(b)>0)
error('Enter a valid interval. Abort the procedure.');
else
while(abs_f > epsilon)
x_tilde_next =(a + b)/2;
iter = iter +1;
abs_f = abs(f(x_tilde_next));
fprintf(1,'Iteration: %d | Lower Interval: %2.3f | Upper Interval: %2.3f |
Root: %2.3f | f(x) Abs. Value: %1.4f
',...
iter,a,b,x_tilde_next,abs_f);
if f(x_tilde_next)*f(b)0
a = x_tilde_next;
else
b = x_tilde_next;
end
x_tilde = x_tilde_next;
end
end
fprintf('The root is %2.4f.
',x_tilde);Problem 1: A Hybrid Bracketing Method [1 pt]
Review the sample code for bisection method and false position method, which can be located on Canvas
under File/Sample MATLAB Code. Run a few examples on your own and see if you understand the code.
If not, speak with the instructors before proceeding with this problem.
A new method for solving a nonlinear equation f(x)=0 is proposed in this problem. The method is a
combination of the bisection and the false position methods. The solution starts by defining an interval
a,b that brackets the solution. Then estimated numerical solutions are determined once with the bisection
method and once with the false position method. (The first iteration uses the bisection method.) Write a
MATLAB user-defined function that solves a nonlinear equation f(x)=0 with this new method. Name
the function x= BiFalRoot(Fun,a,b,Tol ), where the output argument x is the solution. The input
argument Fun is a name for the function that calculates f(x) for a given x(it is a dummy name for the
function that is imported into BiFalRoot), a and b are two initial points that bracket the root, and Tol is
the error tolerance.
Your code should include the following features:
The program should stop when the estimated relative error drops below the specified tolerance Tol.
Check if points a and b are on opposite sides of the solution. If not, the program should halt and
display an error message of your choice.
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
message of your choice.
Use the function BiFalRoot to solve the equation cos(x)-0.8x2=0 with a=0 and b=2 and observe the
answer. For Tol use 0.00001.
clc; clear % Root lies between in the interval [

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!