用matlab如何编写牛顿迭代法问题,
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/23 23:03:04
用matlab如何编写牛顿迭代法问题,
X^3-X-1=0在闭区间【1,2】内的近似根 要求精度达到10^(-5)
X^3-X-1=0在闭区间【1,2】内的近似根 要求精度达到10^(-5)
function [ A ] = cal( a,b,v )%a,b表示区间,v是精度
i=1;
x = (a+b)/2;
A=[i x];
t = x-(x^3-x-1)/(3*x^2-1);%迭代函数
while(abs(t-x)>v)
i=i+1;
x = t;
A = [A;i x];
t = x-(x^3-x-1)/(3*x^2-1);%迭代函数
end
A = [A;i+1 t];
end
运行结果:
>> format long;
>> cal(1,2,0.00001)
ans =
1.000000000000000 1.500000000000000
2.000000000000000 1.347826086956522
3.000000000000000 1.325200398950907
4.000000000000000 1.324718173999054
5.000000000000000 1.324717957244790
i=1;
x = (a+b)/2;
A=[i x];
t = x-(x^3-x-1)/(3*x^2-1);%迭代函数
while(abs(t-x)>v)
i=i+1;
x = t;
A = [A;i x];
t = x-(x^3-x-1)/(3*x^2-1);%迭代函数
end
A = [A;i+1 t];
end
运行结果:
>> format long;
>> cal(1,2,0.00001)
ans =
1.000000000000000 1.500000000000000
2.000000000000000 1.347826086956522
3.000000000000000 1.325200398950907
4.000000000000000 1.324718173999054
5.000000000000000 1.324717957244790