i'm having problem in matlab: maximum recursion limit of 500 reached 1 of functions being called lot. frustrating. there lot problem on web. i've looked , there no single real solution problem. increasing recursion limit using set(0,'recursionlimit',n) not because after , run code, matlab crashes (and crashes value n ii put)
fyi, code supposed call 1 of functions way more 500 times, there nothing wrong it. there way increase recursion limit on matlab (without having crashing) or better make no limit?
to there nothing wrong 500-fold recursion may wrong in itself.
a problem recursion matlab must set separate workspaces each time function called, building stack of them. can quite inefficient, using fair amount of time memory. there may wrong doing.
as well, i've seen recursive functions can re-written not recursive. techniques memoization can employed avoid recursively evaluating function on same inputs many times over. why same computations more once?
you can change limits on stack size, limits quite reasonable, , put there prevent memory , time problems. far better off looking @ code decide if such change appropriate rather reformulating problem.
for example, can compute factorials using recursion, why bother? extremely silly solution when simple loop far more efficient. overhead of stacks far more want expend when loop ample problem.
another example fibonacci sequence. can written recursively, easy thing do, not make @ thing do. computed recursively, n'th fibonacci number require exponential time , memory compute f(n). loops better, allow o(n) amount of work. better yet, memoization schemes coupled proper identities allow computation of f(n) in o(log2(n)) time.
the point is, can solve many problems recursion, not mean right way so.
Comments
Post a Comment