Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Using while loop to generate number according to series function
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (0개)
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!