How to display the nth term where the nth term is found by adding x number previous term?

조회 수: 4 (최근 30일)
I am trying to write code that will ask the user to input n and x. The sequence is similar to the fibonacci sequence, but instead of adding the previous 2 terms, I want to find the next term by adding the previous x number of terms. I then want it to display the nth term of this sequence, also inputted by the user.

답변 (1개)

John D'Errico
John D'Errico 2021년 8월 19일
Admit it. This is homework, since nobody would ask you to do this if it were not. And since it is homework, NOBODY should write the code for you. It is YOUR homework.
But I'll give you some hints.
  1. Can you create a vector of length x? I hope so.
  2. Can you sum all the elements in a vector? Again, if you cannot, then did you fall asleep in class that month?
  3. Can you now create a NEW vector, that contains elements 2:x of the vector, and then append the sum you formed in step 2?
  4. Can you iterate steps 2:3 until you are done? Hint, what does a loop do?

카테고리

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

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by