I'm trying to make more sense of recursive code as I have only very recently started using matlab. I was wondering how I would go about finding the sum of all real numbers up to x using recursive code, I have done it using if / for / while loops however after trying to self teach myself I would expect to go about this by:
function y = sum(x) if x > 0 y = x * (x+1) / 2 end elseif x <= 0 y = 'does not exist' end enddisp(y)
I understand that I am probably wrong, in which case how would I go better about this task. Any help would be appreciated.
Best Answer