How to sum the previous 4 terms of a series?
3 ビュー (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
回答 (1 件)
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!