Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

ISLAMIC UNIVERSITY OF TECHNOLOGY (IUT)

ORGANISATION OF ISLAMIC COOPERATION (OIC)


DEPARTMENT OF ELECTRICAL AND ELECTRONIC
ENGINEERING

NAME : Tasnia Nafs


STUDENT ID : 200021113
DEPARTMENT : ELECTRICAL AND ELECTRONIC ENGINEERING (EEE)
SECTION & GROUP : A1

DATE OF SUBMISSION : October 3, 2023

COURSE NO. : EEE 4506


COURSE TITLE : Numerical Lab
EXPERIMENT NO : 2
NAME OF EXPERIMENT : Introduction to Graphical method, Bisection method
and False-Position method to find the roots of non-linear equation
Advantage of False position method over bisection method:

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

n=input('Enter significant digit\n');


Es=(0.5*10^(2-n))
Es =
0.050000000000000

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

T = table(iteration1', approximation1', approximation_error1', true_error1', ...


'VariableNames', {'Iteration', 'Approximation', 'ApproximationError',
'TrueError'});
disp(T)
Iteration Approximation ApproximationError TrueError
_________ _____________ __________________ ____________________

1 0.95 100 0.0499999999999999


2 1.025 7.31707317073171 0.0250000000000001
3 0.9875 3.79746835443039 0.0125
4 1.00625 1.86335403726708 0.00625000000000009
5 0.996875 0.940438871473356 0.00312499999999993
6 1.0015625 0.468018720748837 0.00156250000000013
7 0.99921875 0.234558248631752 0.000781249999999956
8 1.000390625 0.117141741507228 0.000390625000000089
9 0.9998046875 0.0586051963274099 0.000195312499999933
10 1.00009765625 0.0292940142564269 9.76562500001332e-05

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

T = table(iteration2', approximation2', approximation_error2', true_error2', ...


'VariableNames', {'Iteration', 'Approximation', 'ApproximationError',
'TrueError'});
disp(T)
Iteration Approximation ApproximationError TrueError
_________ _________________ __________________ ____________________

1 0.907702365607606 100 0.0922976343923936


2 0.961577998855544 5.60283547585943 0.0384220011444559
3 0.984973685701688 2.37526008925582 0.0150263142983117
4 0.994292517260027 0.937232393543372 0.0057074827399729
5 0.997857880557277 0.357301712670651 0.00214211944272269
6 0.999199732423949 0.134292656726048 0.000800267576051006
7 0.999701552265299 0.0501969653055514 0.000298447734701335
8 0.999888771189101 0.0187239750257575 0.000111228810898534

Plot of true error


plot(iteration1(2:end),true_error1(2:end),'Marker','*', 'MarkerEdgeColor','r')
hold on
plot(iteration2(2:end),true_error2(2:end),'Marker','*', 'MarkerEdgeColor','r')
hold off
xlabel('no. of iteration')
ylabel('True Error')
legend('Bisection','False Position')
Plot of approx error
plot(iteration1(2:end),approximation_error1(2:end),'Marker','*',
'MarkerEdgeColor','r')
hold on
plot(iteration2(2:end),approximation_error2(2:end),'Marker','*',
'MarkerEdgeColor','r')
hold off
xlabel('no. of iteration')
ylabel('approx Error')
legend('Bisection','False Position')

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.

You might also like