You are on page 1of 10

Excercises in Least Squares September 13, 2006 Fall 2006

1.

Dene constants a and b such that the line y = ax + b interpolates the data points (0, 2.1), (1, 1.92), (2, 1.84), (3, 1.71) ja (4, 1.64) in a least squares sense.
Vastaus:

a = 0.113 b = 2.068
Ratkaisu:

S=
i=1

(yi axi b)2

S attains its smallest value at the critical point. 5 0 = S = 2 xi (yi axi b) a i=1 5 0 = S = 2 yi axi b b
i=1

0 = 2 0 (2.1 a 0 b) + 1 (1.92 a 1 b) + 2(1.84 a 2 b) + 3(1.71 a 3 b) +4(1.64 a 4 b) 0 = 2 2.1 a 0 b + 1.92 a b + 1.84 2a b + 1.71 3a b + 1.64 4a b 60a + 20b = 34.58 20a + 10b = 18.42 a = 0.113 b = 2.068

2.

a) Dene the constant a so that the function y = ax2 is the best t in the sense of least squares to the data points (xi , yi ), i = 1, . . . , n. What value should the constant a attain if the function is y = aex ? b) Dene constants a and b, that make the function g(x) = ax2 + bx to attain

the best t to the function f (x) = sin x over the interval [0, ], in the sense that the squared integral

I=
0

[f (x) g(x)]2 dx

is minimized.

Vastaus:

yi exi

a)

a=

i=1 n

e2xi
i=1

b)

a=

20 2 ( 16), 5

b=

12 (20 2 ) 4

Ratkaisu:

a)

We seek the smallest value of the function


n

S(a) =
i=1 n

(yi ax2 )2 i

S (a) = 2
i=1

x2 (yi ax2 ) = 0 i i
n

x2 yi i a=
i=1 n

x4 i
i=1 n

y = aex S(a) =
i=1 n

(yi aexi )2

S (a) = 2
i=1

exi (yi aexi ) = 0

yi exi a=
i=1 n

e2xi
i=1

b)

We seek to minimize I =
0

(sin x ax2 bx)2 dx x2 (sin x ax2 bx) dx = 0

Ia = 2 Ib = 2

x(sin x ax2 bx) dx = 0

(x2 sin x ax4 bx3 ) dx = 0


0

(x sin x ax3 bx2 ) dx = 0

0 0

2 cos x + 2 sin x x2 cos x

bx4 b 4 ax5 a 5 =0 = 2 4 5 4 5 4 ax4 bx3 a 4 b 3 sin x x cos x = =0 4 3 4 3 a= 20 2 ( 16), 5 b= 12 (20 2 ) 4

3.

Approximate the function f (x) dened on the interval [0, 1] with a linear function g(x) = px + q using the least squares method.
Vastaus:

p=
0

(12x 6)f (x) dx


1

q=
0
Ratkaisu:

(4 6x)f (x) dx

I(p, q) =
0

f (x) px q

dx

1 0 = I = 2 x f (x) px q dx = 0 p 0 1 0 = I = 2 f (x) px q dx = 0 q 0 1 1 px3 qx2 p q xf (x) dx = + = + 3 2 3 2 0 0 1 1 px2 p f (x) dx = + qx = + q 2 2 0 0


1

p=
0

(12x 6)f (x) dx


1

q=
0

(4 6x)f (x) dx.

4.

Let us use the least squares method to t a line to the results of a laboratory experiment. In an experiment we have oxidated butanol into butyric acid. We shall assume that reaction kinetics are of rst order and that there are no side reactions. The reaction to be studied is Butanol Butyric acid In the beginning, we have inserted butanol into the vessel to reach the density of 53 mmol . When butanol was oxidized in the presence of a catalyst at 80 C, dm3 the following measurements were made. Time, min Percentage of Butanol oxidized
36.0 65.7 120 180 330 19 % 30 % 41 % 48 % 62 %

Taulukko 1: The percentage of butanol oxidized as a function of time.


Vastaus:

The rate at which Butanol is oxidized into butyric acid is 2.47 103 mmol . min

Ratkaisu:

The speed of the reaction is given by the equation


dcbutyric acid dcbutanol = = kcbutanol dt dt

In other words, butanol is disappearing at the same rate that butyric acid emerges into the vessel. The reaction rate constant k is to be determined by the least squares method. Integrating the equation above, we get
dcbutanol = k cbutanol dt.

In the beginning, the concentration of butanol is given at 53 mmol , and we get dm3
ln cbutanol = kt.

Let us rst convert the measurements into the following convenient form: Time, min butanol (%) cbutyric acid , mmol cbutanol , mmol ln c yi dm3 dm3
36 65.7 120 180 330 19 % 30 % 41 % 48 % 62 % 10.07 15.9 21.73 25.44 32.86 42.93 37.10 31.27 27.56 20.14 3.76 3.61 3.44 3.32 3.00

Taulukko 2: Measurements made We shall now t a line of the form y = mx + b into the measurement table. Using matrices, we can now compute the determinant, angle of incidence and the point at which the line intersects the y axis (in this case the symbol m denotes the reaction rate constant).
(x2 ) i xi D (x2 ) i xi (xi yi ) yi D i i xi xi (xi yi ) yi

b=

D=

m=

Inserting the values measured from the table above, we obtain the following expression for the determinant:
D= 161312 731.7 731.7 5 = 271177

From this, the angle of incidence of the tted line emerges as:
m= 2373.72 731.7 17.135 5 D m = 2.47 103 .

The above result indicates that butanol is oxidized into butyric acid at the rate of 2.47 103 mmol , when the initial concentration of butanol was 53 mmol . min dm3 Please carry out the same computations using Matlab and verify these results.
5.

Arrhenius' Law for the temperature dependence of a reaction can be stated as


k = Ae Ru T ,
J where Ru = 8.3145 molK is the universal gas constant. When measuring the the reaction rate constant k at dierent temperatures T for a reaction between benzene and oxygen, we obtain the following measurements
Ea

T [K] 300.3 341.2 391.2

k [dm3 /mol s] 1.44 107 3.03 107 6.90 107

Determine the activation energy Ea and the Arrhenius constant A for the reaction using the least squares method. Please also consider how you would formulate the least squares problem using matrix algebra (in this case the least squares problem attains the form Y = XC ). LSM = Least Squares Method. We must t a line of the form y = a + bx to the measurements, where
a= yb N x b= x x yN
2

xy x2

Vastaus:

A = 1.28 1010
Ratkaisu:

dm3 mol s

ja

Ea = 17.0

kJ mol

The Arrhenius equation reads


k = Ae Ru T
Ea

We shall take the logarithm of both sides


ln k = ln A + ln e Ru T
Ea

and then transform this into an equation for a line


ln k = ln A +
y a

Ea Ru
b

1 T
x

that is

y = ln k x= 1 T a = ln A Ea b = Ru T [K] 300.3 341.2 391.2 k x y [dm3 /mol s] = 1/T = ln(k) 1.44 107 0.003330 16.483 3.03 107 0.002931 17.227 6.90 107 0.002550 18.050

Now we shall rewrite the measurements as:

The graph of the least squares solution looks as follows From the equation for the line, we obtain its constant coecients. The constant a yields the Arrhenius constant
ln A = 23.147 A = 1.12 1010 dm3 mol s

while the constant b gives us the activation energy


Ea = Ru b = 8.3145 J kJ 2006.9 K = 16.69 mol K mol

The least squares method reads


b= x x yN
2

xy x2

a=

yb N

Inserting our numerical values, we get


N =3 x = 0.008811 y = 51.760 x2 = 26.18 106 xy = 0.1514 b= 0.008811 51.760 3 0.1540 = 2049 0.0088112 3 26.18 106 51.760 + 2049 0.008811 = 23.271 3

a=

The activation energy obtains


Ea = Ru b = 8.3145 J kJ 2049 K = 17.0 mol K mol

and the Arrhenius constant (in the same units as the reaction rate coecient k)
A = ea = e23.271 = 1.28 1010 dm3 mol s

We now write the least squares method in matrix form


Y = XC

where

ln k1 Y = ln k2 ln k3

1 X= 1 1

1 T1 1 T2 1 T3

C= a b

The subscripts refer to measurement points, of which we could have more, but in the interest of simplicity in manual calculation we shall be content with three measurement points only. We therefore have two unknowns in the coecient matrix C , that we shall solve for. X is not a square matrix, so we shall multiply it with its transpose to obtain the normal equations
X T Y = X T XC

This looks better, so let's now multiply the equation with the inverse of (X T X) from the left on both sides
(X T X)1 X T Y = (X T X)1 X T XC

A matrix multiplied by its inverse yields the identity matrix I , and we thus obtain
(X T X)1 X T Y = IC

Let us nally swap the left hand side and the right hand side with one another
C = (X T X)1 X T Y

and we thus get the coecients required by the Arrhenius' law astonishingly fast . . . if we can get it done correctly. Let us check that the matrices multiply correctly
C is of size 2 1 X T is of size 2 3 X is of size 3 2 Y is of size 3 1 [2 1] = [2 3][3 2]
1

[2 3][3 1]

[2 1] = [2 2]1 [2 1] [2 1] = [2 1]

[2 1] = [2 2][2 1]

and we're done.


6.

By writing a reaction equation in matrix form, we can easily balance an equation, i.e. nd the stoichiometric coecients for the reaction equation Let us nd the stoichiometric coecients for the reaction equation
M gO + F e F e2 O3 + M g

Vastaus:

a = 3, b = 2, c = 1 ja d = 3 3M gO + 2F e F e2 O3 + 3M g
Ratkaisu:

We shall rewrite the equation in the form


aM gO + bF e = cF e2 O3 + dM g.

Magnesium : a +0b +0c = 1d Iron : 0a +1b 2c = 0d Oxygen : 1a +0b 3c = 0d We obtain the matrix
1 0 A= 0 1 1 0 0 2 3

It's determinant is detA = 3

1 B = 0 . 0

We now construct the inverse matrix


A1 = 1
2 3 1 3

0 1 0

0
2 3 1 3

From this, we can solve for the stoichiometric coecients


3 [A]1 [B]det[A] = 2 1

And thus and this yields

a = 3, b = 2, c = 1 ja d = 3

3M gO + 2F e F e2 O3 + 3M g

You might also like