
Homework #6 for MATH/CSCI 407
Due March 9th, 2009
There are four problems in total (100 points). Please summarize your plots and results concisely. Please
attach your MATLAB code in separate sheets.
1. (20 points)
Determine the straight line that best fits the following data in the least squares sense:
i xifi
0−2 7
1−1 4
2 0 2
3 1 4
4 2 7
2. (30 points)
Write a Matlab function,
linear least squares(x, f )
whose input is the data set {(xi, fi)}N
i=0. Your function should be able to
•find the linear function that best fits the given data set in the least squares sense
•plot the data points, as well as the linear least squares fitting for the data set.
Use your code to
•solve Problem 1 (please check if your solution for Problem 1. is consistent with that produced
from your Matlab code),
•plot the data set and the linear least squares fitting.
3. (30 points)
Write a Matlab function,
quadra least sq uares(x, f )
whose input is the data set {(xi, fi)}N
i=0. Your function should be able to
•find the quadratic function that best fits the given data set in the least square sense
•plot the data points, as well as the quadratic least squares fitting for the data set.
Apply your code to the following data set and plot your quadratic least squares fitting with the data.
xiyi
0 2
3 5
5 6
8 9
10 11
4. (20 points)
Determine the least squares solution of the inconsistent system of linear equations:
2x+y= 1
x−y=−1
x−2y=−3
1