How to sum the previous 4 terms of a series?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
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.
0 comentarios
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!