用matlab编程,迭代法求方程f(x)=x^2+2x-10的一个正根
1个回答
展开全部
clear all; clc;
f = inline('x^2+2*x-10');
df = inline('2*x+2');
k = 1;
x0 = 0;
tol = 1e-3;
x1 = x0-f(x0)/df(x0);
while abs(x1-x0)>tol
x0 = x1;
k = k+1;
x1 = x0-f(x0)/df(x0);
end
x0
%解析解
x = vpa(solve('x^2+2*x-10'))
x0 =
2.316938934730457
x =
-4.3166247903553998491149327366707
2.3166247903553998491149327366707
追问
非常感谢
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询