You are on page 1of 6

LABORATORY ACTIVITY #6

Curve Fitting and Interpolation 2

OBJECTIVES
At the end of this laboratory activity, you should be able to:
1. Apply the least squares approach in solving for the equation that fits “best” with the given
data.
2. Use Microsoft Excel to solve for the equations using least squares approach

TOOLS REQUIRED
1. Desktop computer or laptop with Microsoft Excel

PROCEDURES

Consider the following set of data:

x y x y
1 20 25 18.9
2.5 21 27 19
4 19 27.5 16
5 21.5 29 16.7
5.5 20 36 16
9 20.8 38 17
10 19.2 41.5 14
12 20.1 44 10
18 19 49 7
22 19.5 55 2

Least Squares Fit (Linear)

1. Label B3 to G3 columns as: x, y, x^2, xy, m, and b respectively. Then input the given set
of data for x and y.

2. For x^2 values, select D4 and input =B4^2 then enter. After select again D4 then click the
small box, hold and drag down until D23. Thereafter, for xy, select E4 and input =B4*C4 and
enter. Select again E4 then click the small box, hold and drag down until E23.
3. Next step is to find the summation of x, y, x^2, and xy. For the summation of x, select cell
B24 and input =SUM(B4:B23) and enter. While for the summation of y, select cell C24 and
input =SUM(C4:C23), for summation of x^2, select D24 then enter =SUM(D4:D23). Lastly,
for the summation of xy, select E24 then enter =SUM(E4:E23).

4. To find the slope of the given data, select cell F4 then enter =SLOPE(C4:C23,B4:B23)
then Enter. Furthermore, to find the y-intercept of the given data, select cell G4 then enter
=INTERCEPT(C4:C23,B4:B23) then Enter.

5. Using the equation y=mx+b , the equation that was created using the set of data is
y=−0.260 73 x +22. 84472. To graph the equation, select B4 to C23 then go insert and
click the scatter on the charts, select the scatter with only markers.
6. Next, go to Layout and click the Trendline under the Analysis area then go to “More
Trendline Options”, select the “Linear” and “Display Equation on Chart” then close.

7. The graph of the linear regression using the solved equation.

Least Squares Fit (2nd Degree Curve)

1. Label B3 to D3 as: x, y, and x^2 respectively. Apply the values/data that were used to
linear. A second-degree curve would correspond to the form y=a x2 +bx +c . Substitute the
given values to acquire equations.
2. Next, transform it into matrix form. Label I3, L3 and N3 as A, B, and C respectively. For A,
input the multiplier for the unknown values of a, b, and c. While for B, the unknown a, b,
and c. Lastly for C, input the values of y.

3. To find the unknown values of a, b, and c we use the equation B= A−1 C from the
equation form of AB=C . But A is not a square matrix (20x3)so we will transpose A as
3x20 matrix. Multiplying AT (3x20 matrix) and A (20x3 matrix) will result to a 3x3 matrix:
T T
A AB= A C . To transpose A, select C26 to V28 a 3x20 matrix then
=TRANSPOSE(H4:J23) and Ctrl + Shift + Enter.

4. Then multiply AT A , select C30 to E36 and input =MMULT(C26:V28,H4:J2) then Ctrl
+Shift + Enter.

5. From this, we can now compute the inverse of AT A and isolate B:


−1
( AT A ) ( A T A ) B=( AT A)−1 A T C . To inverse AT A , select the cell C34 to E36 and input
=MINVERSE(C30:E32) then Ctrl + Shift + Enter.
6. After that multiply the ( AT A)−1 to AT , select cell C38 to V40 and input
=MMULT(C34:E36,C26:V28) then Ctrl + Shift + Enter.

7. We can now solve the values for a, b, and c using B=( A T A)−1 A T C . Select C42 to C44
then input =MMULT(C38:V40,N4:N23) then Ctrl + Shift + Enter.

8. Using the equation for 2nd degree curve y=a x2 +bx +c , the equation that we created using
the given set of data is y=−0. 009187372 x 2 +0. 209721750 x +19. 344839101. To graph
the equation, select B4 to E23 then go insert and click the scatter on the charts, select the
scatter with only markers.

9. Next, go to Layout and click the Trendline under the Analysis area then go to “More
Trendline Options”, select the “Polynomial” and for “Order” input “2”, then select “Display
Equation on Chart” then close.

10. The graph of the 2nd degree curve regression using the solved equation.
SUMMARY

1. The solved equation is y=−0.260 73 x +22.84472 that “best” fits the data set using the
least squares fit approach when the equation is a Linear.

2. The solved equation is y=−0.009187372 x 2 +0.209721750 x +19.344839101 that “best”


fits the data set using the least squares fit approach when the equation is a 2nd degree
curve.

3. Between the two least squares fit approaches, the 2nd degree curve equation appears
to be a better fit than the linear one because it provides a more flexible fit than the
linear.

You might also like