You are on page 1of 42

11/3/2022

Public Works Department


Master Degree

Dr. Asmaa Moddather


Soil Mechanics and Foundations
Faculty of Engineering – Cairo University

FALL 2022

10

11

1
11/3/2022

Introduction

 Data is often given for discrete values along a


continuum.

 However, you may require estimates at points between


the discrete values.

 The present part describes techniques to fit curves to


such data to obtain intermediate estimates.

 In addition, you may require a simplified version of a


complicated function.
Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

12

Introduction

 One way to do this is to compute values of the function


at a number of discrete values along the range of
interest. Then, a simpler function may be derived to fit
these values.

 Both of these applications are known as curve fitting.

 There are two general approaches for curve fitting that


are distinguished from each other on the basis of the
amount of error associated with the data.
Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

13

2
11/3/2022

Introduction
 First, where the data exhibits a significant degree of error or
“noise”, the strategy is to derive a single curve that represents
the general trend of the data.
 Because any individual data
point may be incorrect, we make
no effort to intersect every point.
Rather, the curve is designed
to follow the pattern of the
points taken as a group. One
approach of this nature is called
least-squares regression.
Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

14

Introduction
 Second, where the data is known to be
very precise, the basic approach is to
fit a curve or a series of curves that
pass directly through each of the
points. Such data usually originates
from tables. Examples are values for the
density of water or for the heat capacity
of gases as a function of temperature.

 The estimation of values between well-


known discrete points is called
interpolation. Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

15

3
11/3/2022

Noncomputer methods

 The simplest method for fitting a curve to data is to plot the


points and then sketch a line that visually conforms to the data.

 Although this is a valid option when quick estimates are


required, the results are dependent on the subjective viewpoint
of the person sketching the curve.

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

16

Engineering Practice

 Two types of applications are generally encountered when


fitting experimental data: trend analysis and hypothesis
testing.

 Trend analysis represents the process of using the pattern


of the data to make predictions. For cases where the data is
measured with high precision, you might utilize
interpolating polynomials. Imprecise data is often analyzed
with least-squares regression.

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

17

4
11/3/2022

Engineering Practice

 Trend analysis may be used to predict or forecast values of


the dependent variable. This can involve extrapolation
beyond the limits of the observed data or interpolation
within the range of the data.

 hypothesis testing: an existing mathematical model is


compared with measured data. If the model coefficients
are unknown, it may be necessary to determine values that
best fit the observed data.

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

18

Engineering Practice

 On the other hand, if estimates of the model coefficients


are already available, it may be appropriate to compare
predicted values of the model with observed values to test
the adequacy of the model.

 Often, alternative models are compared and the “best” one


is selected on the basis of empirical observations.

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

19

5
11/3/2022

Engineering Practice

 Curve fitting is important in other numerical methods


such as integration and the approximate solution of
differential equations.

 Finally, curve-fitting techniques can be used to derive


simple functions to approximate complicated functions.

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

20

Curve Fitting

 Least Square Regression

 Interpolation

 Fourier Approximation

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

21

6
11/3/2022

Least Square Regression

 Linear Regression

 Multiple Regression

 General linear least squares

 Nonlinear Regression

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

22

Least Square Regression

 Where substantial error is associated with data, polynomial


interpolation is inappropriate and may yield unsatisfactory
results when used to predict intermediate values.

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

23

7
11/3/2022

Linear Regression

 The simplest example of a least-squares approximation is fitting


a straight line to a set of paired observations: (x1, y1), (x2, y2), . . . ,
(xn, yn). The mathematical expression for the straight line is:

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

24

Linear Regression

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

25

8
11/3/2022

Linear Regression

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

26

Linear Regression

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

27

9
11/3/2022

Linear Regression

We need a criteria to fit


data !!

e=
Minimum error

for all points

One best solution

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

28

Linear Regression

 One strategy for fitting a “best” line through the data would be to
minimize the sum of the residual errors for all the available data:

-e
+e

Σe = zero !!

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

29

10
11/3/2022

Linear Regression

 One strategy for fitting a “best” line through the data would be to
minimize the sum of the residual errors for all the available data:

more than one solution !!

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

30

Linear Regression

 One strategy for fitting a “best” line through the data would be to
minimize the sum of the residual errors for all the available data:

 The minimax criterion:

The line is chosen that


minimizes the maximum
distance that an individual
point falls from the line.

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

31

11
11/3/2022

Linear Regression
How to calculate ao and a1?

 One strategy for fitting a “best” line through the data would be to

minimize the sum of the residual errors for all the available data:

 This criterion has a number of advantages, overcomes the

shortcomings of the aforementioned approaches and the fact

that it yields a unique line for a given set of data.

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

32

Linear Regression

 Differentiate Sr with respect to each coefficient:

 If these derivatives = zero  minimum Sr

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

33

12
11/3/2022

Linear Regression

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

34

Linear Regression

 Fit a straight line to the x and y values in the following

Table:

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

35

13
11/3/2022

Linear Regression

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

36

Linear Regression

xi yi x2i xiyi
1 0.5 1 0.5
2 2.5 4 5
3 2 9 6
4 4 16 16
5 3.5 25 17.5
6 6 36 36
7 5.5 49 38.5
28 24 140 119.5

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

37

14
11/3/2022

Linear Regression
Quantification of data spread around regression line:

 Sy/x : The standard error of estimates 

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

38

Linear Regression
Quantification of Error reduction:

 r2: Coefficient of determination 

 r: correlation coefficient

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

39

15
11/3/2022

Linear Regression

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

40

Linear Regression

7
6 y = 0.8393x + 0.0714
r² = 0.8683
5
4
y

3
2
1
0
0 2 4 6 8
x

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

41

16
11/3/2022

Linear Regression

Always inspect the plot of


points along with your
regression curve !!

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

42

Linearization of Nonlinear Relationships

 Linear regression provides a powerful technique for fitting


a best line to data.

 This is not always the case, and the first step in any
regression analysis should be to plot and visually inspect
the data to ascertain whether a linear model applies.

 Some data are curvilinear. In some cases, techniques such


as polynomial regression are appropriate.

 For others, transformations can be used to express the data


in a form that is compatible with linear regression.
Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

43

17
11/3/2022

Linearization of Nonlinear Relationships

Exponential equation

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

44

Linearization of Nonlinear Relationships

Power equation

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

45

18
11/3/2022

Linearization of Nonlinear Relationships

Saturation growth rate equation

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

46

Linear Regression

 Fit a power equation to the x and y values in the following

Table:

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

47

19
11/3/2022

Linear Regression

New x and y  use linear regression


a1 = β2
a0 = log α2

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

48

Linear Regression

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

49

20
11/3/2022

Polynomial Regression

Convert into
matrix form

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

50

Polynomial Regression

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

51

21
11/3/2022

Polynomial Regression

 Fit a second-order polynomial to the data in the

following Table:

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

52

Polynomial Regression

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

53

22
11/3/2022

Polynomial Regression

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

54

Polynomial Regression

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

55

23
11/3/2022

Polynomial Regression

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

56

Multiple Linear Regression

 A useful extension of linear regression is the case where y is a


linear function of two or more independent variables:

 Such an equation is particularly useful when fitting experimental


data where the variable being studied is often a function of two
other variables.

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

57

24
11/3/2022

Multiple Linear Regression

 For this two-dimensional case, the regression “line” becomes a


“plane”

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

58

Multiple Linear Regression

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

59

25
11/3/2022

Multiple Linear Regression

 Use multiple linear regression to fit this data:

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

60

Multiple Linear Regression

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

61

26
11/3/2022

Multiple Linear Regression

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

62

Interpolation

 Newton Polynomial

 Lagrange Polynomial

 Polynomial Coefficient

 Inverse Interpolation

 Splines

 Multidimensional Interpolation
Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

63

27
11/3/2022

Interpolation

 You will frequently have occasion to estimate intermediate


values between precise data points.

 The most common method used for this purpose is


polynomial interpolation with the the general formula for
an nth-order polynomial is for n + 1 data points.

 There is one and only one polynomial of order n that passes


through all the points.

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

64

Interpolation
 There is only one straight line
(first-order polynomial) that
connects two points.

 Only one parabola (second


order polynomial) connects a
set of three points.

 Only one cubic (third order


polynomial) connects a set of
four points.

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

65

28
11/3/2022

Newton Polynomial

 The simplest form of interpolation


is to connect two data points with a
straight line. This technique, called
linear interpolation, is depicted
graphically, using similar triangles:

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

66

Newton Polynomial

 Estimate the natural logarithm of 2 using linear


interpolation.

 If ln 1 = 0 and ln 6 = 1.791759.

 If ln 1 = 0 and ln 4 =1.386294.

(ln 2 = 0.6931472)

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

67

29
11/3/2022

Newton Polynomial

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

68

Newton Polynomial

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

69

30
11/3/2022

Newton Polynomial

 The error in previous Example resulted from our


approximating a curve with a straight line.

 A strategy for improving the estimate is to introduce some


curvature into the line connecting the points.

 If three data points are available, this can be accomplished


with a second-order polynomial (also called a quadratic
polynomial or a parabola):

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

70

Newton Polynomial

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

71

31
11/3/2022

Newton Polynomial

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

72

Newton Polynomial

 Estimate the natural logarithm of 2 using quadratic


interpolation.

 If ln 1 = 0, ln 4 = 1.386294, and ln 6 = 1.791759.

(ln 2 = 0.6931472)

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

73

32
11/3/2022

Newton Polynomial

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

74

Newton Polynomial

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

75

33
11/3/2022

Newton Polynomial

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

76

Newton’s divided-difference interpolating


polynomial

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

77

34
11/3/2022

Newton’s divided-difference interpolating


polynomial

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

78

Newton Polynomial

 Estimate the natural logarithm of 2 using quadratic


interpolation.

 If xo = 1, x1 = 4, x2 = 6, x3 = 5

 ln 5 = 1.609438.

(ln 2 = 0.6931472)

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

79

35
11/3/2022

Newton Polynomial

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

80

Newton Polynomial

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

81

36
11/3/2022

Newton Polynomial

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

82

Lagrange Polynomial

 The Lagrange interpolating polynomial is simply a


reformulation of the Newton polynomial that avoids the
computation of divided differences. It can be represented:

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

83

37
11/3/2022

Lagrange Polynomial

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

84

Lagrange Polynomial

 Use a Lagrange interpolating polynomial of the first and


second order to evaluate ln 2 on the basis of the following
data:

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

85

38
11/3/2022

Lagrange Polynomial

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

86

Verification Using Excel

 Excel Trendline

 The data analysis Toolpack

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

87

39
11/3/2022

Trendline

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

88

Trendline

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

89

40
11/3/2022

Toolpack

        

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

90

Toolpack

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

91

41
11/3/2022

Toolpack

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

92

Toolpack

Dr. Asmaa Moddather – Numerical Analysis – Fall 2022

93

42

You might also like