Recursive Summation indices stuck?
Show older comments
So I had to write a summation of S(n)=1 + 2^p + 3^p +...+ n^p
using recursive algorithms.
So far I have managed to do it without the 'p'
function y = SumR(n)
y = n ;
if n == 0
y = 0 ;
else
y = y + SumR(n-1);
end
end
yet obviously this doesn't give the answer, so I tried this instead but it doesnt seem to work annoyingly,
function y = S(n,p)
y = n ;
if n == 0
y = 0 ;
p = 0;
else
y = y + (S(n-1))^p;
end
end
yet obviously its apparently not that simple, any help would be great thanks
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!