x0 = 0.4; % 初值 tol = 1e-6; % 迭代精度 maxIter = 100; % 最大迭代次数 alpha = 1; % 下山因子 iter = 0; % 迭代次数 while iter < maxIter fx = x0^3 - x0 - 1; fp = 3x0^2 - 1; x1 = x0 - alphafx/fp; % 牛顿下山法迭代公式 if abs(x1-x0) < tol % 判断是否达到精度要求 disp('下山因子为' + num2str(alpha)); disp('迭代次数为' + num2str(iter)); break; else % 更新下山因子和迭代次数 if x1 < x0 alpha = 1; else alpha = alpha/2; end x0 = x1; iter = iter+1; end end if iter == maxIter disp('迭代次数超过最大迭代次数,未能达到精度要求'); end

MATLAB 牛顿下山法求解方程 f(x) = x^3 - x - 1 = 0

原文地址: https://www.cveoy.top/t/topic/nmwV 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录