bisection.m

来自「solvin Parbolic forms of PDE explicitly.」· M 代码 · 共 41 行

M
41
字号
function root=bisection(xl,xu,maxit)

%Uses bisection method to find the root of the function sent to it in the
%given interval with fixed number of iterations (maxit).
%x1,xu=lower and upper limits of the interval
%output:root

es=0.0001;
iter=0;
xr=xl;

 
falpha1 = findroot(xl);
falpha2 = findroot(xu);

if (falpha1 * falpha2) < 0
    
    while (xu - xl) > es
        
        xmid = (xl + xu)/2;
        
        falpha3 = findroot(xmid);
        
        if (falpha1 * falpha3) > 0
            xl = xmid;
            falpha1 = falpha3;
        else
            xu = xmid;
            falpha2 = falpha3;
        end
    end
    root = xmid;
    fprintf('Alpha = %8.6f', root)
    return
end

end



⌨️ 快捷键说明

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