Department of Mechatronics Engineering University of Engineering & Technology, Peshawar

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

DEPARTMENT OF MECHATRONICS ENGINEERING

UNIVERSITY OF ENGINEERING & TECHNOLOGY, PESHAWAR

MtE 350L Numerical Method


Student Name: Mian Sayaf Ali Shah Reg. No: 18PWMCT0612

Lab Tittle: Bisection Method

Lab No: 3

LAB REPORT RUBRICS:


Excellent (4) Proficient (3) Basic (2) Below Basic
Student’s
Criteria (1)
Score

Report is mostly Report is


Report is as per
as per the disorganized
the guidelines. Sections/Steps
To organize the lab guidelines and and follows
All are not ordered
report and practice most some guidelines
sections/steps are and Report is
the writing skills as sections/steps are but most of the
clearly organized not as per the
per the guidelines ordered well but guidelines are
in a logical guidelines
requires minor missing
order.
improvements.
The report
completely
The report
discusses the The report is
The report discusses the lab
To discuss the actual required task in totally
discusses the work but have
task own words with irrelevant to
required task irrelevant
some relevant the lab work
information
additional
information
Calculations and
Calculations and Most data and
data analysis were
data analyses observations
performed
were were recorded Calculations
To perform accurately, but
performed adequately, but and data
calculations and minor errors were
clearly, with several analyses of lab
data analysis made both in
concisely, and significant were missing
calculations and
accurately, with errors or
in applying
correct units. omissions.
correct units
Graphs, if
necessary, were Graphs, if Major
To present results Graphs, if
drawn accurately necessary, were components of
in the form of necessary, were
and neatly and drawn but lab were
graphs drawn adequately
were clearly inadequately. missing
labelled.
Numerical Methods
Lab Report # 3

Bisection Method

Submitted by: Mian Sayaf Ali Shah(18PWMCT0612)

Submitted to: Dr. Shahzad Anwar

Section: A

Submission Date (December 4, 2020)

DEPARTMENT OF MECHATRONICS ENGINEERING


University of Engineering and Technology, Peshawar, Pakistan
Objective:
 To know about basic and arithmetic operations of polynomial MATLAB
 To Know about roots of equation in MATLAB.
 To determine the derivative of equation in MATLAB.
 To write the code for the Bisection iteration method.

Software:
 MATLAB

Theory:
Basically, we do computations and visualization in MATLAB. In this lab, we did the
computations. We learn how to write the polynomial in MATLAB and do arithmetic operations
on polynomial. We learn how to find roots and derivative of polynomial. We use many
commands like roots, polyval, polyder, poly, conv, deconv, and fprintf. In bisection method,
we used the conditional statements and loops.

Post Lab Tasks:


Write down the MATLAB Code for the following Equation using bisection Method.
1. 5x^3-12x^2+20x-5
2. 4x^2-7x+5
1. 5x^3-12x^2+20x-5
MATLAB Code:
%5*x.^3-12*x.^2+20*x-5
f = @(x) 5*x.^3-12*x.^2+20*x-5;
XL = input('enter value of XL: ');
XU = input('enter value of XU: ');

if f(XL)==0
fprintf('XL is one of the root\n');
elseif f(XU) == 0
fprintf('XU is one of the root\n');
end

if f(XL)*f(XU)>0
fprintf('no roots exist in given interval\n');
end

if f(XL)*f(XU) < 0
fprintf(' XL XU XM\n'); %This line is just for
displaying lables in output
for i=1:20
XM = (XL+XU)/2;
fprintf('%.4f %.4f %.4f\n', XL, XU ,XM);
if f(XL) > 0 & f(XM) > 0 & f(XU) <0
XU = XU;
XL = XM;
elseif f(XL)>0 & f(XM) < 0 & f(XU) <0
XL = XL;
XU = XM;
elseif f(XL) <0 & f(XM) < 0 & f(XU) > 0
XL = XM;
XU = XU;
elseif f(XL) <0 & f(XM) > 0 & f(XU) > 0
XL = XL;
XU = XM;
end
end
fprintf('the final root is: %.4f ' ,XM);
end
Results:

Figure 1 Result of Task 1

2. 4x^2-7x+5
MATLAB Code:
%4*x^2-7*x+5
f = @(x) 4*x^2-7*x+5;
XL = input('enter value of XL: ');
XU = input('enter value of XU: ');

if f(XL)==0
fprintf('XL is one of the root\n');
elseif f(XU) == 0
fprintf('XU is one of the root\n');
end

if f(XL)*f(XU)>0
fprintf('no roots exist in given interval\n');
end

if f(XL)*f(XU) < 0
fprintf(' XL XU XM\n'); %This line is just for
displaying lables in output
for i=1:20
XM = (XL+XU)/2;
fprintf('%.4f %.4f %.4f\n', XL, XU ,XM);
if f(XL) > 0 & f(XM) > 0 & f(XU) <0
XU = XU;
XL = XM;
elseif f(XL)>0 & f(XM) < 0 & f(XU) <0
XL = XL;
XU = XM;
elseif f(XL) <0 & f(XM) < 0 & f(XU) > 0
XL = XM;
XU = XU;
elseif f(XL) <0 & f(XM) > 0 & f(XU) > 0
XL = XL;
XU = XM;
end
end
fprintf('the final root is: %.4f ' ,XM);
end
Results:

Figure 2 Result of Task 2

NOTE: Equation 2 has no roots.


Conclusion:
After performing this lab, we come to know about the computations in MATLAB and basic
operations that we did on polynomials in MATLAB. We write the code for bisection method
to determine the roots of polynomial. In first task, the roots determined which is shown in
figure. 1. In second task, there is no roots of equation given to us. The graph of equation 2 is
not touching the x-axis.

You might also like