Effacer les filtres
Effacer les filtres

generate a summation series

5 vues (au cours des 30 derniers jours)
Odien
Odien le 13 Août 2015
3(2+1)+4(3+2+1)+5(4+3+2+1)+6(5+...1)+...+1000(999+...+1).
How to write a matlab code to calculate the following summation without using for loop?
i can see the trend for 3(2+1) if the n = 1 (n+2)[((n+2)-1)+((n+2)-2)].
Assume the summation only sum until 6th term.
can we use array to solve this?
  2 commentaires
ibraheem kanai
ibraheem kanai le 5 Juin 2021
Walter Roberson
Walter Roberson le 5 Juin 2021
Modifié(e) : Walter Roberson le 12 Juin 2021

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 13 Août 2015
Modifié(e) : Stephen23 le 13 Août 2015
>> X = 1+cumsum(2:999); % 1+[2,3+2,4+3+2,...,999+..+2]
>> Y = 3:1000; % [3,4,5,...,1000]
>> sum(X.*Y)
ans = 125083208248
Note that this uses element-wise multiplication.
  2 commentaires
Odien
Odien le 13 Août 2015
Thank you !
Walter Roberson
Walter Roberson le 13 Août 2015
This looks like it was homework to me...

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 13 Août 2015
It does have a symbolic answer that you could find using nested symsum() if you have the symbolic toolbox.
But for a numeric answer: cumsum() and multiply by something gives a bunch of terms...

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by