Multivariate Calculus - Bruce E. Shapiro

Multivariate Calculus - Bruce E. Shapiro Multivariate Calculus - Bruce E. Shapiro

bruce.shapiro.com
from bruce.shapiro.com More from this publisher
21.04.2015 Views

112 LECTURE 14. UNCONSTRAINED OPTIMIZATION Dividing by 2 and separating the three sums as before 0 = = n∑ x i (mx i + b − y i ) i=1 n∑ mx 2 i + b i=1 = m n∑ n∑ x i − x i y i i=1 n∑ x 2 i + bX − i=1 i=1 i=1 n∑ x i y i where X is defined in equation 14.8. Next we define, A = C = n∑ x 2 i (14.11) i=1 n∑ x i y i (14.12) i=1 so that 0 = mA + bX − C (14.13) Equations ?? and ?? give us a a system of two linear equations in two variables m and b. Multiplying equation 14.10 by A and equation 14.13 by X gives 0 = A (mX + nb − Y ) = AXm + Anb − AY (14.14) 0 = X (mA + bX − C) = AXm + X 2 b − CX (14.15) Subtracting these two equations gives and therefore 0 = Anb − AY − X 2 b + CX = b(An − X 2 ) + CX − AY b = n∑ x 2 i AY − CX An − X 2 = i=1 n∑ ∑ y i − n x i y i i=1 i=1 n∑ ∑ n n ( n∑ ) 2 x 2 i − x i i=1 i=1 x i i=1 If we instead multiply equation 14.10 by X and equation 14.13 by n we obtain Subtracting these two equations, 0 = X (mX + nb − Y ) = mX 2 + nXb − Y X 0 = n (mA + bX − C) = nAm + nXb − nC 0 = m ( X 2 − nA ) − (Y X − nC) Solving for m and substituting the definitions of A, C, X and Y , gives Revised December 6, 2006. Math 250, Fall 2006

LECTURE 14. UNCONSTRAINED OPTIMIZATION 113 n∑ n∑ ∑ x i y i − n n x i y i XY − nC m = X 2 − nA = i=1 i=1 i=1 ( n∑ ) 2 ∑ x i − n n x 2 i i=1 i=1 Generally this algorithm needs to implemented computationally, because there are so many sums to calculate. It is also implemented on many calculators. Least Squares Algorithm To find a best-fit line to a set of n data points calculate, The best fit line is (x 1 , y 1 ), (x 2 , y 2 ), ..., (x n , y n ) X = ∑ n x i i=1 Y = ∑ n y i i=1 A = ∑ n i=1 x2 i C = ∑ n x iy i i=1 y = mx + b where XY − nC m = X 2 − nA AY − CX b = An − X 2 Example 14.8 Find the least squares fit to the data (3, 2), (4,3), (5,4), (6,4) and (7,5). Solution. First we calculate the numbers X, Y , A, and C, X = ∑ n x i = 3 + 4 + 5 + 6 + 7 = 25 i=1 Y = ∑ n y i = 2 + 3 + 4 + 4 + 5 = 18 i=1 A = ∑ n i=1 x2 i = 9 + 16 + 25 + 36 + 49 = 135 C = ∑ n x iy i = (3)(2) + (4)(3) + (5)(4) + (6)(4) + (7)(5) = 97 i=1 Therefore XY − nC (25)(18) − (5)(97) 450 − 485 m = X 2 = − nA (25) 2 = − 5(135) 625 − 675 = −35 −50 = 0.7 and AY − CX (135)(18) − (97)(25) 2430 − 2425 b = = An − X2 (135)(5) − 25 2 = = 5 50 50 = 0.1 So the best fit line is y = 0.7x + 0.1 Math 250, Fall 2006 Revised December 6, 2006.

112 LECTURE 14. UNCONSTRAINED OPTIMIZATION<br />

Dividing by 2 and separating the three sums as before<br />

0 =<br />

=<br />

n∑<br />

x i (mx i + b − y i )<br />

i=1<br />

n∑<br />

mx 2 i + b<br />

i=1<br />

= m<br />

n∑ n∑<br />

x i − x i y i<br />

i=1<br />

n∑<br />

x 2 i + bX −<br />

i=1<br />

i=1<br />

i=1<br />

n∑<br />

x i y i<br />

where X is defined in equation 14.8. Next we define,<br />

A =<br />

C =<br />

n∑<br />

x 2 i (14.11)<br />

i=1<br />

n∑<br />

x i y i (14.12)<br />

i=1<br />

so that<br />

0 = mA + bX − C (14.13)<br />

Equations ?? and ?? give us a a system of two linear equations in two variables<br />

m and b. Multiplying equation 14.10 by A and equation 14.13 by X gives<br />

0 = A (mX + nb − Y ) = AXm + Anb − AY (14.14)<br />

0 = X (mA + bX − C) = AXm + X 2 b − CX (14.15)<br />

Subtracting these two equations gives<br />

and therefore<br />

0 = Anb − AY − X 2 b + CX = b(An − X 2 ) + CX − AY<br />

b =<br />

n∑<br />

x 2 i<br />

AY − CX<br />

An − X 2 = i=1<br />

n∑ ∑<br />

y i − n x i y i<br />

i=1<br />

i=1<br />

n∑<br />

∑<br />

n n ( n∑<br />

) 2<br />

x 2 i − x i<br />

i=1 i=1<br />

x i<br />

i=1<br />

If we instead multiply equation 14.10 by X and equation 14.13 by n we obtain<br />

Subtracting these two equations,<br />

0 = X (mX + nb − Y ) = mX 2 + nXb − Y X<br />

0 = n (mA + bX − C) = nAm + nXb − nC<br />

0 = m ( X 2 − nA ) − (Y X − nC)<br />

Solving for m and substituting the definitions of A, C, X and Y , gives<br />

Revised December 6, 2006. Math 250, Fall 2006

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!