You are on page 1of 8

Muhammad Aaliyan

Shafi Khan
Bsche(19-23)
Nmce Lab 5

Submitted on 18th March 2022


Table of contents

Lab Objective................................3
•Task 1..............................................3
1. Output
2. Discussion
•Task2...............................................5
1. Output
2. Discussion
Objective:
The main objective of this lab is applied numerical method by computational techniques such as
through MATLAB. In this 5th lab our aim is to practice closed bracketing methods like
Bisection and Regula Falsi Method and we also have to cover the different types of loops like if-
else, nested-if, for-loop and the operation inside them. Moreover, we shall give the interval of
input of our own choice

TASK 1

Code:
%f(x)=(x+2)*(x+1)*x*(x-1)^3*(x-2)
f=@(x) x^7-2*x^6-4*x^5+10*x^4-x^3-8*x^2+4*x;
a=input('Enter the starting interval value : ');
b=input('Enter the ending interval value : ');
n=input('Enter the number of iterations :');
e=input('Enter the tolerance value');%We shall put tolerance according to our own choice here
recommended is of 0.01 to 0.000001
if f(a)*f(b)<0
for i=1:n
m=(a+b)/2;
fprintf('\nIter %d =%.5f',i,m)
if abs(m-a)<e && abs(m-b)<e
disp(e)
break
end
if f(a)*f(m)<0
b=m;
elseif f(a)*f(m)>0
a=m;

end

i=i+1;
end
else
disp('No route is present in the interval');

end

Output:

(Part 1): (Part2):


(Part 3): (Part 4):

Discussion:

In this task we had solved various problems of bisection method. Bisection method is the
safest and it always converges. The bisection method is the simplest of all other methods and
is guaranteed to converge for a continuous function. It is always possible to find the number
of steps required for a given accuracy. And the new methods can also be developed from
bisection method and bisection method plays a very crucial role in computer science
research. We had seen in our results that for all parts tolerance value for convergence is in
(10^-6) order, moreover we also had seen for mostly all the cases the solution converges at
(16-20 ) iteration range.
.
TASK 2

Use False Position Method to find the solution to within 10-5 for the following
problem

Code:

%f(x)=x^3-2x^2-5=0 in interval [1,4], f(x)=x^3+3x^2-1=0 in interval [-3,-2], f(x)=x-cosx=0 in


interval [0,pi/2] ,f(x)=x-0.8-0.2sinx=0 in interval [0,pi/2]
f=input('Enter the expression: ');
a=input('Enter the starting interval value : ');
b=input('Enter the ending interval value : ');
n=input('Enter the number of iterations :');
e=input('Enter the tolerance value');%We shall put tolerance according to our own choice here
recommended is of 0.01 to 0.00001
if f(a)*f(b)<0
for i=1:n
m=a-((f(a)*(b-a))/(f(b)-f(a)));
fprintf('\nIter %d =%.5f',i,m)
if abs(m-a)<e && abs(m-b)<e
disp(e)
break
end
if f(a)*f(m)<0
b=m;
elseif f(a)*f(m)>0
a=m;

end

i=i+1;
end
else
disp('No route is present in the interval');

end

OUTPUT:

(Part 1): (Part 2):


(Part 3): (Part 4):

Discussion:

In this task we had solved various problems of Regula Falsi method. The regula falsi or the false
position method is used to solve problems in arithmetic or algebra. It refers to the basic trial and
error methods of solving problems by substituting test values for the unknown quantities. It is
also referred to as "guess and check". Its advantages include It always converges, It does not
require the derivative, It is a quick method, Its disadvantages include, one of the interval
definitions can get stuck, It may slowdown in unfavorable situations. We had seen in our results
that for all parts tolerance value for convergence is in (10^-5) order, moreover we also had seen
for mostly all the cases the solution converges at (16-20 ) iteration range.

Results:
• The results are obtained with best of possible knowledge and are fine according to the
given condition.
• We can see from our coherence of results and logics that the activity is fine.
• Bugs were avoided with best possible efforts.

You might also like