I had to find the sum of the series 1/2+(1/2)^2+....(1/2)^100
why does my code not work?
(ones(1,100).*1/2).^([1:100])
it gives the answer zero.

 채택된 답변

Mischa Kim
Mischa Kim 2014년 10월 27일
편집: Mischa Kim 2014년 10월 27일

0 개 추천

Airas, use
f = sum(arrayfun(@(x) 0.5^x,1:100))
or, with your approach, add the sum()
f = sum((ones(1,100).*1/2).^([1:100]))

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Dynamic System Models에 대해 자세히 알아보기

태그

질문:

2014년 10월 27일

편집:

2014년 10월 27일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by