首页 > 编程知识 正文

matlab不动点迭代法,不动点法求函数迭代

时间:2023-05-04 07:38:22 阅读:237024 作者:987

不动点迭代法(Fixed point iteration method)

原理网上已经很多了,这里不再赘述。
需要注意的是不动点迭代法的使用条件。

举个简单的例子,利用不动点法求解方程f(x) = 1 + 0.5*sin(x) − x = 0在(1,2)区间的根。
令g(x)=1+0.5*sin(x)

g = @(x) fun2(x);% Initializationx0 = 0;tol = 1e-5;maxIter = 40;% Test biSection function[xStar,xRoot] = fixPoint(g,x0,tol,maxIter);fprintf('The fixed point is: %dn',xStar);fprintf('The root of the equation is: %dn',xRoot);function [xStar,xRoot] = fixPoint(fun2,x0,tol,maxIter)% Inputs:% fun2: a function handle, standing for the function written above% x0: the initial guess of the fixed point% tol: the tolerance within which the program can stop% maxIter: the maximum number of iterations the program is allowed to run% Outputs:% xStar: the numerical value of the fixed point% xRoot: the numerical value of the root x = zeros(maxIter,1); x(1) = fun2(x0); i = 1; while abs(fun2(x(i))-x(i))>tol && i<maxIter x(i+1) = fun2(x(i)); xStar = x(i); i = i+1; end xRoot = x(i);endfunction gx = fun2(x) gx = 1+0.5*sin(x);end

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。