Laboratory Activity 6 - Curve Fitting

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

Laboratory Activity No.

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

2. Intended Learning Outcomes (ILOs):

The students shall be able to:


2.1 Demonstrate scientific thinking and the ability to approach scientific resources intelligently.
2.2 Utilize MATLAB software in finding the best equations that would fit to a series of data points.
2.3 Infer appropriate conclusions based upon the results of activity.
2.4 Reflect on personal transformation along the TIP graduate attributes, specifically, professional
competence and critical thinking skills.

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

EXAMPLE 1: Fit a straight line y=a x+b to the following data

x 1 2 3 4 5

y 1 2 4 4 6

On your command window, input x

>> x=[1 2 3 4 5]

then input y,

>> y=[1 2 4 4 6]

then type

>> polyfit(x,y,1)

Write the equation ___________________________

2. To show the graph of the following points, On your command window, type the following

>> plot(x,y)

to rename the figure, type


>> title('linear regression')

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


EXAMPLE 2: Fit a quadratic equation y=a x2 +bx +c to the following data

x 0 0.5 1.0 1.5 2.0 2.5

y 0 0.25 1 2.25 4.0 6.25

On your command window, input x

>> x=[0 0.5 1.0 1.5 2.0 2.5]

then input y,

>> y=[0 0.25 1 2.25 4 6.25]

then type

>> polyfit(x,y,2)

Write the equation _____________________________

2. To show the graph of the following points, On your command window, type the following

>> plot(x,y)

to rename the figure, type


>> title('polynomial regression')

to show the graph of the linear regression, on the figure go to “Tools” ≫ “Basic Fitting” ≫ check
“quadratic” ≫ check “show equations”

Copy the figure shown on MATLAB


ACTIVITY

EXAMPLE 2: Fit a 5th degree polynomial functions to the following data

x -5 -1 3 7 9 13

y 10 8 6 4 5 -2

Write the equation _______________________________________

Show the graph

EXERCISES

1. Fit a straight line y=ax+ b to the following data

x 1 2 3 3 4 4 5 6

y 0 0 0 1 1 2 2 2

Write the equation _______________________________________

Show the graph


2. Fit a quadratic equation to the following data

x 0.75 2 3 4 6 8 8.5

y 1.2 1.95 2 2.4 2.4 2.7 2.6

Write the equation _______________________________________

Show the graph

3. Fit a cubic equation to the following data

x 3 4 5 7 8 9 11 12

y 1.6 3.6 4.4 3.4 2.2 2.8 3.8 4.6


Write the equation _______________________________________

Show the graph

4. Fit a cubic equation to the following data

x 3 4 5 7 8 9 11 12

y 1.6 3.6 4.4 3.4 2.2 2.8 3.8 4.6

Write the equation _______________________________________

Show the graph


5. Given these data

x 5 10 15 20 25 30 35 40 45 50

y 17 24 31 33 37 37 40 40 42 41

Use least-squares regression to fit a straight line _______________________________________

Show the graph

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.

a. Find the least squares regression line for the data.

_______________________________________

b. Estimate the demand when the price is $32.95.


5. Conclusion:

6. Assessment (Rubric for Activity Performance):

BEGINNER ACCEPTABLE PROFICIENT


CRITERIA SCORE
1 2 3
I. Activity Skills
Work that usually needs to have quality of work and Provides work of the
Quality of work be checked/redone by some small errors on the highest quality and answers
others to ensure quality answer are correct
Group is rarely focused on Group is focused on the Group is consistently stays
Focus on the
the task and what to be task and what needs to be focused on the task and
task
done done most of the time what needs to be done
Members do not Members occasionally Members always
Process Skills demonstrate targeted demonstrate targeted demonstrate targeted
process skills. process skills. process skills.
II. Work Habits
Time
Members finish ahead of
Management / Members do not finish on Members finish on time with
time with complete data
Conduct of time with incomplete data. incomplete data.
and time to revise data.
Experiment
Members are on tasks and
Members do not know their Members have defined
have defined
tasks and have no defined responsibilities most of the
Cooperative and responsibilities at all times.
responsibilities. Group time. Group conflicts are
Teamwork Group conflicts are
conflicts have to be settled cooperatively managed
cooperatively managed at
by the teacher. most of the time.
all times.
Clean and orderly Clean and orderly
Neatness and Messy workplace during workplace with occasional workplace at all times
Orderliness and after the experiment. mess during and after the during and after the
experiment. experiment.
Ability to do
Members require Members require occasional Members do not need to be
independent
supervision by the teacher. supervision by the teacher. supervised by the teacher.
work
Other Comments / Observations:
TOTAL SCORE

Rating =
(Total Score / 21)

You might also like