1. A sequence of numbers can be defined recursively, that is the next number can be defined as a function of one or more of the previous numbers (the Fibonacci Sequence is a well known example of this). A recursive sequence is given by the recursive formula Xn = 3xn-1+ 2x,n–2 where 11 = 1 and x2 = 1. (a) Write a small program, using a loop, to calculate and display the first 10 terms, a1,..., x10- If we do not need to store past results for (say) plotting purposes we do not need to save past values. In your code do not create a vector of these values, that is do not use subscripts( ie x(1), x(2) etc) in your code. The calculation that is repeated, ie xn = 3xn-1+2xn-2, has the form c= 36 + 2a. You should update the values in a and b (as the relevant older values) each time through the loop after c has been calculated. (b) Now create a version where you do create a vector saving the values of xn and then plot these values against n using a semi-log axis (log in the "y-axis"). Give the plot a title and tight axis and use '.-r' dictates that we join the dots with lines and use the colour read.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 1TF
icon
Related questions
Question

Please solve this problem using Matlab

1. A sequence of numbers can be defined recursively, that is the next number can be defined as
a function of one or more of the previous numbers (the Fibonacci Sequence is a well known
example of this). A recursive sequence is given by the recursive formula
Xn = 3xn-1 + 2xn-2
where r1 = 1 and r2 = 1.
(a) Write a small program, using a loop, to calculate and display the first 10 terms, x1,... , x10-
If we do not need to store past results for (say) plotting purposes we do not
need to save past values. In your code do not create a vector of these values,
that is do not use subscripts( ie x(1), x(2) etc) in your code. The calculation
that is repeated, ie xn = 3xn-1+ 2xn-2, has the form c = 36 + 2a. You should update
the values in a and 6 (as the relevant older values) each time through the loop after c
has been calculated.
(b) Now create a version where you do create a vector saving the values of xn and then plot
these values against n using a semi-log axis (log in the "y-axis"). Give the plot a title
and tight axis and use '.-r' dictates that we join the dots with lines and use the colour
read.
Transcribed Image Text:1. A sequence of numbers can be defined recursively, that is the next number can be defined as a function of one or more of the previous numbers (the Fibonacci Sequence is a well known example of this). A recursive sequence is given by the recursive formula Xn = 3xn-1 + 2xn-2 where r1 = 1 and r2 = 1. (a) Write a small program, using a loop, to calculate and display the first 10 terms, x1,... , x10- If we do not need to store past results for (say) plotting purposes we do not need to save past values. In your code do not create a vector of these values, that is do not use subscripts( ie x(1), x(2) etc) in your code. The calculation that is repeated, ie xn = 3xn-1+ 2xn-2, has the form c = 36 + 2a. You should update the values in a and 6 (as the relevant older values) each time through the loop after c has been calculated. (b) Now create a version where you do create a vector saving the values of xn and then plot these values against n using a semi-log axis (log in the "y-axis"). Give the plot a title and tight axis and use '.-r' dictates that we join the dots with lines and use the colour read.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Computational Systems
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage