How to find sum using single statement?

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.

 Respuesta aceptada

Mischa Kim
Mischa Kim el 27 de Oct. de 2014
Editada: Mischa Kim el 27 de Oct. de 2014
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]))

Más respuestas (0)

Categorías

Más información sobre Dynamic System Models en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 27 de Oct. de 2014

Editada:

el 27 de Oct. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by