I am trying to create a recursive formula to calculate the double factorial of a number, n. The code I have come up with currently is as follows:
function [DFact] = DFactorialRec(n) DFact = n*DFactorialRec(n-2) end
This clearly does not work as it will recursively continue for negative values of n. Please could someone suggest an alteration to stop the memory overflow error?
================================================================
Out of memory. The likely cause is an infinite recursion within the program.
Error in DFactorialRec (line 2)
DFact = n*DFactorialRec(n-2)
================================================================
Thanks!
Best Answer