⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 broyden.m

📁 linear equation routines in matlab
💻 M
字号:
function [x, ithist, iflag] = broyden( f, B, x, tolf, tolx, maxit )%%  function [x, ithist, iflag] = broyden( f, B, x, tolf, tolx, maxit )%%  fdbroyden attempts to compute a root of F using Broyden's method%%  Input parameters:%    f       name of a matlab function that evaluates F.%    Binv    initial Broyden matrix B_0%    x       initial iterate%    tolf    stopping tolerance (optional. Default tolf = 1.e-7)%            Newton's method stops if  ||F(x)||_2 < tolf%    tolx    stopping tolerance (optional. Default tolx = 1.e-7)%            Newton's method stops if  ||s||_2 < tolx, %            where s = -Binv F(x)  is the Newton step.%    maxit   maximum number of iterations (optional. Default maxit = 100)%%%  Output parameters:%    x       approximation of the solution. %    ithist  array with the iteration history%            The i-th row of ithist contains  [it, x, F, s]%    ifag    return flag%            iflag =  0  ||F(x)||_2 <= tolf %            iflag =  1  iteration terminated because maximum number of %                        iterations was reached. ||F(x)||_2 > tolf %%  Matthias Heinkenschloss%  Department of Computational and Applied Mathematics%  Rice University%  March 9, 2004%% set tolerances if necessaryif( nargin <= 3 ) tolf = 1.e-7; tolx = 1.e-7; maxit = 100; endif( nargin <= 4 ) tolx = 1.e-7; maxit = 100; endif( nargin <= 5 ) maxit = 100; end   it       = 0;iflag    = 0;F        = feval(f, x);    norms    = 2*tolx;while( it < maxit & norms > tolx & norm(F) > tolf )      s     = - (B\F);   norms = norm(s);      ithist(it+1,:) = [it, norm(x), norm(F), norms];      x  = x+s;   it = it+1;   F  = feval(f, x);   B  = B + F*s'/(s'*s);end% check why the Newton's method truncated and set iflagif( norm(F) > tolf )    % Newton's method truncated because the maximum number of iterations    % was reached    iflag = 1;    returnelse    % Newton's method truncated because norm(F) <= tolf    % print info for last iteration    ithist(it+1,:) = [it, norm(x), norm(F),0];end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -