Reference no: EM133640088
Scientific Computing
Instruction:
You may use MATLAB or Python for writing your programs. You are allowed to use the library function for calculating the matrix inverse, but are not allowed to use any library functions for calculating the pseudo or Moore-Penrose inverse.
Upload all your programs to the homework dropbox (do not put this in a word document or a pdf file. I'll should be able to run your programs for evaluation)
Learning Objective: To understand that there may exist a unique solution for a square matrix system of equations (using matrix inverse) and there exists a unique least squares solution to a rectangular matrix system of equations when there are more number of training data than the number of unknown model parameters to be estimated.
Homework Problem:
1. Write a program to determine a unique polynomial function y(x) that passes through all the given data {(x1, y1), . . . , (xn, yn)}, for an arbitrary choice of n. Confirm that your estimates of the model parameters agree with the data by plotting the model predicted values of yi for various values of xi.
Data Generation : To evaluate your algorithms (programs), generate test data
{(xi, yi)}i=1n that has a cubic relationship as follows:
(a) Let the underlying relationship between variables xi (independent) and yi (dependent) be cubic. i.e. yi = β0 + β1xi + β2x2 + β3x3.
(b) Choose any non-zero values for the model parameters β0, β1, β2 and β3.
(c) Generate exactly 4 unique data points from the cubic model: {(xi, yi)}4i=1, where yi = β0 + β1xi + β2x2 + β3x3. For example, choosei xi = {-2, 0, 2, 4} ; β0 = 3; β1 = -1; β2 = -3 and β3 = 1 and estimate the model predicted values yi. i.e. these data points lie exactly on the cubic model. (ancillary question: how should one choose {xi}4i=1 for simulating the data governed by the model?)
Model validation
(a) Plot the data {(xi, yi)}4 i=1 used for estimating the model parameters {βi, i = 0, . . . , 3}
(b) Once the model parameters are estimated, estimate yˆi for {xi = -2, -1.9, -1.8, . . . , -0.1, 0, 0.1, . . . , 3.8, 3.9, 4.0}
(c) In the same figure, plot the data {(xi, y^i)} predicted by the model in the previous step.
(d) Write your observations from the plot as well as by comparing your parameter estimates with the true model parameters.
Question 1: Write a program to determine a polynomial function y(x) that passes through all the given data {(x1, y1), . . . , (xn, yn)} in a least squared error sense as discussed in class (for an arbitrary choice of n). Confirm that your estimates of the model parameters agree with the data by plotting the model predicted values of yi for various values of xi
Data Generation : To evaluate your algorithms (programs), generate test data {(xi, yi)}ni=1 that has a cubic relationship as follows:
a) Same as in the first problem.
b) Same as in the first problem.
c) Same as in the first problem.
d) Add random variations to each of the data points as follows:
yi = β0 + β1xi + β2x2 + β3x3 + ∈i, where the random variable ∈i follows a normal distribution with 0 mean and σ standard deviation. i.e. ∈i ∼ Normal(0, σ2). You can choose any variance σ, e.g. σ = 2. Hint: In Matlab, you can use eps = normrnd(mu, sigma, n) to draw n random ∈i from a normal distribution with mean mu = 0 and standard deviation sigma.
Model validation:
(a) Plot the data {(xi, yi)}4i=1 used for estimating the model parameters {βi, i = 0, . . . , 3}
(b) Once the model parameters are estimated, estimate yˆi for {xi = -2, -1.9, -1.8, . . . , -0.1, 0, 0.1, . . . , 3.8, 3.9, 4.0}
(c) In the same figure, plot the data {(xi, yˆi)} predicted by the model in the previous step.
(d) Write your observations from the plot as well as by comparing your parameter estimates with the true model parameters.