Professional Documents
Culture Documents
Laboratory Activity 6 Curve Fitting 1
Laboratory Activity 6 Curve Fitting 1
6
Curve Fitting
Name: Lahom, Section: CHE31S1
Date Performed: 06/10/21 Date Submitted: 06/12/21
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 1911 18 14 1 5 226 20 17 13 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)
y=1x+0.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 “linear
≫ check “show equations”
Copy the figure shown on MATLAB
then input y,
then type
>> polyfit(x,y,2)
Write the equation:
y=1x^2 + (1.304^15)x-8.937^-16
ans =
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
ans =
x 1 2 3 3 4 4 5 6
y 0 0 0 1 1 2 2 2
y=0.5000x - 0.7500
ans =
0.5000 -0.7500
x 0.75 2 3 4 6 8 8.5
ans =
x 3 4 5 7 8 9 11 12
ans =
x 3 4 5 7 8 9 11 12
ans =
x 5 10 15 20 25 30 35 40 45 50
y 17 24 31 33 37 37 40 40 42 41
y=0.4945x+20.6
ans =
0.4945 20.6000
y= -1.7800x + 127.6000
ans =
-1.7800 127.6000
y= -1.7800(32.95) + 127.6000
= 68.949
5. Conclusion:
In conclusion, the Matlab software/application is a very useful tool to plot the processed data in a curve
or line. It helps prevent human error and gives more precise results. It also makes processing it easier
and faster rather than manually doing it by hand.
6. Assessment (Rubric for Activity Performance):
Rating =
(Total Score / 21)