([[名無しさん]])
[13]
[CITE[Transforming XHTML to LaTeX and BibTeX]]
([[名無しさん]])
[14]
ex7.m
clear;
clc;
% Exercise #7: Root of a single nonlinear equation
% Find the root of the nonlinear equation h(x) = tan(x) - x = 0, which is between pi/2 and 3pi/2, using the bisection method AND the false position (regula falsi) method. Show the estimated root for each iteration.
epsilon = 1e-4;
imax = 1e9;
% interval_init = [1.00001 * (pi / 2), 0.99999 * (3 * pi / 2)];
interval_init = [1.001 * (pi / 2), 0.99 * (3 * pi / 2)];
xb = interval_init(1);
xh = interval_init(2);
x = [xb : (xh - xb) / 10000 : xh];
h = function_ex7(x);
% a) Méthode de bisection
for i = 1:imax
% Étape (1)
xm = (xh + xb) / 2;
% Étape (2)
hxmhxb = function_ex7(xm) * function_ex7(xb);
disp(['xm = ', num2str(xm), ' h(xm) * h(xb) = ', num2str(hxmhxb)]);
if (hxmhxb > epsilon)
xb = xm;
elseif (hxmhxb < -epsilon)
xh = xm;
else
disp(['h(x) = 0 --> x = ', num2str(xm), ' (i = ', num2str(i), ')']);
break;
end
end
imax_bisection = i;
x0_bisection = xm;
% b) Méthode de "false position" (regula falsi)
xb = interval_init(1);
xh = interval_init(2);
for i = 1:imax
xm = xb - (function_ex7(xb) * (xh - xb)) / (function_ex7(xh) - function_ex7(xb));
hxm = function_ex7(xm);
% disp(['xm = ', num2str(xm), ' h(xm) = ', num2str(hxm)]);
disp(['i = ', num2str(i), ', xm = ', num2str(xm), ' h(xm) = ', num2str(hxm)]);
if (hxm > epsilon)
xb = xm;
elseif (hxm < -epsilon)
xh = xm;
else
disp(['h(x) = 0 --> x = ', num2str(xm), ' (i = ', num2str(i), ')']);
break;
end
end
imax_regulafalsi= i;
x0_regulafalsi = xm;
figure(7);
hold on;
plot(x, h, '-b', 'DisplayName', 'tan(x) - x');
plot(x0_bisection, 0, 'rd', 'DisplayName', ['Bisection (i_{max} = ', num2str(imax_bisection), ')']);
plot(x0_regulafalsi, 0, 'rx', 'DisplayName', ['Regula Falsi (i_{max} = ', num2str(imax_regulafalsi), ')']);
xlabel('x');
ylabel('h');
legend('show');
legend('Location', 'NorthWest');
axis([interval_init(1) interval_init(2) -10 10]);
grid on;
enhance_plot(0, 30, 5, 15, 0)
([[Mr.Anonymous]] [WEAK[2006-04-18 15:44:19 +00:00]])