Sei sulla pagina 1di 23

CHE 317: COMPUTER PACKAGES FOR

CHEMICAL ENGINEERS

(EXCEL SECTION)

INTRODUCTION TO THE USE OF EXCEL


(Lecture 8)

Instructors:
Prof. V.E Efeovbokhan and Engr. D. E. Babatunde
Curve Fitting with Excel
• Engineers often collect paired data in order to
understand the characteristics or the behaviour of a
system.
• Relationships between the paired data are often
developed graphically.
• Mathematical expressions that capture the
relationships shown in the data can then be developed.
• Our goal is to determine the equation of a curve that
represents the trend reflected by the entire data set.
• To do so, we will make use of the method of least
squares, which is commonly used for fitting straight line
or a curve to a set of data.
The method
The methodof
of least squares
least squares
Cluster of measured data during an
experimental session in the lab.
The method of least squares
• The method of least squares is based on
minimizing the sum of the deviations or errors
of each of the data points from the values on
the line of best fit. For example, the figure that
follows shows how much data point number 8
is deviated from the line of best fit. If each
error is calculated this way and then summed
together. The least squares method is a way of
minimizing the sum of all these errors (Read up
on this from your engineering mathematics or
statistics textbook if you have forgotten).
The method
The methodof
of least squares
least squares
Fitting a straight line to a set of data
• To fit a straight line to a set of data means we wish to
determine the values of the coefficients a and b in the
straight-line equation y = ax + b so that the line will pass
through n data points. The coefficients are obtained by
satisfying the least squares criteria. In particular, the
coefficients are determined by solving the following two
simultaneous equations (You can find out how this is
derived from books on curve fittings). .
Fitting a straight line to a set of data
Class Example:
An engineer has measured the force exerted by
a spring as a function of its displacement from
its equilibrium position. The following data
have been obtained:
Fitting a straight line to a set of data

Pass a straight line through the data points


using the method of least squares. Then plot
the data points and the resulting straight line.

Solution
Fitting a straight line to a set of data

Pass a straight line through the data points


using the method of least squares. Then plot
the data points and the resulting straight line.
i xi yi xi2 xiyi
Solution 1 2 2 4 4
2 4 3.5 16 14
3 7 4.5 49 31.5
4 11 8 121 88
5 17 9.5 289 161.5
Total 41 27.5 479 299
Fitting a straight line to a set of data
On substituting the values in the table into the
simultaneous equations earlier written, we have:

41a + 5b = 27.5
479a + 41b = 299

Which on solving, a = 0.514706 and b = 1.279412

Hence, the equation of the line of best fit then


becomes y = 0.514706x + 1.279412

The next figure shows a plot of the given data and the
line of best fit.
Fitting a straight line to a set of data

14

12

10
Force, N

0
0 5 10 15 20 25
Displacement from Equilibrium Position, cm
Accessing a curve fit

• To access the quality of the curve fit, sum of the


squares of the errors (SSE) is usually computed to
evaluate each of the error terms and is given by

SSE is an indication of the quality of the curve fit – the


smaller the sum of the square errors, the better the fit.
• Another indication of the quality of the curve fit is the so-
called R-squared value defined as :
Accessing a curve fit

• where SST is the sum of the squares of the


deviations about the mean, and is given by

The R-squared value varies between 0 and 1. Note that


Will equal 1 when SSE equals zero. Hence, an value
close to 1 (which means that the sum of the square errors
is small) generally indicates a good fit.
Fitting a straight line to a set of data

Read up about curve fittings to understand


more about the underlying mathematical
principles of the method of least squares,
which is what Excel uses to fit equations to
data.
Linear Regression With Excel:
TRENDLINE

chart inserted into your worksheet


•To add a line of best fit (linear regression )
• click on Trendline in the Layout tab.
In the window that appears, select linear or any one
appropriate for the Trend/Regression type and
click on the checkboxes for:
“Display Equation on chart” and
“Display R-squared value on chart”.

For fit to a polynomial


must specify the degree
Or order
R2 is the square of the correlation coefficient or
coefficient of determination, is used as the measure of
correlation
It ranges from 0 (no correlation) to 1 (perfect
correlation).
R2 can be used as a measure of the goodness of fit of
data.
A value of R2 of less than 0.9 corresponds to a rather
poor fit of data
ARGUMENTS OF SLOPE , INTERCEPT AND RSQ FUNCTIONS
To fit data to a straight line:
If one is dealing with a set of points (x,y) for a
straight line, the slope, the intercept and R2 can be
found without plotting by using the functions:
SLOPE,
INTERCEPT and
RSQ
ARGUMENTS OF SLOPE , INTERCEPT AND RSQ FUNCTIONS
To fit data to a straight line:

• The arguments are the same as for the SLOPE


function.
a. SLOPE(known_y's,known-x's)

b. INTERCEPT(known_y's,known-x's)

c. RSQ (known_y's,known-x's)
If one is dealing with a set of points (x,y) for a
straight line, the slope, the intercept and R2can be
found without plotting by using the functions:
SLOPE,
Practice Questions
Q1
y: 0.038; 0.080; 0.174; 0.448; 1.43; 5.13; 9.47;
x: 0.2 0.4 0.8 2.0 6.0 20.0 35.0
Find the best values of the constants bo and b1 that best describe the
data by the equation: Y = b0Xb1
Q2. Develop a polynomial equation from the data on the heat capacity
of benzene vapour as a function of temperature.
Cp cal/K gmol: 19.65; 26.74; 32.80; 37.74; 41.75; 45.06; 47.83; 50.16;
TK 300; 400; 500; 600; 700; 800; 900; 1000.

Q3
V mm/s: 11.71; 13.63; 17.25; 18.92;
P bar : 50.6; 75.3; 116.3; 138.8.
Based on theoretical and empirical knowledge the relationship between
burning rate and pressure had the form: V=bPn
Determine the coefficients b and n
Q4
The relation between the heat capacity of liquid sulfuric acid in Cal/g C
and temperature in C is as follows:
Cal/g C: 0.377; 0.389; 0.396; 0.405; 0.466; 0.458
T C: 50; 100; 150; 200; 250; 300
Determine regression coefficients in the linear regression:
Cp = bo + b1T

Potrebbero piacerti anche