You are on page 1of 1

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