Nı Nümerik
Nı Nümerik
SORU 2
clc;close all;clear all;
% Bisection Method's
xl = 140; % Lower limit of the closed interval
xu = 150; % Upper limit of the closed interval
fx =@(x) sqrt(g.*x/cd).tanh(sqrt(gcd./x)*t)-v; % Define the function
f(x)
es = 0.01; % Given approximate absolute relative error tolerance.
imax = 100; % Define maximum # iteration
xl_all = []; % Store all calculated values of xl
xu_all = []; % Store all calculated values of xu
xr_all = []; % Store all calculated values of xr
ea_all = []; % Store all calculated values of ea
fxl_all = []; % Store all calculated values of f(xl)
fxu_all = []; % Store all calculated values of f(xu)
fxr_all = []; % Store all calculated values of f(xr)
if fx(xl)*fx(xu) > 0 % if guesses do not bracket
disp('no bracket')
return
end
for i=1:1:imax
xr=(xu+xl)/2 ;
ea = abs((xu-xl)/xl);
test= fx(xl)*fx(xr);
if test < 0
xu=xr;
end
if test > 0
xl=xr;
end
if test == 0
ea=0;
end
if ea < es
break;
end