Experiment (3) Bisection Method in MATLAB: Objective: Equipment: 3. Background
Experiment (3) Bisection Method in MATLAB: Objective: Equipment: 3. Background
Experiment (3)
Bisection Method in MATLAB
1. Objective: to find the root of non-linear equation using Bisection Method in MATLAB.
2. Equipment: pc and MATLAB software.
3. Background:
4. Procedure:
Create a script file and type the following code
Write a program to find the roots of the following equations using bisection method:
a. X3 + 4 x2 -10
60
50
40
30
20
10
-10
0 0.5 1 1.5 2 2.5 3
A. L. Reem shakir 1
3th year ; 2nd semester numerical analysis lab
clear all;clc
% first plot the function
x=0:0.05:5;
f=@(x) (x.^3)+(4*(x.^2))-10;
plot(x,f(x));grid
a=input ('a=');
b=input ('b=');
tol=0.00001;
i=0
while (abs(a-b)> tol);
fa=f(a);
fb=f(b);
c=(a+b)/2;
fc=f(c);
fprintf('%13.4f %13.4f %13.4f %13.4f \n',a,b,c,fc)
if (fa *fc > 0);
a=c;
else
b=c;
end
i=i+1;
end
b. X3 - 6 x2 +10 x -4
-1
-2
-3
-4
0 0.5 1 1.5 2 2.5 3 3.5 4
A. L. Reem shakir 2
3th year ; 2nd semester numerical analysis lab
clear all;clc
% first plot the function
x=0:0.05:4;
f=@(x) (x.^3)-(6.*(x.^2))+10*x - 4;
plot(x,f(x));grid
a=input ('a=');
b=input ('b=');
tol=0.00001;
i=0
while (abs(a-b)> tol);
fa=f(a);
fb=f(b);
c=(a+b)/2;
fc=f(c);
fprintf('%13.4f %13.4f %13.4f %13.4f \n',a,b,c,fc)
if (fa *fc > 0);
a=c;
else
b=c;
end
i=i+1;
end
c = 3.414207 for [3 4]
5. Discussion
1. Consider f(x) = tan(x) on the interval (0,3). Use the 20 iterations of the bisection method and see what
happens. Explain the results that you obtained.
2. Write a program to find the roots of the following equation using bisection method:
F(x) = exp (x) - 3 x 2
A. L. Reem shakir 3
3th year ; 2nd semester numerical analysis lab
A. L. Reem shakir 4