Topographic Contour and Curve Fitting

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 41

Topographic mapping

and curve fitting

Mahesh Shrivastava
What is the elevation of point A and C ?
What is the slope between points A and C?
points of 105
points of 100 100

98 102

100 105
D

101 108

105
Questions 1:
Make the contour of the map 0.5unit
1.5 1.0 1.5 1.5 1.0 1.5

1.0 2.0 1.0 1.0 0.0 1.0

2.0 0.0 -1.0 0.0


3.0 2.0

1.0 2.0 1.0 1.0 0.0 1.0

1.5 1.5 1.5 1.5 1.5 1.5


Questions 2:
Make the contour of the map 0.5unit
1.0 1.0 1.0 1.0 1.0 1.0

1.0 -2.0 1.0 1.0 0.0 1.0

-2.0 -3.0 -2.0 0.0 -1.0 0.0

1.0 -2.0 1.0 1.0 0.0 1.0

1.0 1.0 1.0 1.0 1.0 1.0


Curve Fitting
Data distribution

x
Data distribution

x
Data distribution and straight line fit

x
Least Squares Method

If our fit is a straight line f (x ) = ax + b

2 2 2 2
Error = ∑ d i2 = [y1 − f (x1 )] + [y2 − f (x2 )] + [y3 − f (x3 )] + [y4 − f (x4 )]

N N
2 2
Error = ∑ [yi − f (xi )] = ∑ [yi − (axi + b )]
i =1 i =1
•The ‘best’ line has minimum error between line and data points
•This is called the least squares approach, since square of the error
is minimized.
N
⎧ 2⎫
Minimize⎨ Error = ∑ [yi − (axi + b )] ⎬
⎩ i =1 ⎭
Take the derivative of the error with respect to a and b, set each to zero

⎛ N 2⎞
∂⎜ ∑ [yi − (axi + b )] ⎟
∂ (Error )
= ⎝ i =1 ⎠ =0
∂a ∂a

⎛ N 2⎞
∂⎜ ∑ [yi − (axi + b )] ⎟
∂ (Error )
= ⎝ i =1 ⎠ =0
∂b ∂b
∂ (Error ) N
= −2∑ xi [yi − (axi + b )] = 0
∂a i =1

∂ (Error ) N
= −2∑ [yi − (axi + b )] = 0
∂b i =1

Solve for the a and b so that the previous two equations both = 0
N N N
2
a ∑ x + b∑ xi = ∑ xi yi
i
i =1 i =1 i =1

N N
a ∑ xi + bN = ∑ yi
i =1 i =1

put these into matrix form

N
⎡ ⎤ ⎡N ⎤
⎢N ∑ xi ⎥
b ⎢ ∑ yi ⎥
⎢ i =1
⎥ ⎡⎢ ⎤⎥ = ⎢ i =1 ⎥
⎢N N

2 ⎣ ⎦ a ⎢ N

⎢∑ xi ∑ xi ⎥ ⎢∑ xi yi ⎥
⎣ i =1 i =1 ⎦ ⎣ i =1 ⎦
N N N
N ∑ xi yi − ∑ xi ∑ yi
i =1 i =1 i =1
a= 2
N N
⎡ ⎤
2
N ∑ x − ⎢∑ xi ⎥i
i =1 ⎣ i =1 ⎦

N N N N
2
∑ y ∑x −∑x ∑x
i =1
i
i =1
i
i =1
i
i =1
i yi
b= 2
N N
⎡ ⎤
2
N ∑ x − ⎢∑ xi ⎥i
i =1 ⎣ i =1 ⎦
Linear Regression Analysis

• Linear curve fitting


• Polynomial curve fitting
• Power Law curve fitting: y=axb
• ln(y) = ln(a)+bln(x)
• Exponential curve fitting: y=aebx
• ln(y)=ln(a)+bx
Goodness of fit and the correlation coefficient

• A measure of how good the regression line as a


representation of the data.
• It is possible to fit two lines to data by
• (a) treating x as the independent variable : y=ax+b, y as
the dependent variable or by
• (b) treating y as the independent variable and x as the
dependent variable.
• This is described by a relation of the form x= a'y +b'.
• The procedure followed earlier can be followed again to
find best values of a’ and b’.
N N N
' 2 '
a ∑ y + b ∑ yi = ∑ xi yi
i
i =1 i =1 i =1

N N
' '
a ∑ yi + b N = ∑ xi
i =1 i =1

put these into matrix form

N
⎡ ⎤ ⎡N ⎤
⎢N ∑ yi ⎥ '
⎡b ⎤ ⎢ ∑ xi ⎥
i =1
⎢ ⎥ ⎢ ⎥ = ⎢ i =1 ⎥
⎢N N
⎥ ⎢
2 ⎣ ⎦ a '
⎥ ⎢ N

⎢ ∑ yi ∑ yi ⎥ ⎢∑ xi yi ⎥
⎣ i =1 i =1 ⎦ ⎣ i =1 ⎦
N N N
N ∑ xi yi − ∑ xi ∑ yi
' ' ' i =1 i =1 i =1
x = a y+b ⇒ a = 2
N N
⎡ 2 ⎤
N ∑ y − ⎢ ∑ yi ⎥
i
i =1 ⎣ i =1 ⎦
Recast the second fit line as:

1 b'
y = ' x− '
a a
1 is the slope of this second line, which not same as
a' the first line
•The ratio of the slopes of the two lines is a measure of
how good the form of the fit is to the data.
•In view of this the correlation coefficient ρ defined
through the relation

2 slope of first Regression line '


ρ = = aa
Slope of second Regression line
N N N
N ∑ xi yi − ∑ xi ∑ yi
i =1 i =1 i =1
y = ax + b ⇒ a = 2
N N
⎡ ⎤2
N ∑ x − ⎢∑ xi ⎥ i
i =1 ⎣ i =1 ⎦
N N N
N ∑ xi yi − ∑ xi ∑ yi
' ' ' i =1 i =1 i =1
x = a y+b ⇒ a = 2
N N
⎡ ⎤ 2
N ∑ y − ⎢ ∑ yi ⎥ i
i =1 ⎣ i =1 ⎦
N N N 2
⎧ ⎫
⎨ N ∑ xi yi − ∑ xi ∑ yi ⎬
ρ2 = ⎩ i =1 i =1 i =1 ⎭
⎧⎪ N 2 ⎡ N ⎤ 2 ⎫⎪⎧⎪ N 2 ⎡ N ⎤ 2 ⎫⎪
⎨ N ∑ xi − ⎢∑ xi ⎥ ⎬⎨ N ∑ yi − ⎢∑ yi ⎥ ⎬
⎪⎩ i =1 ⎣ i =1 ⎦ ⎪⎭⎪⎩ i =1 ⎣ i =1 ⎦ ⎪⎭

⎧ N N N

⎨ N ∑ xi yi − ∑ xi ∑ yi ⎬
ρ =± ⎩ i =1 i =1 i =1 ⎭
⎧⎪ N 2 ⎡ N ⎤ 2 ⎫⎪⎧⎪ N 2 ⎡ N ⎤ 2 ⎫⎪
⎨ N ∑ xi − ⎢∑ xi ⎥ ⎬⎨ N ∑ yi − ⎢∑ yi ⎥ ⎬
⎪⎩ i =1 ⎣ i =1 ⎦ ⎪⎭⎪⎩ i =1 ⎣ i =1 ⎦ ⎪⎭
ρ2=1.000 ρ2=0.991 ρ2=0.904

ρ2=0.821 ρ2=0.493 ρ2=0.0526


(a) (b)
linear fitting with (a) small and (b) large residual errors
Correlation Coefficient
• The sign of the correlation coefficient is determined by the sign
of the covariance.
• If the regression line has a negative slope the correlation
coefficient is negative
• while it is positive if the regression line has a positive slope.
• The correlation is said to be perfect if ρ = ± 1.
• The correlation is poor if ρ ≈ 0.
• Absolute value of the correlation coefficient should be greater
than 0.5 to indicate that y and x are related!
• In the case of a non-linear fit a quantity known as the index of
correlation is defined to determine the goodness of the fit.
• The fit is termed good if the variance of the deviates is much
less than the variance of the y’s.
• It is required that the index of correlation defined below to be
close to ±1 for the fit to be considered good.
N
2
∑ {y
i =1
i − f (xi )}
ρ = ± 1− 2
N
⎧ ⎫
N ⎪ ∑ yi ⎪
⎪ ⎪
⎨ yi −
i =1

i =1 ⎪ N ⎪

⎪⎩ ⎪⎭
Example

N N N N N N N
2
N ∑ xi yi − ∑ xi ∑ yi ∑ y ∑x −∑x ∑x
i =1
i
i =1
i
i =1
i
i =1
i yi
a= i =1 i =1 i =1 b= 2
2 N
N
⎡ N
⎤ ⎡N ⎤
2
N ∑ xi2 − ⎢∑ xi ⎥ N ∑ x − ⎢∑ xi ⎥
i
i =1 ⎣ i =1 ⎦ i =1 ⎣ i =1 ⎦
Find out the curve model and correlation of following data sets.

(i)
x 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
y 2 3 6 4 5 7 9 9 10 11

(ii)
x 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
y 11 10 9 8 6 5 5 5 4 2

You might also like