Assignment date: 08.12.
2009
Due date: 21.12.2009, 00:00
Prepared by: Mine Cuneyitoglu (C-210)
Middle East Technical University
Mechanical Engineering Department
ME 310 Numerical Methods
Fall 2009
Programming Project Assignment 3
• This assignment will be collected and graded.
• This assignment will be submitted through METU-Online, as described in the “Programming Project
Assignment Guidelines”, which is posted on the course website and METU-Online.
th
Write a program that finds the least squares regression polynomial of m order for any given data set
as input. The data set is composed of x and y row vectors, each having a length n. The expected
output of your program should include:
1. The coefficients of the regression polynomial, which are defined as follows:
a0 + a1 x + a2 x 2 + ... + am x m
2. The correlation coefficient, which can be calculated for polynomial least squares regression
as follows:
St − S r
r=
St
3. Standard error of the estimate, which can be calculated as follows:
Sr
sy/ x =
n − (m + 1)
4. Plot of the actual data set and the mth order least squares regression polynomial function.
Your program should be called in the Matlab command window using the following format:
>> function [poly_coeffs, corr_coef, err_est] = exxxxxx(m,x,y)
where exxxxxx is the student id, m is the desired degree of the least squares polynomial, x and y are
row vectors containing the given data sets, poly_coeffs is the row vector containing the coefficient
of least squares polynomial, corr_coef is the variable for the correlation coefficient, and err_est is
the variable for the standard error of estimate.
Output of your program should look like as follows:
ME 310 Numerical Methods - Fall 2009
Programming Project Assignment - 3
Name & Surname : xxx xxx
Student ID : xxxxxxx
Regression Polynomial Coefficients:
poly_coeffs = [a0 a1 a2 ... am ]
(The coefficients above should be a row vector and should start from the coefficient of the lowest term and
should be in increasing order)
The correlation coefficient:
r = …
The standard error of estimate:
syx = …
Plot of the data (Only a figure as an output)
Note that your function should strictly have the following format and give three global Matlab variables
[poly_coeffs, corr_coef, err_est] as the output, i.e.:
% First line of your .m file
function [poly_coeffs, corr_coef, err_est] = exxxxxx(m,x,y)
In this way, your output variables will also be available in the global workspace of Matlab.
To test your program, you will be given a sample data set, which will be available on METU-ONLINE.
In your report, try different orders of m to fit a polynomial to the given data set and comment on the
results and the error estimation. You may also work with a data set of your own to test your code.
Additional notes:
• All of your plot operations should be handled in your .m file. The graphical output of your
program should be a Matlab figure.
• The plot should include the given data points and the line fitted by regression. Do not connect
the given data points with each other. Just plot them as points or markers.