how to sum a vector without sum func
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
yuval ohayon
am 27 Jul. 2017
Kommentiert: Jan de Jong
am 31 Jul. 2017
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 Kommentar
James Tursa
am 27 Jul. 2017
Bearbeitet: James Tursa
am 27 Jul. 2017
Maybe use plus and minus functions? What have you done so far?
Akzeptierte Antwort
Star Strider
am 28 Jul. 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 Kommentare
Weitere Antworten (2)
Jan
am 28 Jul. 2017
What about:
v = 19^3 - 17^3 + 15^3 - 13^3 + 11^3 - 9^3 + 7^3 - 5^3 + 3^3 - 1^3;
0 Kommentare
Jan de Jong
am 31 Jul. 2017
Bearbeitet: Walter Roberson
am 31 Jul. 2017
Or a little more general:
val = [19:-2:1]'; sig = -cos(pi*[1:10]);
s = sig*val.^3;
2 Kommentare
Jan de Jong
am 31 Jul. 2017
It will give an alternating sequence to account for the sign change in the sum.
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!