You are on page 1of 1

Research Institute in Economics and Finance

Summer School in Economics and Finance 2023


Computational Economics
Instructor: César Salinas

Problem Set

Instructions

• You must work in groups of 4 to write a Python code and answer the questions below.

• You are required to upload your code (a Jupyter Notebook) through Canvas with your solution by
11:59pm on January 7.

• Make sure your code works and add comments indicating the steps and logic you used in your functions,
so it is easier for me to understand.

1. Write a function that computes the ordinary polynomial interpolation using the collocation approach. Call
this function pol_interp(x,f,xn) with

(a) Input. The values of the unknown function (x,f) and the values we want to interpolate for (xn).
(b) Output. The values of the interpolated function.

Your function should be general enough so it can be used for any (x,f) values. Use the following data
points to check the accuracy of your interpolation function:

x = [0, 1, 2, 3, 4, 5, 6] (1)
f = [0, 0.8415, 0.9093, 0.1411, −0.7568, −0.9589, −0.2794]

Note: You just need to focus in the case where the number of given points (x) is equal to the number of
nodes of the polynomial.

2. Now assume we have more data points than the number of nodes of the polynomial we want to use for
interpolation. Write a function that computes the ordinary polynomial interpolation using the regression
approach. Call this function pol_interp_reg(x,f,xn,m) with

(a) Input. The values of the unknown function (x,f), the values we want to interpolate for (xn), and
the number of nodes of the polynomial we want to use (m).
(b) Output. The values of the interpolated function.

Your function should be general enough so it can be used for any (x,f,m) values, but you can use the data
points in (1) to check the accuracy of your interpolation function.

You might also like