Quantcast
Channel: MyClassBook
Viewing all articles
Browse latest Browse all 368

Bisection method – Algorithm,flowchart,matlab program

$
0
0

Algorithm for the Bisection Method:   Given a continuous function f(x)

  1. Find points a and b such that a < b and f(a) * f(b) < 0.
  2. Take the interval [a, b] and find its midpoint x1.
  3. If f(x1) = 0 then x1 is an exact root, else if f(x1) * f(b) < 0 then let a = x1, else if f(a) * f(x1) < 0 then let b = x1.
  4. Repeat steps 2 & 3 until f(xi) = 0 or |f(xi)| <= DOA, where DOA stands for degree of accuracy.

Matlab Program For Bisection Method :

% Bisection Method
clear all
close all
clc
% Change here for different functions
f=@(x) 3*x+sin(x)-exp(x)
% Change lower limit ‘a’ and upper limit ‘b’
a=0; b=1;
for i=1:1:100
x=(a+b)/2;
if f(x)<0
a=x;
else
b=x;
end
end
sol=x;
fprintf(‘Approximate Root is %.15f’,sol)
a=0;b=1;
er(10)=0;
for i=1:1:10
x1=(a+b)/2;
if f(x1)<0
a=x1;
else
b=x1;
end
er(i)=x1-sol;
end
plot(er)
xlabel(‘Number of iterations’)
ylabel(‘Error’)
title(‘Error Vs. Number of iterations’)
f = @(x)3*x+sin(x)-exp(x)
Approximate Root is 0.360421702960324

graph of Bisection Method

graph of Bisection Method

tags : Algorithm for bisection method flowchart for bisection method matlab program for bisection method matlab program for bisection method algorithm flowchart



Viewing all articles
Browse latest Browse all 368

Trending Articles