Professional Documents
Culture Documents
200021113_Tasnia_Nafs_Assignemnt-2
200021113_Tasnia_Nafs_Assignemnt-2
False position method and bisection method both are root finding methods. These two methods
maintains almost similar process while calculating the root of the given equation. False position method
usually consider the upper and lower level point while calculating the root which converge linearly.
Whereas in the bisection method we halve the two intervals. So, the converging time for the bisection
method is faster than the false position method. Besides, efficiency in false position method is much
more than the bisection method.
Bisection
clc
clear all
close all
format long
p=@(x) ((x^10)-1);
fplot(p,[0.5,1]);
Warning: Function behaves unexpectedly on array inputs. To improve performance, properly
vectorize your function to return an output with the same size and shape as the input
arguments.
hold on
yline(0,'-g');
hold off
iteration1 = [];
approximation1 = [];
approximation_error1 = [];
true_error1 = [];
iter = 1;
xl=0.8;
xu=1.1;
xr_previous=0;
ea=100;
while ea>Es
xr= (xl+xu)/2;
ea= abs((xr- xr_previous)/xr)*100;
true_err = abs(xr - 1);
iteration1(iter) = iter;
approximation1(iter) = xr;
approximation_error1(iter) = ea;
true_error1(iter) = true_err;
if p(xl)*p(xr) <0
xu=xr ;
elseif p(xl)*p(xr) >0
xl=xr;
else
break;
end
xr_previous=xr;
iter= iter+1;
end
double(xr)
ans =
1.000097656250000
False Position
format long
p=@(x) ((x^10)-1);
fplot(p,[0.5,1]);
Warning: Function behaves unexpectedly on array inputs. To improve performance, properly
vectorize your function to return an output with the same size and shape as the input
arguments.
hold on
yline(0,'-g');
hold off
n=input('Enter significant digit\n');
Es=(0.5*10^(2-n))
Es =
0.050000000000000
iteration2 = [];
approximation2 = [];
approximation_error2 = [];
true_error2 = [];
iter = 1;
xl=0.8;
xu=1.1;
xr_previous=0;
ea=100;
while ea>Es
xr= (xu*p(xl)-xl*p(xu))/(p(xl)-p(xu));
ea= abs((xr- xr_previous)/xr)*100;
true_err = abs(xr - 1);
iteration2(iter) = iter;
approximation2(iter) = xr;
approximation_error2(iter) = ea;
true_error2(iter) = true_err;
if p(xl)*p(xr) <0
xu=xr ;
elseif p(xl)*p(xr) >0
xl=xr;
else
break;
end
xr_previous=xr;
iter= iter+1;
end
double(xr)
ans =
0.999888771189101
In the false position method no of iteration is 8 whereas in the bisection method no of iteration is 10.
Hence we can conclude that false position method is better than bisection method.