how to sum a vector without sum func
Mostra commenti meno recenti
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 Commento
James Tursa
il 27 Lug 2017
Modificato: James Tursa
il 27 Lug 2017
Maybe use plus and minus functions? What have you done so far?
Risposta accettata
Più risposte (2)
Jan
il 28 Lug 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
il 31 Lug 2017
Modificato: Walter Roberson
il 31 Lug 2017
Or a little more general:
val = [19:-2:1]'; sig = -cos(pi*[1:10]);
s = sig*val.^3;
2 Commenti
yuval ohayon
il 31 Lug 2017
Jan de Jong
il 31 Lug 2017
It will give an alternating sequence to account for the sign change in the sum.
Categorie
Scopri di più su Debugging and Analysis in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!