Recursive Summation indices stuck?
이전 댓글 표시
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
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!