Bisection,
Bisection,
( πt
described as i (t )=10− 10 sin +cos
4
πt
4 )
A reaches zero for the first time using the
Solution:
a. Graphical Method:
clear;
clc;
function y=i(t)
y = 10 - (10 * sin(%pi * t / 4) + cos(%pi * t / 4));
endfunction
t = 0:0.01:10;
plot(t, i, "Red",'LineWidth');
xlabel('t');
ylabel('v(t)');
title('Graphical Method to Show the Root of v(t)');
xgrid (5,1,7);
Answer:
b. bisection method:
clc;
clear;
function i=f(t)
i = 10 - (10 * sin(%pi * t / 4) + cos(%pi * t / 4));
endfunction
t0 = input('Enter your lower range guess of the time: ');
t1 = input('Enter your upper range guess of the time: ');
es = input('Prespecified acceptable level in %: ');
ea = 100;
i = 0;
printf('Iteration\tt0\t\tf(t0)\t\tt1\t\tf(t1)\t\tea\n');
while ea > es
if ea == 100 then
printf('%d\t\t%f\t%f\t%f\t%f\n', i, t0, f(t0), t1, f(t1));
else
printf('%d\t\t%f\t%f\t%f\t%f\t%f\n', i, t0, f(t0), t1, f(t1), ea);
end
t20 = (t0 + t1) / 2;
f20 = f(t20);
a = f(t0) * f20;
if a < 0 then
t1 = t20;
else
t0 = t20;
end
t21 = (t0 + t1) / 2;
ea = (abs(t21 - t20) / t21) * 100;
i = i + 1;
end
printf('%d\t\t%f\t%f\t%f\t%f\t%f\n', i, t0, f(t0), t1, f(t1), ea);
printf('The approximate time when the current is zero for the first time is
%f seconds.\n', t21);
Answer: