how to sum a vector without sum func

given this elements:19^3 −17^3 +15^3 −13^3 +11^3 −9^3 +7^3 −5^3 +3^3 −1^3 notice the sign changing 9 times with 10 element again without sum function\ anyone idea?

1 comentario

James Tursa
James Tursa el 27 de Jul. de 2017
Editada: James Tursa el 27 de Jul. de 2017
Maybe use plus and minus functions? What have you done so far?

Iniciar sesión para comentar.

 Respuesta aceptada

Star Strider
Star Strider el 28 de Jul. de 2017
The elements are cubed, so the signs are conserved.
This works:
v = [19^3 -17^3 +15^3 -13^3 +11^3 -9^3 +7^3 -5^3 +3^3 -1^3];
sum_v = v*ones(numel(v),1)
Check = sum(v) % Check
sum_v =
3970
Check =
3970

2 comentarios

yuval ohayon
yuval ohayon el 28 de Jul. de 2017
star its look like the right answer, the function ones(10,1} is a column vector?
Star Strider
Star Strider el 28 de Jul. de 2017
Yes.
The ‘ones(length(v),1)’ call forms a (10 x 1) column vector.

Iniciar sesión para comentar.

Más respuestas (2)

Jan
Jan el 28 de Jul. de 2017
What about:
v = 19^3 - 17^3 + 15^3 - 13^3 + 11^3 - 9^3 + 7^3 - 5^3 + 3^3 - 1^3;
Jan de Jong
Jan de Jong el 31 de Jul. de 2017
Editada: Walter Roberson el 31 de Jul. de 2017
Or a little more general:
val = [19:-2:1]'; sig = -cos(pi*[1:10]);
s = sig*val.^3;

2 comentarios

yuval ohayon
yuval ohayon el 31 de Jul. de 2017
Im sorry im not aware to -cospi×[1:10] Explain me please
Jan de Jong
Jan de Jong el 31 de Jul. de 2017
It will give an alternating sequence to account for the sign change in the sum.

Iniciar sesión para comentar.

Categorías

Más información sobre Debugging and Analysis en Centro de ayuda y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Preguntada:

el 27 de Jul. de 2017

Comentada:

el 31 de Jul. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by