Professional Documents
Culture Documents
Laboratory Activity 6 - Curve Fitting
Laboratory Activity 6 - Curve Fitting
Laboratory Activity 6 - Curve Fitting
6
Curve Fitting
Name: Section:
Date Performed: Date Submitted:
Instructor:
1. Objective(s):
1.1 To find the best equations that would fit to a series of data points using MATLAB
1.2 To solve some applications for the linear and polynomial regression using MATLAB
3. Discussion:
Curve fitting is a technique of finding an algebraic relationship that “best” (in least squares sense) fits a
given set of data. Unfortunately, there is no magical function (in MATLAB or otherwise) that can give the
relationship if we simply supply the data. We have to have an idea of what kind of relationship might
exist between the input data and the output data. However, if we do not have the firm idea but have data
that we trust, MATLAB can help us in exploring the best possible fit.
MATLAB includes Basic Fitting in its Figure window’s Tools menu that lets us fit a polynomial curve (up
to 10th order) to the data on the fly. It also gives us options of displaying the residual at the data points
and computing the norm of the residuals. This can help in comparing different fits and then selecting the
one that best fits.
[ ]
0 7 23 19 11
18 14 1 5 22
6 20 1713 4
12 3 9 2115
24 16 10 2 8
4. Procedure:
LINEAR REGRESSION
x 1 2 3 4 5
y 1 2 4 4 6
>> x=[1 2 3 4 5]
then input y,
>> y=[1 2 4 4 6]
then type
>> polyfit(x,y,1)
2. To show the graph of the following points, On your command window, type the following
>> plot(x,y)
to show the graph of the linear regression, on the figure go to “Tools” ≫ “Basic Fitting” ≫ check “linear
≫ check “show equations”
then input y,
then type
>> polyfit(x,y,2)
2. To show the graph of the following points, On your command window, type the following
>> plot(x,y)
to show the graph of the linear regression, on the figure go to “Tools” ≫ “Basic Fitting” ≫ check
“quadratic” ≫ check “show equations”
x -5 -1 3 7 9 13
y 10 8 6 4 5 -2
EXERCISES
x 1 2 3 3 4 4 5 6
y 0 0 0 1 1 2 2 2
x 0.75 2 3 4 6 8 8.5
x 3 4 5 7 8 9 11 12
x 3 4 5 7 8 9 11 12
x 5 10 15 20 25 30 35 40 45 50
y 17 24 31 33 37 37 40 40 42 41
5. A hardware retailer wants to know the demand for a rechargeable power drill as a function of price.
The ordered pairs (25, 82), (30, 75), (35, 67), and (40, 55) represents the price x (in dollars) and the
corresponding monthly sales y.
_______________________________________
Rating =
(Total Score / 21)