Picard迭代法-习题2.5
代码:
Main.h:
clc;clear;format long;
tol=10^(-8);
x0=0.5;
x1=(cos(0.5)*x0-sin(x0)+1)/(1+cos(0.5));
k=1;
while abs(x1-x0) >=tol
x0=x1;
x1=(cos(0.5)*x0-sin(x0)+1)/(1+cos(0.5));
k=k+1;
end
k
x1
运行结果:
x1=0.510973429388219
k=4
Newton迭代法-习题2.6
代码:
Main.h:
clc;clear;format long;
newton_iteration(1,10^(-8));
newton_iteration.m:
function x=newton_iteration(x0,tol)
x1=x0-f(x0)/f1(x0);k=1;
while abs(x1-x0) >=tol
x0=x1; x1=x0-f(x0)/f1(x0);k=k+1;
end
x1
k
f.m:
function f=f(x)
f=2sin(x+pi/3)-x;
end
f1.m:
function f=f(x)
f=2sin(x+pi/3)-x;
end
运行结果:
x1= 1.352044211500058
k=5