Matlab - 函数:返回变量向量

Matlab - Functions: returning a vector of variables

我正在实施定点法来求根。下面是代码:

clear;
clc;

f = inline('y^4 - 2', 'y');
phii = inline('y - (y^4 -2)/(4*(y^3))', 'y');
x0 = 4;
toler = 10^-10;
nmax = 1000;

a = fixpoint(x0,toler,nmax,f,phii)

function[alpha,res,iters] = fixpoint(x_0,tol,max_iters,fun,phi)

    error = tol +1;
    iters = 0;
    xvect = x_0;
    x = x_0;
    res = fun(x);
    xdif = [];

    while iters < max_iters & error > tol
        iters = iters +1;
        x_n = phi(x);
        error = abs(x_n - x);
        xdif = [xdif; error];
        x = x_n;
        xvect = [xvect;x];
        res = [res;fun(x)];
    end
    alpha = xvect(end);
    residual = res(end);
    return
end

该方法可以正常工作。我遇到的唯一问题是我希望它 return 所有三个:alpha、res(一个向量,其中最后一个条目是重要性的残差,但所有值都是必需的)和迭代。

目前只有 returns alpha。

解决此问题的最佳方法是什么?

[alpha,res,iters] = fixpoint(x0,toler,nmax,f,phii)

另外,这里不需要return