Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Control flow and functions are a basic aspect of every computer language. In R you can use loops with the following syntax: for (A in

image text in transcribed

Control flow and functions are a basic aspect of every computer language. In R you can use loops with the following syntax: for (A in B) { C}. Here, if A is a variable name, and 'B' is a vector and 'C' is an expression, then the expression will be evaluated once for each element of the vector 'B' (and the variable A may be used in the expression 'C' and the value of A will walk through all elements of the vector B). You can define and call functions with the syntax A = function(B) { C; return(D); }'. In this code, A is now a function that takes one argument, and 'C' and 'D' are expressions that may refer to B. You can call the function A using code like A(7)'. Here's an example: A = function(B) { C = B + 7; return(C) } A (22) The result of A(22) should be 29, does that make sense? Question 5a, (3 points): Fibonacci numbers. The first two Fibonacci numbers are both 1 (f1 = f2 = 1). The n-th Fibonnaci number fn (for n > 2) is fn = fn-1 + fn-2. Write R code to compute the sum of the first 20 Fibonacci numbers. You may use recursive functions, or you may use Cramer's rule for linear equations. Provide the sum of the first 20 Fibonacci numbers. Question 5b, (1 point): Provide the R code you used to compute the previous answer. Question 5c, (1 bonus point): Provide an estimate of the logarithm of the sum of the first one million Fibonacci numbers, in scientific notation with 4 digits in the significand. Please use R to generate the answer. Thank you

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

25 Vba Macros For Data Analysis In Microsoft Excel

Authors: Klemens Nguyen

1st Edition

B0CNSXYMTC, 979-8868455629

More Books

Students also viewed these Databases questions