필터 지우기
필터 지우기

generate a summation series

조회 수: 5 (최근 30일)
Odien
Odien 2015년 8월 13일
편집: Walter Roberson 2021년 6월 12일
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
ibraheem kanai
ibraheem kanai 2021년 6월 5일
Walter Roberson
Walter Roberson 2021년 6월 5일
편집: Walter Roberson 2021년 6월 12일

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
Stephen23 2015년 8월 13일
편집: Stephen23 2015년 8월 13일
>> 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
Odien
Odien 2015년 8월 13일
Thank you !
Walter Roberson
Walter Roberson 2015년 8월 13일
This looks like it was homework to me...

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2015년 8월 13일
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...

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by