Implementation of Bisection method and False Position method in coding form to find the value of unknown in MATLAB.

 

 

Objective:


Lab Report 06

Implementation of Bisection method and False Position method in coding form to find the value of unknown in MATLAB.




Theory:

·       Bisection Method:

The bisection method is used to find the roots of a polynomial equation. It separates the interval and subdivides the interval in which the root of the equation lies. The principle behind this method is the intermediate theorem for continuous functions. It works by narrowing the gap between the positive and negative intervals until it closes in on the correct answer. This method narrows the gap by taking the average of the positive and negative intervals. It is a simple method and it is relatively slow. The bisection method is also known as interval halving method, root-finding method, binary search method or dichotomy method.

Let us consider a continuous function “f” which is defined on the closed interval [a, b], is given with f(a) and f(b) of different signs. Then by intermediate theorem, there exists a point x belongs to (a, b) for which f(x) = 0.

Bisection Method Algorithm:

 

Follow the below procedure to get the solution for the continuous function:

 

i.           Calculate c, the midpoint of the interval, c = a + b/2.

ii.           Calculate the function value at the midpoint, f(c).

iii.           If convergence is satisfactory (that is, c - a is sufficiently small, or |f(c)| is sufficiently small), return c and stop iterating.

iv.           Examine the sign of f(c) and replace either (a, f(a)) or (b, f(b)) with (c, f(c)) so that there is a zero crossing within the new interval.

Repeat above three steps until f(t) = 0.

 

The bisection method is an approximation method to find the roots of the given equation by repeatedly dividing the interval. This method will divide the interval until the resulting interval is found, which is extremely small.


MATLAB Code:

>>clc

 

>>close all

 

>>clear all

 

>>xl=input('Enter Lower Boundary limit: ');

 

>>xu =input ('Enter Upper Boundary limit: ');

 

>>n= input('Enter number of iteration ');

 

>>fx1= (668.06/xl)*(1-exp(-0.146843*xl))-40;

 

>>fxu= (668.06/xu) *(1-exp(-0.146843*xu))-40;

 

>>if fx1*fxu<0

 

>>disp('Guees is right')

 

>>else

 

>>disp('your guess is wrong')

 

>>break

 

>>end

 

>>for i=1:1:n

 

>>xr(i)=(xl+xu)/2;

 

>>fx1= (668.06/xl)*(1-exp(-0.146843*xl))-40;

 

>>fxu= (668.06/xu)*(1-exp(-0.146843*xu))-40;

 

>>fxr(i)=(668.06/xr(i))*(1-exp(-0.146843*xr(i)))-40;

 

>>if fx1*fxr (i) <0

 

>>xu=xr (i);

 

>>else if fx1*fxr(i)>0

 

>>xl=xr(i);

 

>>else


>>xr(i)

 

>>end

 

>>end

 

>>if i>1

 

>> e(i)= ((xr(i)-xr(i-1))/xr(i))*100;

 

>>e(i-1)

 

>>if norm (e(i))<.02

 

>>xr(i-1)

 

>>break

 

>>end

 

>>end

 

>>end Screenshots: Input:


 

Output:

 

 

 

 

 

 

 

 

 

 

 

·       False Position Method:

ThisMATLAB program for finding real root of non-linear equation using Regula Falsi Method with Output. Regula Falsi method is also known as False Position Method. In this MATLAB program for false position method, y is nonlinear function, a & b are two initial guesses and e is tolerable error.

This is one of the iterative methods that give you the root if the function changes its sign: from positive to negative or from negative to positive. Despite the fact that bisection is an entirely legitimate strategy for determining roots, its “brute force” approach is generally inefficient. False position is based on graphical approach. A shortcoming of the bisection method is that, in dividing the interval from xl to xu into equivalent parts, no record is taken of the values of f (xl) and f (xu).

For instance, if f (xl) is very near to zero than f (xu), it is just like that the root is nearer to xl than to xu (as shown in the figure below). An alternate method that exploits this graphical understanding is to join f (xl) and f (xu) by a straight line. The intersection of this line with the x-axis gives an improved version of the root.

The way that the substitution of a curve by a straight line gives a “false position” of the root is the actual point of the name, method of false position, or in Latin, regula falsi method. It is additionally called the linear interpolation method. Because it takes the same approach where two points of a function are joined with a straight line.


Difference b/w False Position and Bisection:

 

The difference between bisection method and false-position method is that in bisection method, both limits of the interval have to change. This is not the case for false position method, where one limit may stay fixed throughout the computation while the other guess converges on the root.

 

false position method error


MATLAB Code:

 

>>clc

>>clear all

>>close all

>>xl= input('Enter value of lower boundary limit');

>>xu= input('Enter value of upper boundary limit');

>>n= input('Enter number of iteration');

>>fxl=(668.06/xl)*(1-exp(-0.146843*xl))-40;


>>fxu=(668.06/xu)*(1-exp(-0.146843*xu))-40;

>>if fxl*fxu<0

>> disp('Guess is right')

>>else

>> disp('Guess is wrong')

>> break

>>end

>>for i=1:1:n

>> fxl=(668.06/xl)*(1-exp(-0.146843*xl))-40;

>> fxu=(668.06/xu)*(1-exp(-0.146843*xu))-40;

>> xr(i)=xu-(((fxu)*(xl-xu))/(fxl-fxu))

>> fxu=(668.06/xu)*(1-exp(-0.146843*xu))-40;

>> fxr(i)=(668.06/xr(i))*(1-exp(-0.146843*xr(i)))-40;

>>if fxl*fxr(i)<0

>>      xu=xr(i)

>> else if fxl*fxr(i)>0

>>        xl=xr(i)

>> else

>> xr(i)

>>      end

>> end

>> if i>1

>>    e(i)=((xr(i)-xr(i-1))/xr(i))*100;

>> e(i-1)

>> if norm(e(i))<.02

>> xr(i-1)

>> break


>> end

>> end

>>end


MATLAB Screenshots: Input:

Output:


Post a Comment

0 Comments