% 牛顿迭代法 function x = newton_raphson(x0, f, df, tol) % x0: 初始解 % f: 函数 % df: 导函数 % tol: 容忍误差 while abs(f(x0)) >= tol x0 = x0 - f(x0) / df(x0); end x = x0; end

% 简化牛顿迭代法 function x = simplified_newton_raphson(x0, a, tol) % x0: 初始解 % a: 求立方根的数 % tol: 容忍误差 while abs(x0 ^ 3 - a) >= tol x0 = (2 * x0 + a / x0 ^ 2) / 3; end x = x0; end

% 构造立方根表 a = 101:111; x1 = zeros(1, 11); x2 = zeros(1, 11); for i = 1:11 x1(i) = newton_raphson(1.0, @(x) x ^ 3 - a(i), @(x) 3 * x ^ 2, 1e-6); x2(i) = simplified_newton_raphson(1.0, a(i), 1e-6); end x = [x1; x2]; fprintf('%10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s ', ... '101', '102', '103', '104', '105', '106', '107', '108', '109', '110', '111'); fprintf('%10.6f %10.6f %10.6f %10.6f %10.6f %10.6f %10.6f %10.6f %10.6f %10.6f %10.6f ', x);

MATLAB 立方根表生成:牛顿迭代法与简化牛顿迭代法

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

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