0% found this document useful (0 votes)
65 views1 page

Bisection Method MATLAB Code Example

This document contains code to perform the bisection method to find the root of a function between two bounds Vl and Vu. It takes user input for the bounds, maximum number of iterations, and acceptable error. It then iteratively calculates the midpoint Vm, checks if the function values on either side have opposite signs, and updates the bounds accordingly. The value of Vm and iteration number are printed if it converges within the error threshold.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views1 page

Bisection Method MATLAB Code Example

This document contains code to perform the bisection method to find the root of a function between two bounds Vl and Vu. It takes user input for the bounds, maximum number of iterations, and acceptable error. It then iteratively calculates the midpoint Vm, checks if the function values on either side have opposite signs, and updates the bounds accordingly. The value of Vm and iteration number are printed if it converges within the error threshold.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

clc;

clear;
disp ('Name
: ');
disp ('Matric Number : ');
Vl = input (' Enter the value of Vl: ');
Vu = input (' Enter the value of Vu: ');
Es = input (' Enter the value of Specific Error: ');
n = input (' Enter the maximum number of iteration: ');
fVl = (8+(2.485/(Vl^2)))*(Vl-0.045)-(0.08206*350);
fVu = (8+(2.485/(Vu^2)))*(Vu-0.045)-(0.08206*350);
disp ('--------------------------------------------------');
if (fVl)*(fVu) <0;
for i=1:n
Vm = (Vl+Vu)/2;
fVm = (8+(2.485/(Vm^2)))*(Vm-0.045)-(0.08206*350);
fVl = (8+(2.485/(Vl^2)))*(Vl-0.045)-(0.08206*350);
fVu = (8+(2.485/(Vu^2)))*(Vu-0.045)-(0.08206*350);
if (fVm)*(fVl)<0;
Vu=Vm;
else
Vl=Vm;
end
if i == 1
fprintf ('The value of V is %f after %d th iterations \n', Vm);
Vmold = Vm;
else
Ea = (abs ( Vm-Vmold)*100) ;
if Ea <= Es
fprintf ('The value of V is %f after %d th iterations \n', Vm, i);
break;
else
fprintf ('The value of V is %f after %d the iterations \n', Vm, i);
Vmold = Vm;
end
end
end
else
fprintf ('There are no roots between %f and %f \n', Vl, Vu);
end

You might also like