How to sum the previous 4 terms of a series?

3 ビュー (過去 30 日間)
Shazil
Shazil 2024 年 11 月 26 日
回答済み: Drishti 2024 年 11 月 26 日
Sorry if this is a basic question, but i am just beginning to learn matlab. I want to sum the previous 4 terms of a sequence [0,1,2,3,6,12...] and calculate up to 20 of these "four previous # sums". How would I do this?

回答 (1 件)

Drishti
Drishti 2024 年 11 月 26 日
Hi Shazil,
To compute a new term in the sequence using the previous four terms, you can use iterative statements such as the 'for' loop in MATLAB.
For better understanding you can refer to the MATLAB Documentation of 'for' loop:
Furthermore, you can refer to the below code snippet to get started with your solution:
% for calculating a new term in the sequence
nextTerm = sum(sequence(i-4:i-1));
I hope this helps in resolving your query.

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by