0% found this document useful (0 votes)
492 views8 pages

Practice Problems For Curve Fitting - Solution

The document contains practice problems for curve fitting involving linear regression, nonlinear regression, polynomial interpolation, and spline interpolation. For linear regression, it fits a straight line to data and estimates parameters. For nonlinear regression, it linearizes a non-linear equation and estimates parameters. For polynomial interpolation, it uses a 3rd order Lagrange polynomial to approximate a value. For spline interpolation, it fits quadratic splines to data with natural end conditions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
492 views8 pages

Practice Problems For Curve Fitting - Solution

The document contains practice problems for curve fitting involving linear regression, nonlinear regression, polynomial interpolation, and spline interpolation. For linear regression, it fits a straight line to data and estimates parameters. For nonlinear regression, it linearizes a non-linear equation and estimates parameters. For polynomial interpolation, it uses a 3rd order Lagrange polynomial to approximate a value. For spline interpolation, it fits quadratic splines to data with natural end conditions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

CME261

Kaiwen Xia

Engineering Mathematics
November 04, 2010

Practice Problems for Curve Fitting - Solution


A. Linear Regression
1. Use least squares regression to fit a straight line to the data given in Table
1. Along with the slope and intercept, compute the standard error of the
estimate and the coefficient of determinant.
Table 1
x
y

0
5

2
6

4
7

6
6

9
9

11
8

2. An investigator has reported the data tabulated in Table 2 for an


experiment to determine the growth rate of bacteria k (per d) as a
function of oxygen concentration (mg/L). It is known that such data can
be modeled by the following equation:

kmax c 2
cs + c 2
where cs and kmax are parameters. Use a transformation to linearize this
equation. Then use linear regression to estimate cs and kmax and predict
the growth rate at c=2 mg/L.
k=

Table 2
C
K

0.5
1.1

0.8
2.4

1.5
5.3

2.5
7.6

4
8.9

B. General Linear Least Squares and nonlinear regression


A physics process can be described with the equation y = f ( x) =

a0 a1
. The
+
x x2

measured values of ( x, y ) are listed in the following table:


Table 3
x
y

1
3

2
0.9

3
0.6

4
0.4

Use direct nonlinear regression method to determine a0 and a1.

CME261

Engineering Mathematics
November 04, 2010

Kaiwen Xia

C. Polynomial Interpolation
Assume that the tabulated data in Table 3 are precise; apply the 3rd order Lagrange
Polynomial to approximate f (2.5) with precision to five decimal spaces.

D. Spline interpolation
Fit the data in Table 4 with a quadratic with natural end conditions.
Table 4
x
y

1
55

1.5
22

2
13

2.5
10

CME261

Kaiwen Xia

Engineering Mathematics
November 04, 2010

Practice Problems for Curve Fitting - Solution

A. Linear Regression
1. Use least squares regression to fit a straight line to the data given in Table
1. Along with the slope and intercept, compute the standard error of the
estimate and the coefficient of determinant.
Table 3
0
5

x
y

2
6

4
7

6
6

9
9

11
8

Solution:

The straight line that results in the least sum of squares of the residuals
between the measured y and the calculated y will be:
y = a1 x + a0
n xi yi xi yi

where a1 =

n xi2 ( xi )

and a0 = y a1 x

For the data in table 1 we have:


n =6,

= 32 ,

x y

= 41 ,

= 245 ,

2
i

= 258 , x = 5.33 , y = 6.83 .

Substituting in the above relations:


a1 =

6 245 32 41
= 0.30152 and a0 = 6.83 0.30152 5.33 = 5.2258
6 258 322

Therefore, the equation we are looking for is: y = 0.3015 x + 5.2258 .


The standard error of the estimate, SY / X , is given by the following equation:
Sr
n2
where S r is defined as
SY / X =

S r = ei2 = ( yi a0 a1 xi )
n

i =1

i =1

CME261

Kaiwen Xia

Engineering Mathematics
November 04, 2010
In this case, Sr is computed to be S r = 2.8931 .

The coefficient of determinant is r2 is the normalized decrease in the error due


to describing the data in terms of a straight line rather than an average value
and it is given by the following equation:

St S r
St
where St is the total sum of squares around the mean for y:
r2 =

St = ( yi y )

i =1

For the given data, we have:

St = 10.833 and r 2 =

10.833 2.893
= 0.7329
10.833

2. An investigator has reported the data tabulated in Table 2 for an


experiment to determine the growth rate of bacteria k (per d) as a
function of oxygen concentration (mg/L). It is known that such data can
be modeled by the following equation:
kmax c 2
cs + c 2
where cs and kmax are parameters. Use a transformation to linearize this
equation. Then use linear regression to estimate cs and kmax and predict
the growth rate at c=2 mg/L.
k=

Table 4
C
K

0.5
1.1

0.8
2.4

1.5
5.3

2.5
7.6

4
8.9

Solution:
The given equation for the growth rate of bacteria can be linearized in the
following way:

kmax c 2
c
1
1
1
= s 2+
2
cs + c
k kmax c kmax
which is of the form y = a1 x + a0
k=

with y = 1/ k , x = 1

c2

, a0 = 1

kmax

and a1 =

cs

kmax

CME261

Kaiwen Xia

Engineering Mathematics
November 04, 2010

As a result if we remake the data in table 2 accordingly, we can use linear


regression to estimate cs and kmax.
1

c2
1
k

1.563

0.444

0.160

0.063

0.909

0.417

0.189

0.132

0.112

As in exercise 1, we need to calculate the following quantities for this data:


n = 5,

= 6.299 ,

x = 2.076 , y = 0.586 .

= 1.758 ,

x y
i

= 4.399 ,

2
i

= 18.668 ,

Then we can calculate 0 and 1:

a1 =

5 4.399 6.299 1.758


= 0.202 ,
5 18.668 6.2992

a0 = 0.586 0.202 2.076 = 0.099

Now that we know 0 and 1, we can calculate cs and kmax:

a0 = 1
a1 =

cs

kmax

kmax

kmax = 1

a0

=1

0.099

= 10.1 d-1

cs = a1 kmax = 0.202 10.1 = 2.04 mg/L

and the expression for k is:

k=

10.1 c 2
2.04 + c 2

c = 2 mg / L

k = 6.689 d 1

B. General Linear Least Squares and nonlinear regression


A physics process can be described with the equation y = f ( x) =

a0 a1
. The
+
x x2

measured values of ( x, y ) are listed in the following table:


Table 3
x
y

1
3

2
0.9

3
0.6

4
0.4

Use direct nonlinear regression method to determine a0 and a1.

CME261

Kaiwen Xia

Engineering Mathematics
November 04, 2010

S r = ( yi

a0 a1 2
)
xi xi2

1
1
a0 a1
a0 a1
S r

a = 2( yi x x 2 )( x ) = 0
( yi x x 2 )( x ) = 0
0
i
i
i
i
i
i

S
a0 a1
a0 a1
1
1
r

= 2( yi 2 )( 2 ) = 0
( yi x x 2 )( x 2 ) = 0
a1

xi xi
xi
i
i
i
1
1
1 a0 a1
yi

( yi x x 2 x 3 ) = 0
a0 x 2 +a1 x 3 = x
i
i
i
i
i
i

1
1
yi
1 a0 a1
( yi 2 3 4 ) = 0
a0 3 +a1 4 = 2

xi xi xi
xi
xi
xi
i

xi

yi

1
2
3
4

1
2
3
4

3
0.9
0.6
0.4

1 / xi2
1.0000
0.2500
0.1111
0.0625
1.4236

1 / xi3
1.0000
0.1250
0.0370
0.0156
1.1777

1 / xi4
1.0000
0.0625
0.0123
0.0039
1.0788

yi / xi
3.0000
0.4500
0.2000
0.1000
3.7500

yi / xi2
3.0000
0.2250
0.0667
0.0250
3.3167

The system to solve is then:


1.4236a0 + 1.1777 a1 = 3.7500
a = 0.9206
0

a1 = 2.0714
1.1777 a0 + 1.0778a1 = 3.3167

C. Polynomial Interpolation
Assume that the tabulated data in Table 3 are precise; apply the 3rd order Lagrange
Polynomial to approximate f (2.5) with precision to five decimal spaces.
Solution:
The third order Lagrange polynomial for the four data points given in table 3 will be:
4

x xj

i =1

j =1
j i

xi x j

y = yi Li ( x) , Li ( x) =

where:

for i=1

CME261
L1 ( x) =

( x x2 )( x x3 )( x x4 )
( x 2)( x 3)( x 4)
=
( x1 x2 )( x1 x3 )( x1 x4 )
6

( x x1 )( x x3 )( x x4 )
( x 1)( x 3)( x 4)
=
( x2 x1 )( x2 x3 )( x2 x4 )
2

for i=3

L3 ( x) =

Kaiwen Xia

for i=2

L2 ( x) =

Engineering Mathematics
November 04, 2010

( x x1 )( x x2 )( x x4 )
( x 1)( x 2)( x 4)
=
( x3 x1 )( x3 x2 )( x3 x4 )
2

and for i=4

L4 ( x) =

( x x1 )( x x2 )( x x3 )
( x 1)( x 2)( x 3)
=
( x4 x1 )( x4 x2 )( x4 x3 )
6

Changing the notation of the data points to make it easier to substitute, gives:
Substituting gives:

f3 ( x) =

( x 2 )( x 3)( x 4 ) 3 + ( x 1)( x 3)( x 4 ) 0.9 +

2
6
( x 1)( x 2 )( x 4 ) 0.6 + ( x 1)( x 2 )( x 3) 0.4
+
6
2

f 3 ( x) = 0.5 ( x 2 )( x 3)( x 4 ) + 0.45 ( x 1)( x 3)( x 4 )


0.3 ( x 1)( x 2 )( x 4 ) + 0.067 ( x 1)( x 2 )( x 3)

To find f(2.5) we substitute x=2.5 in the above equation:

f 3 ( x) = 0.5 ( 2.5 2 )( 2.5 3)( 2.5 4 ) + 0.45 ( 2.5 1)( 2.5 3)( 2.5 4 )
0.3 ( 2.5 1)( 2.5 2 )( 2.5 4 ) + 0.067 ( 2.5 1)( 2.5 2 )( 2.5 3) = 0.63125

CME261

Engineering Mathematics
November 04, 2010

Kaiwen Xia

D. Spline interpolation
Fit the data in Table 4 with a quadratic with natural end conditions.
Table 4
x
y

1
55

1.5
22

2
13

2.5
10

Solution:

For quadratic splines, we want to derive a second order polynomial for each interval
which will fit the data in the interval. The polynomial is of the following form:

f i ( x) = ai + bi ( x xi ) + ci ( x xi ) 2
Natural condition implies c1 = 0, b1 = ( y2 y1 ) /( x2 x1 ) .
Use the formula:

ai +1 = yi +1
a1 = 55 a2 = 22 a3 = 13

b1 = 66; b2 = 66; b3 = 30
bi +1 = bi + 2ci ( xi +1 xi )

c = 0 c = 96 c = 72
yi + 2 yi +1
bi +1
3
2
1
ci +1 = ( x x ) 2 ( x x )
i+2
i +1
i+2
i +1

The splines are plotted in the graph below.


60
50

40
30
20
10
0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4 2.6

You might also like