Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Using while loop to generate number according to series function

1 Ansicht (letzte 30 Tage)
Delaney Andersen
Delaney Andersen am 5 Nov. 2018
Geschlossen: John D'Errico am 5 Nov. 2018
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.

Antworten (0)

Diese Frage ist geschlossen.

Tags

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by