exact_solution = @(x) x-2*sin(x);
xexact=linspace(0, 3, 1000);
yexact=exact_solution(xexact);
plot(xexact, yexact,'r');
hold on
x0=2;
e=0.00005;
n=100;
k=1;
x_iterations = [];
y_iterations = [];
for k=1:n
x1=asin(0.5*x0);
fprintf('x%d = %f\n', k, x1);
x_iterations(k) = x1;
y_iterations(k) = exact_solution(x1);
if abs(x1-x0)<e
fprintf('找到解: %f\n', x1);
break;
elseif k==n
fprintf('失败\n');
break;
else
x0=x1;
end
end
plot(x_iterations, y_iterations,'b*');
hold off