Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please solve it in Rstudio. Thank you! Problem 6 Control flow and functions are a basic aspect of every computer language. In R you can

image text in transcribed

Please solve it in Rstudio.

Thank you!

Problem 6 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() { C = B + 7; return(C) } A(22) [1] 29 Does it make sense to you that A(22) is 29? What would A(22) be if we changed the text return(C) to return(C*2)? Or to return(B)? Question 6a, (3 points): Fibonacci numbers. The first two Fibonacci numbers are both 1 (f1 = f2 = 1). The n-th Fibonnaci number n (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 6b, (1 point): Provide the R code you used to compute the previous answer. Question 6c, (1 bonus point): Provide an estimate of the logarithm of the sum of the first one million Fibonacci numbers, in scientific notation with 4 significant figures

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

Database Fundamentals Study Guide

Authors: Dr. Sergio Pisano

1st Edition

B09K1WW84J, 979-8985115307

More Books

Students also viewed these Databases questions