程序代写代做代考 algorithm Bonus points sheet

Bonus points sheet
Winter term 2020/2021
Computational Economics
(version: 15. Oktober 2020)
1. The deadline for this sheets ends on January 31, 2021 (end of day). Submission is via Ilias.
2. Handwritten program code is not allowed! Submission must be a PDF with proper R-Code!
3. This sheet contains in total 7 questions. All questions cover in total 7 pages.
4. You receive 9 points (i.e., 10 %) as bonus points for the exam if 50 % (or more) are correctly answered. However, these points are only added if you pass the ex- am without bonus points.The bonus points cannot prevent you from failing the exam!
5. Group work is not allowed. Plagiarism can lead to exclusion from the exam.
6. Please label the submission document with your name, matriculation number, and program of study.
Good luck!
Ex. 1
Ex. 2
Ex. 3
Ex. 4
Ex. 5
Ex. 6
Ex. 7
Total
Pass
7
8
15
4
8
4
9
55

Exercise 1: Visualization
a) Createacoloredplotwithcontoursofthefunctionf(x,y)= x2 +sinx+y2 −cosy. 22
Both x- and y-dimension should range from −10 to 10.
b) Prepare a 3D plot of the function f (x, y) = sin2 x − cos2 y.
4
3
Page: 1 of 7

Exercise 2: Dataframes
a) Load the csv file persons2.csv into a dataframe.
• Insert a column bmi which indicates the body mass index (BMI) of the person
which is defined as bmi = weight in kg (height in m)2
• A BMI between 19 and 24 is considered to be normal. Which person does not have a normal BMI?
• Create a histogram of the BMI with step size one. Choose reasonable scales and labels for x and y-axis.
8
Page: 2 of 7

Exercise 3: Control Flow
a) Write a for-loop that calculates the following sum s(n)=􏰂n 1.
i=0 2i
Test your loop with n = 10.
b) Write a function that tests if a positive integer n can be written as sum of two squared integers, i. e. n = i2 + j2 with i, j ∈ N>0. Test your function for the integer n = 100.
Page: 3 of 7
5
10

Exercise 4: Linear Algebra
a) The solution of a linear system
is often rewritten as minimizing a function
F (x) = ∥Ax − b∥2 . We can calculate the gradient to
∇F(x) = 2AT (Ax − b). Write a matrix expression in R to compute ∇F (x) for
􏰀1 2􏰁 􏰀5􏰁 􏰀−1􏰁
A= , b= and x= . 0341
Ax = b
4
Page: 4 of 7

Exercise 5: Numerical Analysis
a) Convert the number 243043 from base 10 into the hexadecmal. State the correspon- ding R code.
b) Visualize the function f (x) = ex + e−x and its Taylor approximation for x0 = 1
Use an x-axis ranging from −5 to 5 and y-axis from 0 to 20.
1
7
Page: 5 of 7

Exercise 6: Optimality Conditions
􏰀− 9 􏰁
a) Verify that x = 22 is a minimum of the function −2
11
f(x1,x2)=3+2×1 +3×2 +2×21 +2x1x2 +6×2.
State the corresponding R code.
4
Page: 6 of 7

Exercise 7: Optimization
a) Implement the one-dimensional Newton’s method to find a local extreme point of a function f (x) given a starting point x(0) and a tolerance ε. Stop the algorithm, when |x(i) − x(i−1)| < ε. Complete the following R code. 9 library(Deriv) f = function(x) x**2 * sin(x-3) * exp(-0.5*x) f.prime = # TODO f.double.prime = # TODO newton = function(f.prime, f.double.prime, x0, tol) { # TODO } newton(f.prime, f.double.prime, 5, 10**-6) Page: 7 of 7