简单迭代法:

clear all; clc; x0=1.5; tol=1e-6; N=50; x=x0; for k=1:N x1=x^3-1; if abs(x1-x)<tol fprintf('The solution is %f\n',x1) fprintf('The number of iterations is %d\n',k) break end x=x1; end

牛顿迭代法:

clear all; clc; x0=1.5; tol=1e-6; N=50; x=x0; for k=1:N f=x^3-x-1; f1=3*x^2-1; x1=x-f/f1; if abs(x1-x)<tol fprintf('The solution is %f\n',x1) fprintf('The number of iterations is %d\n',k) break end x=x1; end

收敛速度:

简单迭代法的收敛速度较慢,需要较多的迭代次数才能达到精度要求。而牛顿迭代法的收敛速度较快,通常只需要几次迭代就能达到较高的精度。但是牛顿迭代法需要计算函数的一阶导数,如果导数不易计算或者计算复杂,会影响收敛速度。


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

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