matlab, given a fixpoint solver y = fixpoint(fun, x0), write a wrapper function linsolve_fp(a, b, x0, tol) in matlab

main.m
function y = fixpoint(fun, x0)
    maxiter = 1000;
    tol = 1e-6;
    iter = 0;
    x = x0;
    while true
        x_new = fun(x);
        if norm(x_new - x, inf) < tol || iter >= maxiter
            break;
        end
        x = x_new;
        iter = iter + 1;
    end
    y = x_new;
end

function y = linsolve_fp(a, b, x0, tol)
    fun = @(x) a*x + b;
    y = fixpoint(fun, x0, tol);
end
392 chars
21 lines

gistlibby LogSnag