Iterative Fibonacci (while loop, perils of integer arithmetic) The Fibonacci sequence defined by F=1,1,2, 3, 5, 8, 13, 21, 34, 55, 89, ... where the 4th term is given by F₁ = F₁-1+Fx-2 As k increases, the ratio of two adjacent terms in the sequence approaches the Golden Ratio, F₂ =drp. The goal of this problem is to generate Fibonacci numbers until the absolute value of the difference between subsequent computations of the Golden Ratio falls below a given tolerance. My Solutions E = |x-₁-1- Code has already been provided to define a function named fibGenerator that accepts a single input value into the variable to1GR. Add code that uses a while loop to generate Fibonacci numbers until the error E in subsequent calculations of is less than or equal to the value of to1GR. Your function should assign values to three output variables as follows. 1. Assign the final calculated value of the Golden Ratio to the variable GoldenRatio with default double precision datatype. 2. Assign the largest Fibonacci number generated to the variable lastFib with 32-bit unsigned integer datatype. 3. Assign the number of terms required to meet the tolerance to the variable numTerms with 8-bit unsigned integer datatype. Note the value of to1GR is defined as an input to the function. Do not overwrite this value in your code. Be sure to assign values to each of the function output variables. Use a while loop in your solution.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter10: Classes And Data Abstraction
Section: Chapter Questions
Problem 19PE
icon
Related questions
Question
Function >
1 function [GoldenRatio, lastFib, numTerms] = fibGenerator (tolGR)
%write the commands for your function here.
Code to call your function >
1 [GoldenRatio, lastFib, numTerms] = fibGenerator (1e-3)
Assessment:
>
Is the first output GoldenRatio correct for input of tolGR = 1e-3? (Pretest)
>
Is the second output lastFib correct for input of toIGR = 1e-3? (Pretest)
>
Is the third output num Terms correct for input of tolGR = 1e-3? (Pretest)
Are all three outputs correct for an input of toIGR = 1e-6?
Does solution use a while loop?
Save
C Reset
EEMATLAB Documentation
Run Pretest
C Reset
▶ Run Function ?
Submit ?
Transcribed Image Text:Function > 1 function [GoldenRatio, lastFib, numTerms] = fibGenerator (tolGR) %write the commands for your function here. Code to call your function > 1 [GoldenRatio, lastFib, numTerms] = fibGenerator (1e-3) Assessment: > Is the first output GoldenRatio correct for input of tolGR = 1e-3? (Pretest) > Is the second output lastFib correct for input of toIGR = 1e-3? (Pretest) > Is the third output num Terms correct for input of tolGR = 1e-3? (Pretest) Are all three outputs correct for an input of toIGR = 1e-6? Does solution use a while loop? Save C Reset EEMATLAB Documentation Run Pretest C Reset ▶ Run Function ? Submit ?
Iterative Fibonacci (while loop, perils of integer arithmetic)
The Fibonacci sequence defined by
F=1,1,2,3,5, 8, 13, 21, 34, 55, 89, ...
where the th term is given by
F₁ = F₁-1+F₁-2
As & increases, the ratio of two adjacent terms the sequence approaches the Golden Ratio, :
F₁
· = $x → ·
The goal of this problem is to generate Fibonacci numbers until the absolute value of the difference E between subsequent computations of the Golden Ratio falls below a given
tolerance.
My Solutions >
E = |dx-x-1|-
Code has already been provided to define function named fibGenerator that accepts a single input value into the variable to1GR. Add code that uses a while loop to generate
Fibonacci numbers until the error E in subsequent calculations of is less than or equal to the value of to1GR. Your function should assign values to three output variables as
follows.
1. Assign the final calculated value of the Golden Ratio to the variable GoldenRatio with default double precision datatype.
2. Assign the largest Fibonacci number generated to the variable lastFib with 32-bit unsigned integer datatype.
3. Assign the number of terms required to meet the tolerance to the variable numTerms with 8-bit unsigned integer datatype.
Note the value of to1GR is defined as an input to the function. Do not overwrite this value in your code. Be sure assign values to each of the function output variables.
Use a while loop in your solution.
Transcribed Image Text:Iterative Fibonacci (while loop, perils of integer arithmetic) The Fibonacci sequence defined by F=1,1,2,3,5, 8, 13, 21, 34, 55, 89, ... where the th term is given by F₁ = F₁-1+F₁-2 As & increases, the ratio of two adjacent terms the sequence approaches the Golden Ratio, : F₁ · = $x → · The goal of this problem is to generate Fibonacci numbers until the absolute value of the difference E between subsequent computations of the Golden Ratio falls below a given tolerance. My Solutions > E = |dx-x-1|- Code has already been provided to define function named fibGenerator that accepts a single input value into the variable to1GR. Add code that uses a while loop to generate Fibonacci numbers until the error E in subsequent calculations of is less than or equal to the value of to1GR. Your function should assign values to three output variables as follows. 1. Assign the final calculated value of the Golden Ratio to the variable GoldenRatio with default double precision datatype. 2. Assign the largest Fibonacci number generated to the variable lastFib with 32-bit unsigned integer datatype. 3. Assign the number of terms required to meet the tolerance to the variable numTerms with 8-bit unsigned integer datatype. Note the value of to1GR is defined as an input to the function. Do not overwrite this value in your code. Be sure assign values to each of the function output variables. Use a while loop in your solution.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Lower bounds sorting algorithm
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