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

3 ビュー (過去 30 日間)
MATLAB
MATLAB 2021 年 8 月 19 日
回答済み: John D'Errico 2021 年 8 月 19 日
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 Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by