f = @(x) x^2 - 3x + 1;
a = 0;
b = 1;
tolerance = 1e-3;
iteration = 1;
maxiterations = 100;
while (b - a) / 2 > tolerance && iteration < maxiterations
c = (a + b) / 2;
fc = f(c);
if fc == 0
break;
elseif fc * f (a) < 0
b = c;
else
a = c;
end
iteration = iteration + 1;
end
root = (a + b) / 2;
fprintf(‘Approximate root: %f\n’, root);
fprintf(‘Number of iteration: %d\n’, iteration);
F = @(x) 2x^3 - 10*x + 5;
a = 0;
b = 1;
tolerance = 1e-3;
iteration = 1;
maxiterations = 100;
while (b - a) / 2 > tolerance && iteration < maxiterations
c = (a + b) / 2;
fa = f(a);
fb = f(b);
c = (a * f(b) - b * f(a) / f(b) - f(a);
fc = f(c);
if fc == 0
break;
elseif fc * f (a) < 0
b = c;
else
a = c;
end
iteration = iteration + 1;
end
root = c;
fprintf(‘Approximate root: %f\n’, root);
fprintf(‘Number of iteration: %d\n’, iteration);
f = @(x, y) x^2 + y^2;
x0 = 1;
y0 = 1.2;
h = 0. 01
N = 5;
x_values = zeroes(1, N+1);
y_values = zeroes(1, N+1);
x_values(1) = x0;
y_values(1) = y0;
for i = 1:N
x = x_values(i);
y = y_values(i);
x_values(i + 1) = x + h;
y_values(i + 1) = y + h * f(x, y);
end
plot(x_values, y_values, ‘-o’);
xlabel(‘x’);
ylabel(‘y’);
title(‘Approximate Solution using Euler’’s Method’);
fprintf(‘Approximate solution at x = %f: y = %f\n’, x_values (N + 1), y_values (N + 1));