Problem finding sum of array using vectorization
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Trying to find the sum of this array using vectorization, the value of the sum should be 0.74 but when I run it I am getting 'ans = -Inf'. Where am I going wrong?
x = sym(1) ./ (1:9)
1 - sum( +1./((x)-1) ./ x )
0 Kommentare
Antworten (1)
James Tursa
am 15 Dez. 2021
The first element of x is 1, so that element produces 1/(1-1) = 1/0 = inf in the second line. You need to rewrite that second line.
2 Kommentare
James Tursa
am 15 Dez. 2021
Bearbeitet: James Tursa
am 15 Dez. 2021
You just need a vector that alternates +1, -1, +1, -1, etc. to use for the sign, right? Hint: Start with mod(1:9,2) and see if you can manipulate it into what you want.
Siehe auch
Kategorien
Mehr zu Matrices and Arrays 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!