フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Using while loop to generate number according to series function

1 回表示 (過去 30 日間)
Delaney Andersen
Delaney Andersen 2018 年 11 月 5 日
閉鎖済み: John D'Errico 2018 年 11 月 5 日
For the following problem, I have completed the first part using vectors, but I am not sure how to complete the second part. A.k.a., I do not know how to generate the single value independent of the vector using a while (or for if needed) loop.
Part 1 Consider the following sequence of numbers [ p0 p1 p2 ...] generated using the recurrence relation: p(sub n) = 2p(subn-1) + p(subn-2), n = 2,3,... with p(sub 0) = 0 and p(sub 1) = 1. Notice that in Mathematics as in computer science, the first item of a sequence of quantity is labelled by 0, the second item is labelled by 1, etc. This is certainly not the case in Matlab or in everyday usage. In this problem generate the sequence of these numbers up to and including the mth member, and store them in a row vector. The value for m must be entered by the user during runtime. For example, for m = 11, the vector is given by [ 0 1 2 5 12 29 70 169 408 985 2378 ]. Display the resulting vector. Part 2 Redo the above problem, but this time we are only interested in producing the m-th member of the sequence. For example, if m = 11 then the result is the number 2378. This time you are not allowed to use any vectors or matrices at all. Vector operations are therefore also not allowed. Only scalars are allowed. Display the last member of the sequence.

回答 (0 件)

この質問は閉じられています。

タグ

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by