How to sum the previous 4 terms of a series?

3 visualizaciones (últimos 30 días)
Shazil
Shazil el 26 de Nov. de 2024
Respondida: Drishti el 26 de Nov. de 2024
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?

Respuestas (1)

Drishti
Drishti el 26 de Nov. de 2024
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.

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by