21
Introduction to Statistics (MECH261-2)StLe61ft.tex January 15, 2010 1 Wheeler & Ganji, pp.118-179, 2nd ed., pp.128-243, 3rd ed. You may pass, maybe even with a good grade, the statistics module of MECH 262 by reading these pages in the text and doing all problems assiduously. If you want to skip the lectures on Fridays; no hard feelings just be sure to show up for the mid-term on 10-03-05 at 09H30. 2 Broad Issues Statistics is about inference concerning expectation to allow us to make wise -if not lucky- planning decisions. There is a lot of “extra reading” for those who are interested. They appear via some of the blue hyper-links in the course outline and inherited from my predecessor, Dr. Martin Beuhler. Do not take these too seriously. These are like the appendix, a vestigial organ whose function we don’t quite understand. This is not the course where you can get deeply into statistics to which only a mere single credit is allotted. 3 Am./Can. Idol? It’s pretty safe to say if there was a TV show called “Mechanical Engineering Idol” that Sir Isaac Newton would rank pretty high, based on his contribution to dynamics and optics. But did he do statistics? Examine Fig. 1. 3.1 Binomial Distributions Newton’s problem will provide an opportunity to introduce an important topic in statistical prob- ability. A binomial distribution is pretty much like the proverbial “bell”, normal or Gaussian but the former is discrete while the latter is continuous. Let us first illustrate via Fig. 2 what is meant by a discrete distribution by looking at the throwing of only a pair of dice. Now let us go on to examine option A, that of the probability of throwing one or more sixes with a single toss from the leather cup containing six dice. This is a sufficiently simple problem, having but six levels, that it can be practically represented with the complete binary decision tree in Fig. 3. Nevertheless it is complicated enough to convey two important statistical notions. The relation among “less than”, “greater than” and “exactly” problem specifications and How the general binomial probability formula is derived. 1

1 Wheeler & Ganji, pp.118-179, 2nd ed., pp.128-243, 3rd ed

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 1 Wheeler & Ganji, pp.118-179, 2nd ed., pp.128-243, 3rd ed

Introduction to Statistics(MECH261-2)StLe61ft.tex

January 15, 2010

1 Wheeler & Ganji, pp.118-179, 2nd ed., pp.128-243, 3rd

ed.

You may pass, maybe even with a good grade, the statistics module of MECH 262 by readingthese pages in the text and doing all problems assiduously. If you want to skip the lectures onFridays; no hard feelings just be sure to show up for the mid-term on 10-03-05 at 09H30.

2 Broad Issues

Statistics is about inference concerning expectation to allow us to make wise -if not lucky- planningdecisions. There is a lot of “extra reading” for those who are interested. They appear via some ofthe blue hyper-links in the course outline and inherited from my predecessor, Dr. Martin Beuhler.Do not take these too seriously. These are like the appendix, a vestigial organ whose function wedon’t quite understand. This is not the course where you can get deeply into statistics to whichonly a mere single credit is allotted.

3 Am./Can. Idol?

It’s pretty safe to say if there was a TV show called “Mechanical Engineering Idol” that Sir IsaacNewton would rank pretty high, based on his contribution to dynamics and optics. But did he dostatistics? Examine Fig. 1.

3.1 Binomial Distributions

Newton’s problem will provide an opportunity to introduce an important topic in statistical prob-ability. A binomial distribution is pretty much like the proverbial “bell”, normal or Gaussian butthe former is discrete while the latter is continuous. Let us first illustrate via Fig. 2 what is meantby a discrete distribution by looking at the throwing of only a pair of dice.Now let us go on to examine option A, that of the probability of throwing one or more sixeswith a single toss from the leather cup containing six dice. This is a sufficiently simple problem,having but six levels, that it can be practically represented with the complete binary decision treein Fig. 3. Nevertheless it is complicated enough to convey two important statistical notions.

• The relation among “less than”, “greater than” and “exactly” problem specifications and

• How the general binomial probability formula is derived.

1

Page 2: 1 Wheeler & Ganji, pp.118-179, 2nd ed., pp.128-243, 3rd ed

Figure 1: Gleick, J. (2003) Isaac Newton, Vantage, ISBN 1-4000-3295-4, p.146.

2 11 123 104 5 96 870

2

3

4

1

5

6

Outcome

ways

0/36

1/36

2/36

3/36

4/36

5/36

6/36

=1/9

=1/12

=1/18

probability

(MECH2612)2DICE

=1/6

Figure 2: Two Dice Throw Outcome Probability

To see this, examine Fig. 3 carefully, maybe drawn to a larger scale, and trace out the “direct”and “inverse” problem solution paths. The structure and application of the general formula aredetailed in the sample problem below. After studying this carefully, do Newton’s dice problem forall three cases, A, B and C.

4 Binomial Probability

Here the reader is referred to pp.129-131 in Wheeler & Ganji. Additional examples are cited there.Consider the probability of there being x or more rotten eggs in a sample of n eggs. Assume abinomial distribution with a mean probability of µ. The probability p(r) of there being exactly ris given by Eq. 1.

p(r) = nCrprµq

n−rµ (1)

2

Page 3: 1 Wheeler & Ganji, pp.118-179, 2nd ed., pp.128-243, 3rd ed

p=5/6p=1/6

(MECH2612)6DICE

Figure 3: All 64 Possible Outcomes upon Tossing One Die Six Times or Six Dice Simultaneouslyin Order to Get a “Six”

Note that p(r) + q(r) = 1. Recall from the definition of permutations nPr and combinations nCr

that

nPr =n!

(n− r)!, nCr =

nPr

r!

nPr and nCr appear as buttons on an ordinary scientific pocket calculator. The specific problemassigned asked us to estimate the probability of there being more than 2 bad eggs in a sample of12, i.e., a dozen where the mean probability of finding bad eggs in a very large sample is one intwenty or pµ = 1

20. One might solve the problem p(> 2) as

p(> 2) =i=12∑i=3

p(i)

This is a sum of 12 − 2 = 10 expressions like Eq. 1. On the other hand only three terms arenecessary if we choose instead to use the complement.

p(> 2) = q(≤ 2) = 1− p(≤ 2) = 1−i=2∑i=0

p(i)

1−(

12C0p0µq

12µ +12 C1p

1µq

11µ +12 C2p

2µq

10µ

)Putting in the numbers produces

1−[1×

(1

20

)0 (19

20

)12

+ 12×(

1

20

)1 (19

20

)11

+ 66×(

1

20

)2 (19

20

)10]

or about1− 0.5404 − 0.3413 − 0.0988 = 1− 0.9805 = 0.0185

So we expect about 2% of the dozens to exceed the limit of two bad eggs.

4.1 A Somewhat Similar Problem

As a child I lived in a village where my father worked as a design engineer in a factory producingsmall arms ammunition, for the World War II effort, at the rate of millions of rounds per month.

3

Page 4: 1 Wheeler & Ganji, pp.118-179, 2nd ed., pp.128-243, 3rd ed

Acceptable product was deemed not to exceed, on average, one defective round per 1000. Samplebatches of 100 were taken and test fired. If the desired quality standard was being maintainedoverall, what was the probability of finding two or more “duds” in a batch? Hint: This can bereduced to a problem identical to the formulation of the “rotten egg” one, above.

1−(

100C0p0µq

100µ +100 C1p

1µq

99µ

)

5 Variability & Randomness

Measurement variability -controllable- and randomness -uncontrollable- affect conclusions drawntherefrom, hence usefulness. Statistics nevertheless permits us to plan experiments and interpretthe results. Because we are lucky enough to have fairly good theoretical models, unlike the poorsocial “scientists”, we have fewer uncontrollable effect to contend with.

6 Models & Correlation

Correlative relation reliability will be encountered in other courses like MECH 240, 331, 341, 346,430. Experimental correlation occurs by comparing measurements to models -phenomenologicalor heuristic- to be verified. Here’s a couple you may have encountered.

PV = mNRt, Nu(h) = CReαPrβ

Measured data scatter about expected model predicted characteristics leads to the requirementfor least squares regression to obtain parameters that best fit data to characteristics.

4

Page 5: 1 Wheeler & Ganji, pp.118-179, 2nd ed., pp.128-243, 3rd ed

Simple Regression on x and y; a Review

7 Regression on x versus y; a Comparison

Examine Fig. 4. The idea is that the independent variable, conventionally plotted along the x-axis,is given unequivocally, i.e, it is “known” like the weights used to calibrate the load cell assignmentexample. So we only need to minimize the sum of the squares of the y-deviations, yi. The exerciseto minimize sum of squares of xi is done afterwards to show that when the independent variablebecomes y in the normal right-handed Cartesian frame one must be careful to correctly distinguishbetween the left and right hand!

ax +b=yi

x i

y i

y=ax+b

y i

x

y a data point

data point givenby equation

x i

y iy=ax+b

x

y a data pointdata point givenby equation

=x x=(y -b)/ai

x i

Figure 4: Deviations in x and y

8 Regression on Deviations in y

Examine the graph on the left in Fig. 4. The deviation of the single visible data point with respectto line y = ax + b is

∆yi = yi − axi − b

The problem is to determine a and b such that the expression

n∑i=1

(∆yi)2

is minimized with respect to a sample population of n given data points. The simplest redundantsystem is represented by n = 3.

∆y1 = y1 − x1a− b

∆y2 = y2 − x2a− b

∆y3 = y3 − x3a− b

5

Page 6: 1 Wheeler & Ganji, pp.118-179, 2nd ed., pp.128-243, 3rd ed

Squaring and collecting the sum of the three right-hand sides and noting the recursion implicit ina sum of only three points yields the following conic equation, F (a, b) = 0, in a and b. Recall thata conic is any equation, in two variables, of order two.

F (a, b) =(∑

x2i

)a2 +

(2∑

xi

)ab−

(2∑

xiyi

)a + nb2 −

(2∑

yi

)b +

(∑yi

)2= 0

Take partial derivatives ∂F (a,b)∂a

= 0 and ∂F (a,b)∂b

= 0 and solve the resulting, now linear, twoequations for a and b.

(∑

x2i ) a (

∑xi) b − (

∑xiyi) = 0

(∑

xi) a +nb − (∑

yi) = 0

This gives

a =n∑

xiyi −∑

xi∑

yi

n∑

x2i − (

∑xi)2

, b =

∑yi∑

x2i −

∑xi∑

xiyi

n∑

x2i − (

∑xi)2

A simpler expression for b is obtained by taking the result for a, substituting it in the secondlinear equation above and rearranging.

b =

∑yi − a

∑xi

n

To better understand the principle of the inertia matrix method, satisfy yourself that the sum ofthe distances of all data points, represented by unit masses, to xG = 0, a vertical line, is zero; afirst moment equilibrium with respect to x.

9 Regression on Deviations in x

Examine the graph on the right in Fig. 4. The deviation of the single visible data point withrespect to the line x = (y − b)/a is

∆xi = xi − x = xi −yi

a+

b

a

With a change of variable A = 1/a, B = −b/a the equation above becomes

∆xi = xi − yiA−B

By similarity to the results in the previous section

A =n∑

xiyi −∑

xi∑

yi

n∑

y2i − (

∑yi)2

, B =

∑xi − A

∑yi

n

To better understand the principle of the inertia matrix method, satisfy yourself that the sum ofthe distances of all data points, represented by unit masses, to yG = 0, a horizontal line, is zero; afirst moment equilibrium with respect to y. Moreover the two lines obtained with the same datapoint cloud intersect on its centroid.

6

Page 7: 1 Wheeler & Ganji, pp.118-179, 2nd ed., pp.128-243, 3rd ed

The Inertia Matrix in Least-Squares Fitting

Inertia Matrix & Line on 3 Points

• Fit to Line; Induction & Differentiation

• Induction

• Differentiation

• The Points & Centroid

• Moments & Product of Inertia

Plane on 6 Points

• Points & Centroid

• Matrix Elements

• Eigenvectors, Eigenvalues and Fitted Plane

7

Page 8: 1 Wheeler & Ganji, pp.118-179, 2nd ed., pp.128-243, 3rd ed

Normal Least Squares Fit of Points to Line by Induction and Differentiation

10 Induction

Examine the upper diagram on Fig. 5.

P1

P2

Pi , i=3

y

x

n i

i

i

n

n 1

2

P

P2

P1

3G

x jx iy

y i

j

h i

y=ax+b

x

normal oncentroid G

y

Figure 5: Line with Minimum Least Squares Normal Distance to Three Given Points

The line to be fit to the three points iP is given by y = ax+b which can be inverted as x = (y−b)/a.The horizontal and vertical distances from a point to the line are given by

∆xi = xi −(

yi − b

a

)and ∆y = yi − (axi + b)

8

Page 9: 1 Wheeler & Ganji, pp.118-179, 2nd ed., pp.128-243, 3rd ed

By similar triangles the normal distance ∆n is

∆ni

∆yi

=∆xi

∆hi

Since the intention is to minimize the sum of the squares of the normal distances the contributionof each point is

∆n2i =

∆x2i ∆y2

i

∆h2i

=∆x2

i ∆y2i

∆x2i + ∆y2

i

=

{[xi −

(yi−b

a

)](yi − axi − b)

}2

[xi −

(yi−b

a

)]2+ (yi − axi − b)2

For three points this expands to

3∑i=1

∆n2i = ∆n2

1 + ∆n22 + ∆n2

3 =

{[x1 −

(y1−b

a

)](y1 − ax1 − b)

}2

[x1 −

(y1−b

a

)]2+ (y1 − ax1 − b)2

+

{[x2 −

(y2−b

a

)](y2 − ax2 − b)

}2

[x2 −

(y2−b

a

)]2+ (y2 − ax2 − b)2

+

{[x3 −

(y3−b

a

)](y3 − ax3 − b)

}2

[x3 −

(y3−b

a

)]2+ (y3 − ax3 − b)2

(2)

and this must be minimized with respect to a and b so

∂(∑3

i=1 ∆n2i

)∂a

= 0 and∂(∑3

i=1 ∆n2i

)∂b

= 0

The inductive aspect of this process becomes clear upon taking derivatives of the triple sum, Eq. 2.

11 Differentiation

The derivative with respect to a, after multiplication by (1 + a2)2/2 and collection of terms, is

∂(∑3

i=1 ∆n2i

)∂a

= [(x1y1 + x2y2 + x3y3)− (x1 + x2 + x3)b2]a2 + {[(x2

1 + x22 + x2

3)− (y21 + y2

2 + y23)]

+2(y1 + y2 + y3)b− 3b2}a− [(x1y1 + x2y2 + x3y3)− (x1 + x2 + x3)b] = 0 (3)

Similar treatment of the derivative with respect to b yields

3b = (y1 + y2 + y3)− (x1 + x2 + x3)a (4)

Substituting Eq. 4 into Eq. 3, multiplying the result by 3 and collecting a yield a quadratic.

Aa2 + Ba + C = 0 (5)

A = (x1 − x2)(y1 − y2) + (x2 − x3)(y2 − y3) + (x3 − x1)(y3 − y1) = −C

B = [(x1 − x2)2 + (x2 − x3)

2 + (x3 − x1)2]− [(y1 − y2)

2 + (y2 − y3)2 + (y3 − y1)

2]

9

Page 10: 1 Wheeler & Ganji, pp.118-179, 2nd ed., pp.128-243, 3rd ed

Examining Eq. 5 produces the following general relations for a and b, valid for n, any number ofpoints, not to be confused with ni, the normal distance of a point to the fitted line.

a2 +

∑ik(x

2i − x2

k)−∑

ik(y2i − y2

k)∑ik(xi − xk)(yi − yk)

a− 1 = 0

nb =∑

i

yi −(∑

i

xi

)a

Note that all possible differences and differences of squares must be taken in the sums∑

ik. Twosolutions for a, the slope of the fitted line, are obtained, along with a corresponding value of b.One of these is the actual line we seek. The other is on the centroid of the given points and normalto this line. There is no way, a-priori, to tell which is which unless one is prepared to take secondderivatives.(28)NLS42u.tex

12 Summing Up

• Q Why do single (semi-) regression (fitting) in the plane (between pairs of variable data),i.e., on y (or x)?

• A Calibration, where the independent variable is deemed to be at least an order of magnitudemore accurate and precise than the readings provided by the instrument under calibration.

• Q Why do double (normal least squares) regression (fitting)?

• A Correlation, where we wish to establish dependency between independent and dependent(that’s an oxymoron, I guess) variables x and y, e.g., smoking and lung cancer may wellyield a positive correlation; a fit line on the graph that has positive slope; exercise frequency-vs- heart attack frequency a negative one. However if we plotted Lotto winnings vs lastdigit of the winning ticket number we should expect a null or zero correlation; a horizontalline indicates no correlation.

• Correlation coefficient r is used to compare correlation trends. If we found that frequency ofgobbling a Big Mac was more steeply upward sloping to the right than smoking a cigarettewe’d say a Big Mac has a higher correlation to cancer than a cigarette. Be careful, thisevidence may or may not mean something in terms of cancer avoidance.

r =Sxy√SxxSyy

, Sxx =∑

x2 − (∑

x)2/n

Syy =∑

y2 − (∑

y)2/n, Sxy = (∑

xy −∑

x∑

y)/n

• In all cases one must assess the strength or significance of the correlation, e.g.,∑

n2i /N for

populations or n− 1 for samples because a population or sample of 2 has a mean x̄ or µ butno variance v = σ2 where σ is standard deviation.

10

Page 11: 1 Wheeler & Ganji, pp.118-179, 2nd ed., pp.128-243, 3rd ed

Inertia Matrix and Line on Three Given Points

13 The Points and Centroid

The numerical example shown in Fig. 5 is presented below.

1P (1, 2), 2P (3, 4), 3P (5, 3)

The first moment is calculated to yield G the centroid on the fit line.

[(1 + 3 + 5)/3, (2 + 4 + 3)/3, ] → G(3, 3)

The inertia matrix is referred to this origin so

1P′(−2,−1), 2P

′(0, 1), 3P′(2, 0),

replaces iP above.

14 Moments and Product of Inertia about Principal Axes

The second moments and product are obtained with iP′ as

Ixx = (−1)2 + 12 + 02 = 2, Iyy = (−2)2 + 02 + 22, Ixy = (−2)(−1) + 0((1) + 2(0) = 2

15 Eigenvectors, Eigenvalues and the Fitted Line

The eigenvectors e and eigenvalues λ are defined below.[Ixx − λ −Ixy

−Ixy Iyy − λ

] [ex

ey

]=

[00

]→∣∣∣∣∣ 2− λ −2−2 8− λ

]= 0 → λ2 − 10λ + 12 = 0

λ = 5±√

13

The greater eigenvalue is associated with the eignevector normal to the fitted line we seek. Why?Because the moment of inertia of the points about a line whose direction numbers are given bythe ratio ex : ey is the greatest with respect to an axis on the centroid G. This ratio is given byeither of the linearly dependent equations

[2− (5 +√

13)]ex − 2ey = 0 or − 2ex + [8− (5 +√

13)]ey = 0

The other, lesser, eigenvalue produces a vector with the same direction numbers as the fitted line.These lines of maximum and minimum inertia must not be confused with Izz, normal to the plane.This is the moment of inertia encountered in elementary planar mechanics.

11

Page 12: 1 Wheeler & Ganji, pp.118-179, 2nd ed., pp.128-243, 3rd ed

BESTLINE

(25,0)

(-25,0)

(7,24)

(-7,-24)x

y

1

2=900

=1600

x

G

8

5.2321245

8

-12.2321245

1

2

=2.767875402

=20.2321245

(2,3)

(4,4)

(5,7)

(8,6)

I

-I

-I

I yy

xyxx

xy

-

-=0

characteristic equation

I

-I

-I

I yy

xyxx

xy

-

-

( )

( )

a

a a

a

+ 21

21 =0

=0

eigenvector direction ratio

a 1

a 2

(0,0)G

(4.75,5)

I xx = y2, I yy =

2, I xy = xyx

Fitting Best Line to (4) Points in the Plane (in the sum of least square distance sense).

y

43

(21)

4

-3

Figure 6: Two 4-Point Line Fits; One Array Is Rectangular, the Other is Random

16 Practice

Now work out the two examples shown in Fig. 6 to your satisfaction. If you are confident thatyou understand how the inertia matrix operates in this respect then continue to the, next, planarfit to six given points. Four could have been chosen and that would be a minimum number thatstill constituted an over-determined system.

12

Page 13: 1 Wheeler & Ganji, pp.118-179, 2nd ed., pp.128-243, 3rd ed

Inertia Matrix and Plane on Six Given Points

How to fit the six-legged monster’s feet, in a fast-moving video game, to a changing surface thatcan be approximated by planar facets?

(29)Mstr47r

Figure 7: Six Monster Feet and the Plane

17 The Points and Centroid

The numerical example shown in Fig. 8 is presented below.

1P (4, 3, 2), 2P (7, 1, 4), 3P (2, 8, 1), 4P (9, 6, 7), 5P (1, 4, 6), 6P (12,−3,−5)

The homogeneous coordinates of the centroid are G{g0 : g1 : g2 : g3} ≡ {6 : 35 : 19 : 15}. Toobtain the elements of the inertia matrix all iP are multiplied by 6 before subtracting g1, g2, g3

from them all to produce

1P′(−11,−1,−3), 2P

′(7,−13, 9), 3P′(−23, , 29,−9),

4P′(19, 17, 27), 5P

′(−29, 5, 21), 6P′(37,−37,−45)

18 Inertia Matrix Elements

Notice that all six of the following sums of products contain the common divisor 6. Inertia matrixmagnitudes are irrelevant because we seek only the direction of eigenvector e associated with the

13

Page 14: 1 Wheeler & Ganji, pp.118-179, 2nd ed., pp.128-243, 3rd ed

greatest eigenvalue λ.

Ixx = {[(−1)2 + (−3)2] + [(−13)2 + 92] + [292 + (−9)2]+[172 + 272] + [52 + 212] + (−37)2 + (−45)2]}/6 = 1010

Iyy = {[(−32) + (−11)2] + [92 + 72] + [(−9)2 + (−23)2]+[272 + 192] + [212 + (−29)2] + [(−45)2 + 372]}/6 = 1106

Izz = {[(−11)2 + (−1)2] + [72 + (−13)2] + [(−23)2 + 292]+[192 + 172] + [(−29)2 + 52] + [372 + (−37)2]}/6 = 994

Ixy = {[(−11)(−1)] + [(7)(−13)] + [(−23)(9)]+[(19)(17)] + [(−29)(5)] + [(37)(−37)]}/6 = 323

Ixz = {[(−3)(−11)] + [(9)(7)] + [(−9)(23)+[(27)(19)] + [(21)(−29)] + [(−45)(37)]}/6 = 243

Ixz = {[(−1)(−3)] + [(−13)(9)] + [(29)(−9)]+[(17)(27)] + [(5)(21)] + [(−37)(−45)]}/6 = −309

19 Eigenvectors, Eigenvalues and the Fitted Plane

Ixx − λ −Ixy −Ixz

−Ixy Iyy − λ −Iyz

−Ixz −Iyz Izz − λ

ex

ey

ez

=

000

λ3 − 3110λ2 + 2961505λ− 796404408 = 0,λ = 453.1092563, 1244.042205, 1412.84854

Using the the greatest, λ = 1412.84854 produces three simultaneous, linearly dependent equations,any two of which can be solved homogeneously. The first two will be used.

(1010− 1412.84854)ex +323ey +243ez = 0323ex +(1106− 1412.84854)ey −309ez = 0243ex −309ey (994− 1412.84854)ez = 0 ex

ey

ez

=

−25242.80478−45991.198919284.4863

These are direction numbers of normals to the plane. Together with the centroid G we get

G1x + G2y + G3z + G0 = 0, g0exx + g0eyy + g0ezz − (g1ex + g2ey + g3ez) = 0

which becomes, numerically,

(6)(−25242.80478)x + (6)(−45991.1989)y + (6)(19284.4863)z−[(35)(−25242.80478) + (19)(−45991.1989) + (15)(19284.4863)] = 0

Fig. 8 shows top and front view of the six spatial points as well as all three mutually orthogonaleigenvector directions using all three eigenvalues. The vector labelled λ3 is associated with thegreatest eigenvalue. It does not appear as the longest because that would require unitizing theeigenvectors and scaling them to their eigenvalues. Note the edge view of the fitted plane g andthe six distances from the points to g. These are parallel to the plane normal λ3 that appears intrue view in the first auxiliary projection. (MECH261-2)StLe16f.tex, (28)NLS42u.tex, (28)IMp6P47s.tex, (MECH261-

2)StLe16ft.tex

14

Page 15: 1 Wheeler & Ganji, pp.118-179, 2nd ed., pp.128-243, 3rd ed

1

1

2

2

3

3

4

4

5

6

6

3

4

1

25

6

G

G

3

(e/l)g

(TL)

H1

3

1

2

3

2

1

H

H

H

H

H

H

H

1

1

1

1

1

1

1

5 F

F

F

F

F

F

(21) BESTPLNG F

Figure 8: Plane with Minimum Least Squares Normal Distance to Six Given Points

15

Page 16: 1 Wheeler & Ganji, pp.118-179, 2nd ed., pp.128-243, 3rd ed

> restart:with(linalg):

Warning, the protected names norm and trace have been redefined andunprotected

P1(1,2),P2(2,3),P3(4,4),P4(6,4,). Normal least squares fit of 2 planar lines to 4 given points.> p1x:=1:p1y:=2:p2x:=2:p2y:=3:p3x:=4:p3y:=4:p4x:=6:p4y:=4:> g1:=(p1x+p2x+p3x+p4x)/4:g2:=(p1y+p2y+p3y+p4y)/4:q1x:=p1x-g1:q1y:=p1y-> g2:q2x:=p2x-g1:q2y:=p2y-g2:q3x:=p3x-g1:q3y:=p3y-g2:q4x:=p4x-g1:q4y:=p4> y-g2:g1;g2;

134134

> Ixx:=q1y^2+q2y^2+q3y^2+q4y^2;Iyy:=q1x^2+q2x^2+q3x^2+q4x^2;Ixy:=q1x*q1> y+q2x*q2y+q3x*q3y+q4x*q4y;

Ixx :=114

Iyy :=594

Ixy :=234

> IM:=evalm(4*matrix(2,2,[Ixx-lambda,-Ixy,-Ixy,Iyy-lambda]));

IM :=[

11− 4 λ −23−23 59− 4 λ

]> CE:=-det(IM);rts:=solve(CE);IMS1:=evalm(4*matrix(2,2,[Ixx-rts[1],-Ixy> ,-Ixy,Iyy-rts[1]]));IMS2:=evalm(4*matrix(2,2,[Ixx-rts[2],-Ixy,-Ixy,Iyy> -rts[2]]));

CE := −120 + 280 λ− 16 λ2

rts :=354−√

11054

,354

+√

11054

IMS1 :=[−24 +

√1105 −23

−23 24 +√

1105

]IMS2 :=

[−24−

√1105 −23

−23 24−√

1105

]> eivec:=matrix(2,1,[e1,e2]);eigvec1:=multiply(IMS1,eivec)[1,1];eigvec2> :=multiply(IMS2,eivec)[1,1];norm1:=collect(23*solve(eigvec1,e2),e1);no> rm2:=collect(23*solve(eigvec2,e2),e1);

eivec :=[

e1e2

]eigvec1 := (−24 +

√1105) e1 − 23 e2

eigvec2 := (−24−√

1105) e1 − 23 e2

norm1 := (−24 +√

1105) e1

norm2 := (−24−√

1105) e1> chk:=((-24+1105^(1/2))*(-24-1105^(1/2))+(-23)*(-23));simplify(chk);

chk := (−24 +√

1105) (−24−√

1105) + 5290

**************************** End of 4-point planar line fit problem ***********************************

1

Page 17: 1 Wheeler & Ganji, pp.118-179, 2nd ed., pp.128-243, 3rd ed

> restart:with(linalg):> p1x:=1:p1y:=2:p1z:=3:p2x:=2:p2y:=3:p2z:=5:p3x:=4:p3y:=4:p3z:=8:p4x:=6> :p4y:=4:p4z:=7:> g1:=(p1x+p2x+p3x+p4x)/4:g2:=(p1y+p2y+p3y+p4y)/4:g3:=(p1z+p2z+p3z+p4z)> /4:q1x:=p1x-g1:q1y:=p1y-g2:q1z:=p1z-g3:q2x:=p2x-g1:q2y:=p2y-g2:q2z:=p2> z-g3:q3x:=p3x-g1:q3y:=p3y-g2:q3z:=p3z-g3:q4x:=p4x-g1:q4y:=p4y-g2:q4z:=> p4z-g3:g1;g2;g3;

134134234

P1(1,2,3),P2(2,3,5),P3(4,4,8),P4(6,4,7). Normal least squares fit of 3 planes to 4 given points. Theeigenvector/plane normal direction numbers associated with the largest eigenvalue is the best fit plane. Theintersection of the plane associated with the next greatest eigenvalue intersects the best normal distance fit planeon the best line fit. (FD1)LSF4P81y.mws, 08-01-25.

> Ixx:=q1y^2+q1z^2+q2y^2+q2z^2+q3y^2+q3z^2+q4y^2+q4z^2;

Ixx :=352

> Iyy:=q1z^2+q1x^2+q2z^2+q2x^2+q3z^2+q3x^2+q4z^2+q4x^2;

Iyy :=592

> Izz:=q1x^2+q1y^2+q2x^2+q2y^2+q3x^2+q3y^2+q4x^2+q4z^2;

Izz :=372

> Ixy:=q1x*q1y+q2x*q2y+q3x*q3y+q4x*q4y;

Ixy :=234

> Ixz:=q1x*q1z+q2x*q2z+q3x*q3z+q4x*q4z;

Ixz :=494

> Iyz:=q1y*q1z+q2y*q2z+q3y*q3z+q4y*q4z;

Iyz :=254

> IM:=evalm(4*matrix(3,3,[Ixx-lambda,-Ixy,-Ixz,-Ixy,Iyy-lambda,-Iyz,-Ix> z,-Iyz,Izz-lambda]));

IM :=

70− 4 λ −23 −49−23 118− 4 λ −25−49 −25 74− 4 λ

> CE:=collect(det(IM),lambda)/4;

CE := 47169− 18617 λ + 1048 λ2 − 16 λ3

> rts:=evalf(solve(CE));

rts := 32.33513374− 0.6 10−8 I, 3.02496380 + 0.535898384 10−9 I,

30.13990246 + 0.7464101616 10−8 I> eivec:=matrix(3,1,[e1,e2,e3]);IMS1:=evalm(4*matrix(3,3,[Ixx-Re(rts[1]> ),-Ixy,-Ixz,-Ixy,Iyy-Re(rts[1]),-Iyz,-Ixz,-Iyz,Izz-Re(rts[1])]));IMS2:> =evalm(4*matrix(3,3,[Ixx-Re(rts[2]),-Ixy,-Ixz,-Ixy,Iyy-Re(rts[2]),-Iyz> ,-Ixz,-Iyz,Izz-Re(rts[2])]));IMS3:=evalm(4*matrix(3,3,[Ixx-Re(rts[3]),> -Ixy,-Ixz,-Ixy,Iyy-Re(rts[3]),-Iyz,-Ixz,-Iyz,Izz-Re(rts[3])]));

2

Page 18: 1 Wheeler & Ganji, pp.118-179, 2nd ed., pp.128-243, 3rd ed

eivec :=

e1e2e3

IMS1 :=

−59.34053496 −23 −49−23 −11.34053496 −25−49 −25 −55.34053496

IMS2 :=

57.90014480 −23 −49−23 105.9001448 −25−49 −25 61.90014480

IMS3 :=

−50.55960984 −23 −49−23 −2.55960984 −25−49 −25 −46.55960984

> Eq1r1:=multiply(IMS1,eivec)[1,1];Eq2r1:=multiply(IMS1,eivec)[2,1];Eq3> r1:=multiply(IMS1,eivec)[3,1];

Eq1r1 := −59.34053496 e1 − 23 e2 − 49 e3Eq2r1 := −23 e1 − 11.34053496 e2 − 25 e3Eq3r1 := −49 e1 − 25 e2 − 55.34053496 e3

> Eq1r2:=multiply(IMS2,eivec)[1,1];Eq2r2:=multiply(IMS2,eivec)[2,1];Eq3> r2:=multiply(IMS2,eivec)[3,1];

Eq1r2 := 57.90014480 e1 − 23 e2 − 49 e3Eq2r2 := −23 e1 + 105.9001448 e2 − 25 e3Eq3r2 := −49 e1 − 25 e2 + 61.90014480 e3

> Eq1r3:=multiply(IMS3,eivec)[1,1];Eq2r3:=multiply(IMS3,eivec)[2,1];Eq3> r3:=multiply(IMS3,eivec)[3,1];

Eq1r3 := −50.55960984 e1 − 23 e2 − 49 e3Eq2r3 := −23 e1 − 2.55960984 e2 − 25 e3Eq3r3 := −49 e1 − 25 e2 − 46.55960984 e3

> M:=evalm(4*matrix(3,3,[Ixx,-Ixy,-Ixz,-Ixy,Iyy,-Iyz,-Ixz,-Iyz,Izz]));

M :=

70 −23 −49−23 118 −25−49 −25 74

> evalf(eigenvectors(M));

[129.3405349− 0.3 10−7 I, 1.,

{[0.13416691− 0.580719710 10−8 I, −2.47658854 + 0.118210632 10−8 I, 1.]}], [12.09985520− 0.598076212 10−8 I, 1.,

{[1.028820972 + 0.2114138896 10−8 I, 0.4595166690− 0.1984481756 10−8 I, 1.]}], [120.5596098 + 0.4598076212 10−7 I, 1.,

{[−1.12510912 + 0.7123874659 10−8 I, 0.34282948− 0.1388202480 10−7 I, 1.]}]> .13416691*1.028820972+(-2.47658854)*.4595166690+1;

0.148 10−7

3

Page 19: 1 Wheeler & Ganji, pp.118-179, 2nd ed., pp.128-243, 3rd ed

> restart:with(linalg):

Warning, the protected names norm and trace have been redefined andunprotected

4PtPln02e.mws, 10-02-05. Eigenvalue/vector best fit plane on 4 points(8,4,2),(4,3,1),(2,6,4),(9,13,3)

> g0:=4:g1:=8+4+2+9:g2:=4+3+6+13:g3:=2+1+4+3:px1:=4*8-g1:py1:=4*4-g2:pz> 1:=4*2-g3:px2:=4*4-g1:py2:=4*3-g2:pz2:=4*1-g3:px3:=4*2-g1:py3:=4*6-g2:> pz3:=4*4-g3: px4:=4*9-g1:py4:=4*13-g2:pz4:=4*3-g3:> Ixx:=py1^2+pz1^2+py2^2+pz2^2+py3^2+pz3^2+py4^2+pz4^2;Iyy:=px1^2+pz1^2> +px2^2+pz2^2+px3^2+pz3^2+px4^2+pz4^2;Izz:=py1^2+px1^2+py2^2+px2^2+py3^> 2+px3^2+py4^2+px4^2;

Ixx := 1056Iyy := 604Izz := 1500

> Ixy:=px1*py1+px2*py2+px3*py3+px4*py4;Ixz:=px1*pz1+px2*pz2+px3*pz3+px4> *pz4;Iyz:=pz1*py1+pz2*py2+pz3*py3+pz4*py4;

Ixy := 376Ixz := −40Iyz := 144

> EVM:=matrix(3,3,[Ixx,-Ixy,-Ixz,-Ixy,Iyy,-Iyz,-Ixz,-Iyz,Izz]);L:=matri> x(3,3,[lambda,0,0,0,lambda,0,0,0,lambda]);

EVM :=

1056 −376 40−376 604 −144

40 −144 1500

L :=

λ 0 00 λ 00 0 λ

> EVML:=evalm(EVM-L);

EVML :=

1056− λ −376 40−376 604− λ −14440 −144 1500− λ

> ceq:=det(EVML);

ceq := 726139904− 2964112 λ + 3160 λ2 − λ3

> egval:=evalf(solve(ceq));

egval := 1549.443154− 0.3 10−6 I, 381.2175572− 0.1771281292 10−6 I,

1229.339288 + 0.3771281292 10−6 I> egval1:=Re(egval[1]);egval2:=Re(egval[2]);egval3:=Re(egval[3]);

egval1 := 1549.443154egval2 := 381.2175572egval3 := 1229.339288

Page 20: 1 Wheeler & Ganji, pp.118-179, 2nd ed., pp.128-243, 3rd ed

> E:=matrix(3,1,[e1,e2,e3]):eq1:=subs(lambda=egval1,multiply(EVML,E)[1,> 1]);eq2:=subs(lambda=egval1,multiply(EVML,E)[2,1]);> eq3:=subs(lambda=egval1,multiply(EVML,E)[3,1]);

eq1 := −493.443154 e1 − 376 e2 + 40 e3eq2 := −376 e1 − 945.443154 e2 − 144 e3

eq3 := 40 e1 − 144 e2 − 49.443154 e3> ee1:=coeff(eq1,e2,1)*coeff(eq2,e3,1)-coeff(eq1,e3,1)*coeff(eq2,e2,1);> ee2:=-(coeff(eq1,e1,1)*coeff(eq2,e3,1)-coeff(eq1,e3,1)*coeff(eq2,e1,1)> );> ee3:=coeff(eq1,e1,1)*coeff(eq2,e2,1)-coeff(eq1,e2,1)*coeff(eq2,e1,1);

ee1 := 91961.72616ee2 := −86095.81418ee3 := 325146.4518

> eee1:=coeff(eq2,e2,1)*coeff(eq3,e3,1)-coeff(eq2,e3,1)*coeff(eq3,e2,1)> ;> eee2:=-(coeff(eq2,e1,1)*coeff(eq3,e3,1)-coeff(eq2,e3,1)*coeff(eq3,e1,1> ));> eee3:=coeff(eq2,e1,1)*coeff(eq3,e2,1)-coeff(eq2,e2,1)*coeff(eq3,e1,1);

eee1 := 26009.69146eee2 := −24350.62590eee3 := 91961.72616

> ee1/eee1;ee2/eee2;ee3/eee3;

3.5356715523.5356715073.535671473

> G0:=solve(4*G0+25*eee1+26*eee2+10*eee3);

G0 := −234185.81872.546557448

> BestPlane:=G0+eee1*x+eee2*y+eee3*z;

BestPlane := −234185.8187 + 26009.69146 x− 24350.62590 y + 91961.72616 z

> with(plots):> PTS:=pointplot3d({[8,4,2],[4,3,1],[2,6,4],[9,13,3]> },axes=boxed,color=black,symbol=circle):pln:=implicitplot3d(BestPlane> ,x=0..10,y=0..15,z=0..5,scaling=constrained, axes=boxed):

> display({PTS,pln});

Page 21: 1 Wheeler & Ganji, pp.118-179, 2nd ed., pp.128-243, 3rd ed

Figure 1: The Plane in Edge View and the Four Given Points