我正在做一个任务,其中必须找到位于区间[a,b)中的三对角对称矩阵的特征值的数量。我需要使用二分法来找到这些特征值,它们必须以向量E的形式输出。函数是函数E=二分法( a,a,b,tol),tol是可接受的误差范围。
% If tolerance is met, add (a + b)/2 to E as many times as there are
% eigenvalues left in [a,b). This is the recursive stopping criterium.
if(b - a < tol)
for i = 1:n
E = [E; (a + b)/2];
end
end
% If there are eigenvalues left in [a,b), add new eigenvalues to E through
% recursion.
if(n > 0)
E = [E; bisection(A, a, (a+b)/2, tol); bisection(A, (a+b)/2, b, tol)];
end
E = [];我想做的是用另一个二等分函数来扩展向量E。只有我得到这个错误:
??? Undefined function or variable "E".
Error in ==> bisection at 56
E = [E; bisection(A, a, (a+b)/2, tol); bisection(A, (a+b)/2, b, tol)];我已经创建了一个空向量E,显然不能放在函数中。那么有没有什么方法可以递归地展开一个向量呢?
发布于 2013-04-18 22:04:19
如果您不能将空的起始向量放入函数中,则应将其作为输入参数传递。
这是顶层代码可能的样子,例如:
E = [];
E = myRecursiveFunction(E,inputs,stoppingCriteria)https://stackoverflow.com/questions/16085090
复制相似问题