SUNIL KUMAR | P23ST013 | BISECTION METHOD
F = @ (x) (x^3-6*x^2+11*x-6) ;
a = 0; b = 1.5; imax = 20; tol = 0.0001 ;
Fa = F(a); Fb = F(b);
if Fa*Fb > 0
disp('Error:The function has the same sign at points a and b.')
else
disp('iteration a b (xNS)Solution f(xNS) Tolerance')
for i = 1:imax
xNS = (a + b)/2;
toli = (b - a )/2;
FxNS = F(xNS);
fprintf('%3i %14.6f %11.6f %11.6f %11.6f %11.6f\n', i, a, b, xNS, FxNS,
toli)
if FxNS == 0
fprintf('An exact solution x=%11.6f was found',xNS)
break
end
if toli < tol
break
end
if i == imax
fprintf('Solution was not obtained in %i iterations',imax)
break
end
if F(a)*FxNS < 0
b= xNS;
else
a = xNS;
end
end
end
RESULT:
iteration a b (xNS)Solution f(xNS) Tolerance
1 0.000000 1.500000 0.750000 -0.703125 0.75000
2 0.750000 1.500000 1.125000 0.205078 0.375000
3 0.750000 1.125000 0.937500 -0.136963 0.187500
4 0.937500 1.125000 1.031250 0.059601 0.093750
5 0.937500 1.031250 0.984375 -0.031986 0.046875
6 0.984375 1.031250 1.007812 0.015442 0.023438
7 0.984375 1.007812 0.996094 -0.007858 0.011719
8 0.996094 1.007812 1.001953 0.003895 0.005859
9 0.996094 1.001953 0.999023 -0.001956 0.002930
10 0.999023 1.001953 1.000488 0.000976 0.001465
11 0.999023 1.000488 0.999756 -0.000488 0.000732
12 0.999756 1.000488 1.000122 0.000244 0.000366
13 0.999756 1.000122 0.999939 -0.000122 0.000183
14 0.999939 1.000122 1.000031 0.000061 0.000092
SUNIL KUMAR | P23ST013 | PROJECTILE MOTION
v = 120; % v = initial velocity in m/s
angle = 30 ; % angle = trajectory angle in degree
r = angle*pi/180; % converts degree to radian
g = 10; % g = acceleration due to gravity
T = 2*v*sin(r)/g ; % time of flight in seconds
fprintf('Total time of flight T= %1.2f\n',T);
disp('time(t) X Y')
for t = 0:0.5:T % t = time in seconds
Vi = v*cos(r); % velocity in X-direction
Vj = v*sin(r); % velocity in Y-direction
X = (Vi*t); % X(t)
Y = (Vj*t-0.5*g*t^2); % Y(t)
fprintf('%3.2f %11.2f %11.2f\n',t , X, Y);
end
RESULT:
Total time of flight T= 12.00
time(t) X Y
0.00 0.00 0.00
0.50 51.96 28.75
1.00 103.92 55.00
1.50 155.88 78.75
2.00 207.85 100.00
2.50 259.81 118.75
3.00 311.77 135.00
3.50 363.73 148.75
4.00 415.69 160.00
4.50 467.65 168.75
5.00 519.62 175.00
5.50 571.58 178.75
6.00 623.54 180.00
6.50 675.50 178.75
7.00 727.46 175.00
7.50 779.42 168.75
8.00 831.38 160.00
8.50 883.35 148.75
9.00 935.31 135.00
9.50 987.27 118.75
10.00 1039.23 100.00
10.50 1091.19 78.75
11.00 1143.15 55.00
11.50 1195.12 28.75
12.00 1247.08 0.00