recursion - Recursively appending to vector in MATLAB -
i'm working on assignment number of eigenvalues of tridiagonal symmetrical matrix located in interval [a,b) have found. need use bisection algorithm find these eigenvalues , have outputted in form of vector e. function function [ e ] = bisection(a, a, b, tol) tol being accepted error margin.
% if tolerance met, add (a + b)/2 e many times there % eigenvalues left in [a,b). recursive stopping criterium. if(b - < tol) = 1:n e = [e; (a + b)/2]; end end % if there eigenvalues left in [a,b), add new eigenvalues e through % recursion. if(n > 0) e = [e; bisection(a, a, (a+b)/2, tol); bisection(a, (a+b)/2, b, tol)]; end e = [];
what i'm trying expanding vector e function call of bisection. error:
??? undefined function or variable "e". error in ==> bisection @ 56 e = [e; bisection(a, a, (a+b)/2, tol); bisection(a, (a+b)/2, b, tol)];
i made empty vector e, can't put inside function. there way expand vector recursively?
if cannot put empty starting vector in function, should pass input argument.
this top level code example:
e = []; e = myrecursivefunction(e,inputs,stoppingcriteria)
Comments
Post a Comment