You are on page 1of 60

Projects ???

1 http://numericalmethods.eng.usf.edu
Interpolants
Polynomials are the most common
choice of interpolants because they
are easy to:

Evaluate
Differentiate, and
Integrate.

2 http://numericalmethods.eng.usf.edu
Newton’s Divided Difference
Method

3 http://numericalmethods.eng.usf.edu
Newton’s Divided Difference
Method
İf two data points are availablee as {x0,f(x0)} and
{x1,f(x1)}, the points can be connected by a straight
line to obtain the simplest form of
interpolation,namely,linear interpolation. (see
Fig.5.4.)The formula for linear interpolation can be
derived by considering the similar triangles ADE and
ABC, which give
DE BC f1(x) – f(x0) f(x1) – f(x0)
= , or =
AE AC x –x0 x1 – x0
4 http://numericalmethods.eng.usf.edu
Newton’s Divided Difference
Method
Linear interpolation: Given ( x0 , y 0 ), ( x1 , y1 ), pass a
linear interpolant through the data
f1 ( x)  b0  b1 ( x  x0 )

where
b0  f ( x0 )
f ( x1 )  f ( x0 )
b1 
x1  x0

5 http://numericalmethods.eng.usf.edu
Example
The path of a rapid laser is given by these specifications.
If the laser is traversing from x = 2 to x = 4.25 in a
linear path, find the value of y at x = 4 using the
Newton’s Divided difference polynomial method.

x (m) y (m) Path of a robot

2 7.2 8
7
4.25 7.1 6
5

5.25 6 4
Y

7.81 5 2
1
0
9.2 3.5 0 5 10 15

10.6 5 X

6 http://numericalmethods.eng.usf.edu
Linear Interpolation
7.2
7.2

y ( x)  b0  b1 ( x  x0 ) 7.18

x0  2.00, y ( x0 )  7.2 ys
7.16

f ( range)
7.14

x1  4.25, y ( x1 )  7.1 
f x desired 
7.12

b0  y ( x0 )  7.2 7.1

y (x 1 )  y (x 0 ) 7.1  7.2 7.1 7.08

b1  
5 0 5 10
x s 10 x s  range x desired x s  10

x1 x 0 4.25  2.00
0 1

 0.04444

7 http://numericalmethods.eng.usf.edu
Linear Interpolation (contd)
7.2
7.2

7.18

7.16
ys

f ( range)
7.14

f x desired 
7.12

7.1

7.1 7.08
5 0 5 10
x s 10 x s  range x desired x s  10
0 1

y ( x)  b0  b1 ( x  x0 )
 7.2  0.04444( x  2.00), 2.00  x  4.25
At x  4
x(4.00)  7.2  0.04444(4.00  2.00)
8  7.1111 in. http://numericalmethods.eng.usf.edu
Example:find value of f(x)=e0.5x Use the
results to estimate the value of f at x=1
x0=0 and x1= 2

f(x0)= f(0) = e0 =1.0


f(x1) = f(2) = e1.0= 2.718282
f1(x) = b0 + a1 (x-x0)
a0=f(x0) = 1.0
f(x1)-f(x0) 2.718282 – 1.0
a1 = =
x1 – x0 2.0 – 0.0
a1=0.859141

9 http://numericalmethods.eng.usf.edu
Example:find value of f(x)=e0.5x Use the
results to estimate the value of f at x=1
x0=0 and x1= 2

f1(x) = 1.0 + 0.859141x


X=1.0
f1(1) = 1.0 + 0.859141(1) = 1.859141

exect value :f(1) = e0.5 = 1.648721

10 http://numericalmethods.eng.usf.edu
Quadratic Interpolation

11 http://numericalmethods.eng.usf.edu
Quadratic Interpolation
Given ( x0 , y 0 ), ( x1 , y1 ), and ( x 2 , y 2 ), fit a quadratic interpolant through the data.
f 2 ( x)  b0  b1 ( x  x0 )  b2 ( x  x0 )( x  x1 )

b0  f ( x0 )

f ( x1 )  f ( x0 )
b1 
x1  x 0

f ( x 2 )  f ( x1 ) f ( x1 )  f ( x 0 )

x 2  x1 x1  x0
b2 
x 2  x0

12 http://numericalmethods.eng.usf.edu
Example
The path of a rapid laser is given by these specifications.
If the laser is traversing from x = 2 to x = 4.25 to
x=5.25 using a quadratic path, find the value of y at x
= 4 using the Newton’s Divided difference polynomial
method.

x (m) y (m) Path of a robot

2 7.2 8
7
4.25 7.1 6
5

5.25 6 4
Y

7.81 5 2
1
0
9.2 3.5 0 5 10 15

10.6 5 X

13 http://numericalmethods.eng.usf.edu
Quadratic Interpolation (contd)
8
7.56258

7.5

ys

f ( range)
7

f x desired 

6.5

6 6
2 2.5 3 3.5 4 4.5 5 5.5
2 x s  range x desired 5.25

y ( x)  b0  b1 ( x  x0 )  b2 ( x  x0 )( x  x1 )
x 0  2.00, y ( x0 )  7.2
x1  4.25, y ( x1 )  7.1

14
x 2  5.25, y ( x 2 )  6.0 http://numericalmethods.eng.usf.edu
Quadratic Interpolation (contd)
b0  y ( x0 )
 7. 2
y ( x1 )  y ( x0 ) 7.1  7.2
b1  
x1  x 0 4.25  2.00
 0.04444
y ( x 2 )  y ( x1 ) y ( x1 )  y ( x0 ) 6.0  7.1 7.1  7.2
 
x 2  x1 x1  x 0
b2   5.25  4.25 4.25  2.00
x 2  x0 5.25  2.00
 1.1  0.04444

3.25
 0.32479
15 http://numericalmethods.eng.usf.edu
Quadratic Interpolation (contd)
y ( x)  b0  b1 ( x  x0 )  b2 ( x  x0 )( x  x1 )
 7.2  0.04444( x  2.00)  0.32479( x  2.00)( x  4.25), 2.00  x  5.25
At x  4,
y (4.00)  7.2  0.04444(4.00  2.00)  0.32479(4.00  2.00)( 4.00  4.25)
 7.2735 in.
The absolute relative approximate error a obtained between the
results from the first and second order polynomial is
7.2735  7.1111
a   100
7.2735

 2.2327%
16 http://numericalmethods.eng.usf.edu
General Form
f 2 ( x)  b0  b1 ( x  x0 )  b2 ( x  x0 )( x  x1 )
where
b0  f [ x0 ]  f ( x0 )
f ( x1 )  f ( x 0 )
b1  f [ x1 , x0 ] 
x1  x0
f ( x 2 )  f ( x1 ) f ( x1 )  f ( x0 )

f [ x 2 , x1 ]  f [ x1 , x0 ] x 2  x1 x1  x0
b2  f [ x 2 , x1 , x0 ]  
x 2  x0 x 2  x0
Rewriting
f 2 ( x)  f [ x0 ]  f [ x1 , x0 ]( x  x0 )  f [ x 2 , x1 , x0 ]( x  x0 )( x  x1 )

17 http://numericalmethods.eng.usf.edu
General Form
Given (n  1) data points,  x0 , y 0  ,  x1 , y1  ,......,  x n 1 , y n 1  ,  x n , y n  as
f n ( x)  b0  b1 ( x  x0 )  ....  bn ( x  x0 )( x  x1 )...( x  x n 1 )
where
b0  f [ x0 ]
b1  f [ x1 , x0 ]
b2  f [ x 2 , x1 , x0 ]

bn 1  f [ x n 1 , x n  2 ,...., x 0 ]
bn  f [ x n , x n 1 ,...., x0 ]

18 http://numericalmethods.eng.usf.edu
General form
The third order polynomial, given ( x0 , y 0 ), ( x1 , y1 ), ( x 2 , y 2 ), and ( x3 , y 3 ), is

f 3 ( x)  f [ x0 ]  f [ x1 , x0 ]( x  x 0 )  f [ x 2 , x1 , x 0 ]( x  x0 )( x  x1 )
 f [ x3 , x 2 , x1 , x0 ]( x  x0 )( x  x1 )( x  x 2 )
b0
x0 f ( x0 ) b1
f [ x1 , x0 ] b2
x1 f ( x1 ) f [ x 2 , x1 , x0 ] b3
f [ x 2 , x1 ] f [ x3 , x 2 , x1 , x0 ]
x2 f ( x2 ) f [ x3 , x 2 , x1 ]
f [ x3 , x 2 ]
x3 f ( x3 )

19 http://numericalmethods.eng.usf.edu
20 http://numericalmethods.eng.usf.edu
Example
The path of a rapid laser is given by these
specifications. Find the path traversed by the
laser using the Newton’s Divided Difference
Polynomial method.
x (m) y (m) Path of a robot

2 7.2 8
7
4.25 7.1 6
5

5.25 6 4
Y

7.81 5 2
1
0
9.2 3.5 0 5 10 15

10.6 5 X

21 http://numericalmethods.eng.usf.edu
Example
The value of y profile is chosen as
y ( x)  b0  b1 ( x  x0 )  b2 ( x  x0 )( x  x1 )  b3 ( x  x0 )( x  x1 )( x  x 2 )
 b4 ( x  x0 )( x  x1 )( x  x 2 )( x  x3 )  b5 ( x  x0 )( x  x1 )( x  x 2 )( x  x3 )( x  x 4 )
Using the six points,
x0  2.00, y ( x0 )  7.2 x1  4.25, y ( x1 )  7.1
x 2  5.25, y ( x 2 )  6.0 x3  7.81, y ( x3 )  5.0
x 4  9.20, y ( x 4 )  3.5 x5  10.60, y ( x5 )  5.0
The values of the constants are found to be
b0  7.2 b1  0.04444 b2  0.32479
b3  0.090198 b4  0.023009 b5  0.0072922

22 http://numericalmethods.eng.usf.edu
Example
H en ce
y (x )  b 0  b 1 ( x  x 0 )  b 2 ( x  x 0 )( x  x 1 )  b 3 ( x  x 0 )( x  x 1 )( x  x 2 )
 b 4 ( x  x 0 ) ( x  x 1 ) ( x  x 2 ) ( x  x 3 )  b 5 ( x  x 0 )( x  x 1 ) ( x  x 2 ) ( x  x 3 ) ( x  x 4 )

 7 . 2  0 . 04 4 ( x  2 )  0 . 32479 ( x  2 )( x  4 . 2 5 )
 0 . 090198 ( x  2 )( x  4 . 2 5 )( x  5 . 2 5 )
 0 . 0230 9 ( x  2 )( x  4 . 2 5 ) ( x  5 . 2 5 ) ( x  7 . 8 1 )
 0 . 0 7292 ( x  2 ) ( x  4 . 2 5 )( x  5 . 2 5 ) ( x  7 . 8 1 ) ( x  9 . 2 )

y ( x )   30 . 898  41 . 34 x  15 . 85 x 2
 2 . 7862 x 3
 0 . 23091 x 4
 0 . 0 7292 x 5, 2  x  10 . 6

23 http://numericalmethods.eng.usf.edu
Example
Path of a robot

10

7 7.2 7.1

6 6

5 5 5
Y

4
3.5
3

0
0 2 4 6 8 10 12
X

y ( x )   30 . 898  41 . 344 x  15 . 855 x 2


 2 . 7862 x 3
 0 . 23091 x 4
 0 . 0072922 x5, 2  x  10 . 6

24 http://numericalmethods.eng.usf.edu
Newton-Gregory forward interpolation
formula

The general Newton’s interpolation


formula can be simplified when the data
points are equally spaced along x-axis.
The resulting formulas are also known
as Newton-Gregory formulas. İf h
denotes the interval between any two
concecutive values of xi(xi+1-xi=h) ve
can write
xi=x0 + ih , i=1,2,….,n.
25 http://numericalmethods.eng.usf.edu
Newton-Gregory forward interpolation
formula

In this case, the coefficients of the interpolation


polynominal a0,a1,….,an can be expressed as,
∆0f0
a0=f(x0) =
h0

∆1f0 ∆0f0

a1 = =
h1 h0

26 http://numericalmethods.eng.usf.edu
Newton-Gregory forward interpolation
formula
∆nf0
an =
n!hn
∆jf0 is the jth-order forward difference(j=1,2,……,n)
Using these relations we can write the nth-order
Newton’s interpolation polynominal as;
∆f0 ∆2f0
fn(x) =f(x0) + (x-x0) + (x-x0)(x-x0-h) +….
27 h 2!h2 http://numericalmethods.eng.usf.edu
Interpolation using Splines ,Why Splines ?
1
f ( x) 
1  25 x 2
Table : Six equidistantly spaced points in [-1, 1]
1
x y
1  25 x 2

-1.0 0.038461

-0.6 0.1

-0.2 0.5

0.2 0.5

0.6 0.1

1.0 0.038461 Figure : 5th order polynomial vs. exact function

28 http://numericalmethods.eng.usf.edu
Why Splines ?
16th Order
Polynomial

Original
Function

4th Order
Polynomial

8th Order
Polynomial

Figure : Higher order polynomial interpolation is a bad idea


29 http://numericalmethods.eng.usf.edu
30 http://numericalmethods.eng.usf.edu
31 http://numericalmethods.eng.usf.edu
32 http://numericalmethods.eng.usf.edu
33 http://numericalmethods.eng.usf.edu
34 http://numericalmethods.eng.usf.edu
Linear Interpolation
Given  x0 , y0  ,  x1 , y1  ,......,  x n 1 , y n1  x n , y n  , fit linear splines to the data. This simply involves
forming the consecutive data through straight lines. So if the above data is given in an ascending
order, the linear splines are given by  yi  f ( xi ) 
Figure : Linear splines

35 http://numericalmethods.eng.usf.edu
Linear Interpolation (contd)
f ( x1 )  f ( x 0 )
f ( x )  f ( x0 )  ( x  x 0 ), x 0  x  x1
x1  x 0

f ( x 2 )  f ( x1 )
 f ( x1 )  ( x  x1 ), x1  x  x 2
x2  x1
.
.
.
f ( x n )  f ( x n 1 )
 f ( x n 1 )  ( x  x n 1 ), x n 1  x  x n
x n  x n 1

Note the terms of


f ( xi )  f ( x i1 )
xi  x i 1

in the above function are simply slopes between xi 1 and x i .


36 http://numericalmethods.eng.usf.edu
Example
The path of a rapid laser is given by these specifications.
If the laser is traversing from x = 2 to x = 4.25 in a linear
path, find the value of y at x = 4 using the linear spline
interpolation method.

x (m) y (m) Path of a robot

2 7.2 8
7
4.25 7.1 6
5

5.25 6 4
Y

7.81 5 2
1
0
9.2 3.5 0 5 10 15

10.6 5 X

37 http://numericalmethods.eng.usf.edu
Linear Interpolation
x 0  2.00, y ( x0 )  7.2
7.2
7.2

x1  4.25, y ( x1 )  7.1
7.18

y ( x1 )  y ( x0 )
y ( x)  y ( x 0 )  ( x  x0 ) ys
7.16

x1  x 0 f ( range)
7.14

f x desired 
7.1  7.2
 7. 2  ( x  2.00) 7.12

4.25  2.00
7.1

y ( x)  7.2  0.04444( x  2.00) 7.1 7.08


5 0 5 10

At x  4, x s 10
0
x s  range x desired x s  10
1

y (4.00)  7.2  0.04444(4.00  2.00)


 7.1111 in.
38 http://numericalmethods.eng.usf.edu
Linear Interpolation (contd)
Find the path of the robot if it follows linear splines.

The linear spline connecting x = 2.00 and x = 4.25.


y ( x)  7.2  0.04444( x  2.00), 2.00  x  4.25
Similarly
y ( x)  7.1  1.1( x  4.25), 4.25  x  5.25
y ( x)  6.0  0.390625( x  5.25), 5.25  x  7.81
y ( x)  5.0  1.07914( x  7.81), 7.81  x  9.20
y ( x)  3.5  1.07143( x  9.20), 9.20  x  10.60

39 http://numericalmethods.eng.usf.edu
Linear Interpolation (contd)
Find the length of the path traversed by the robot
following linear splines.

T h e le n g th o f th e ro b o t’s p a th c a n b e fo u n d b y s im p ly a d d in g th e le n g th
o f th e lin e s e g m e n ts to g e th e r. T h e le n g th o f a s tra ig h t lin e fro m o n e p o in t

( x 0 , y 0 ) to a n o th e r p o in t ( x 1 , y 1 ) is g iv e n b y (x1  x0 )2  ( y1  y0 )2 .

H e n c e , th e le n g th o f th e lin e a r s p lin e s f r o m x = 2 .0 0 to x = 1 0 .6 0 is

L  ( 4 . 25  2 . 00 ) 2  ( 7 . 1  7 . 2 ) 2  ( 5 . 25  4 . 25 ) 2  ( 6 . 0  7 . 1 ) 2
 ( 7 . 81  5 . 25 ) 2  ( 5 . 0  6 . 0 ) 2  ( 9 . 20  7 . 81 ) 2  ( 3 . 5  5 . 0 ) 2
 ( 10 . 60  9 . 20 ) 2  ( 5 . 0  3 . 5 ) 2

L = 1 0 .5 8 4 m

40 http://numericalmethods.eng.usf.edu
Exemple: find a linear spline to fit the
following data :
i xi f(xi)
Use the results to estimate
the value of f at x= 7.0.
0 14.0
1 2.0
20.0
2 17.0
3.0
3 16.0
4 6.5 23.0
8.0

12.0

41 http://numericalmethods.eng.usf.edu
solution
The data points can be joined by straight
lines to linear spline.since x=7.0 lies in
the interval (6.5 to 8.0) we can find the
equation of the straight line between
x=6.5 and x=8.0 as
f(x3) – f(x2)
f3(x) = f(x2) + (x-x2)
x 3 – x2

42 http://numericalmethods.eng.usf.edu
Solution(con)
f3(x) = 17.0 +((16.0 – 17.0) / (8.0 -6.5)) (x-6.5)
= 21.3333 – 0.6667x
The value of f at x=7.0 can be estimated as
f(7.0)=21.3333-0.6667(7.0) = 16.6664

43 http://numericalmethods.eng.usf.edu
Quadratic Interpolation
Given  x0 , y0  ,  x1 , y1  ,......,  x n 1 , y n 1  ,  x n , y n  , fit quadratic splines through the data. The splines
are given by
f ( x )  a1 x 2  b1 x  c1 , x 0  x  x1

 a 2 x 2  b2 x  c2 , x1  x  x 2
.
.
.
 a n x 2  bn x  cn , x n1  x  x n

Find a i , bi , ci , i  1, 2, …, n

44 http://numericalmethods.eng.usf.edu
Quadratic Interpolation (contd)
Each quadratic spline goes through two consecutive data points
2
a1 x 0  b1 x 0  c1  f ( x0 )

a1 x1  b1 x1  c1  f ( x1 )
2
.
.
.
2
a i xi 1  bi xi 1  ci  f ( xi 1 )
2
a i xi  bi xi  c i  f ( xi ) .
.
.
2
a n x n 1  bn x n1  c n  f ( xn 1 )
2
a n x n  bn xn  cn  f ( x n )

This condition gives 2n equations


45 http://numericalmethods.eng.usf.edu
Quadratic Splines (contd)
The first derivatives of two quadratic splines are continuous at the interior points.
For example, the derivative of the first spline
a1 x 2  b1 x  c1 is 2 a1 x  b1
The derivative of the second spline
a 2 x 2  b2 x  c 2 is 2 a2 x  b2
and the two are equal at x  x1 giving
2 a1 x1  b1  2a 2 x1  b2
2 a1 x1  b1  2a 2 x1  b2  0

46 http://numericalmethods.eng.usf.edu
Quadratic Splines (contd)
Similarly at the other interior points,
2a 2 x 2  b2  2a3 x 2  b3  0
.
.
.
2ai xi  bi  2ai 1 xi  bi 1  0
.
.
.
2a n 1 x n 1  bn 1  2a n x n1  bn  0

We have (n-1) such equations. The total number of equations is (2n)  (n  1)  (3n  1) .
We can assume that the first spline is linear, that is a1  0

47 http://numericalmethods.eng.usf.edu
Quadratic Splines (contd)
This gives us ‘3n’ equations and ‘3n’ unknowns. Once we find the ‘3n’ constants,
we can find the function at any value of ‘x’ using the splines,

f ( x)  a1 x 2  b1 x  c1 , x0  x  x1

 a 2 x 2  b2 x  c 2 , x1  x  x 2
.
.
.
 a n x 2  bn x  c n , x n 1  x  x n

48 http://numericalmethods.eng.usf.edu
Example
The path of a rapid laser is given by these specifications
in Cartesian co-ordinates. Find the length of the path
traversed by the robot using quadratic splines.

x (m) y (m) Path of a robot

2 7.2 8
7
4.25 7.1 6
5

5.25 6 4
Y

7.81 5 2
1
0
9.2 3.5 0 5 10 15

10.6 5 X

49 http://numericalmethods.eng.usf.edu
Solution
Since there are six data points, 7.2
8

five quadratic splines pass through them. 7

y ( x)  a1 x 2  b1 x  c1 , 2.00  x  4.25
6

 a 2 x 2  b2 x  c 2 , 4.25  x  5.25
y

 a 3 x 2  b3 x  c3 , 5.25  x  7.81 4

 a 4 x 2  b4 x  c 4 , 7.81  x  9.20 3.5 3


2 4 6 8 10 12
2 x 10.6
 a5 x 2  b5 x  c5 , 9.20  x  10.60

50 http://numericalmethods.eng.usf.edu
Solution (contd)
Setting up the equations
Each quadratic spline passes through two consecutive data points giving
a1 x 2  b1 x  c1 passes through x = 2.00 and x = 4.25,

a1 (2.00) 2  b1 ( 2.00)  c1  7.2 (1)

a1 (4.25) 2  b1 (4.25)  c1  7.1 (2)


Similarly,
a 2 ( 4.25) 2  b2 ( 4.25)  c 2  7.1 (3)

a 2 (5.25) 2  b2 (5.25)  c 2  6.0 (4)

a3 (5.25) 2  b3 (5.25)  c3  6.0 (5)

a 3 (7.81) 2  b3 (7.81)  c3  5.0 (6)

a 4 (7.81) 2  b4 (7.81)  c 4  5.0 (7)

a 4 (9.20) 2  b4 (9.20)  c 4  3.5 (8)

a5 (9.20) 2  b5 (9.20)  c5  3.5 (9)

a 5 (10.60) 2  b5 (10.60)  c5  5.0 (10)


51 http://numericalmethods.eng.usf.edu
Solution (contd)
Quadratic splines have continuous derivatives at the interior data points
At x = 4.25
2a1 (4.25)  b1  2a 2 (4.25)  b2  0 (11) 7.56258
8

At x = 5.25
7.5

2a 2 (5.25)  b2  2a 3 (5.25)  b3  0 (12) ys

At x = 7.81 f ( range)


f x desired 
7

2a3 (7.81)  b3  2a 4 (7.81)  b4  0 (13)


6.5

At x = 9.20
2a 4 (9.20)  b4  2a5 (9.20)  b5  0 (14) 6 6
2 2.5 3 3.5 4 4.5 5 5.5
2 x s  range x desired 5.25

Assuming the first spline a1 x 2  b1 x  c1 is linear,

a1  0 (15)

52 http://numericalmethods.eng.usf.edu
Solution (contd)
 4 2 1 0 0 0 0 0 0 0 0 0 0 0 0  a1  7.2
18.063 4.25 1 0 0 0 0 0 0 0 0 0 0 0 0  b1   7.1
 0 0 0 18.063 4.25 1 0 0 0 0 0 0 0 0 0 c1
    7.1
    
 0 0 0 27.563 5.25 1 0 0 0 0 0 0 0 0 0  a 2  6.0
 0 0 0 0 0 0 27.563 5.25 1 0 0 0 0 0 0  b2  6.0
 0 0 0 0 0 0 60.996 7.81 1 0 0 0 0 0 0 c 2
  5.0
    
 0 0 0 0 0 0 0 0 0 60.996 7.81 1 0 0 0  a 3  5.0 
 0 0 0 0 0 0 0 0 0 84.64 9.2 1 0 0 0  b3   3.5
 0 0 0 0 0 0 0 0 0 0 0 0 84.64 9.2 1   c 3  3.5
    
 0 0 0 0 0 0 0 0 0 0 0 0 112.36 10.6 1   a 4  5.0 
 8.5 1 0  8.5 1 0 0 0 0 0 0 0 0 0 0   b4   0 
 0 0 0 10.5 1 0  10.5 1 0 0 0 0 0 0 0  c 4   0 
    
0  15.62 1 0 0 a5 
 0 0 0 0 0 0 15.62 1 0 0
 0
 0 0 0 0 0 0 0 0 0 18.4 1 0  18.4  1 0  b5   0 
 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0  c 5   0 

53 http://numericalmethods.eng.usf.edu
Solution (contd)
Solving the above 15 equations gives the 15 unknowns as

i ai bi ci

1 0 -0.04444 7.2889

2 -1.0556 8.9278 -11.777

3 0.68943 -9.3945 36.319

4 -1.7651 28.945 -113.40

5 3.2886 -64.042 314.34

54 http://numericalmethods.eng.usf.edu
Solution (contd)
Therefore, the splines are given by
y ( x)  0.04444 x  7.2889, 2.00  x  4.25

 1.0556 x 2  8.9278 x  11 .777, 4.25  x  5.25

 0.68943 x 2  9.3945 x  36.319, 5.25  x  7.81

 1.7651x 2  28.945 x  113 .40, 7.81  x  9.20

 3.2886 x 2  64.042 x  314.34, 9.20  x  10.60

55 http://numericalmethods.eng.usf.edu
Solution (contd)
8
8

6
The length of a curve of a function y  f (x) from ‘a’ to ‘b’ is given by
b 2
 dy  y

L 1    dx f quadratic( range)


4

a  dx 
In this case, f(x) is defined by five separate functions a = 2.00 to b = 10.60 2

dy d
   0.04444 x  7.2889 , 2.00  x  4.25
dx dx 0 0
2 4 6 8 10


d
dx
  1.0556 x 2  8.9278 x  11 .777 , 4.25  x  5.25
1.5 x range 11


d
dx
 0.68943 x 2  9.3945 x  36.319, 5.25  x  7.81
d
   1.7651x 2  28.945x  113 .40, 7.81  x  9.20
dx

d
dx
 3.2886 x 2  64.042 x  314.34 , 9.20  x  10.60

56 http://numericalmethods.eng.usf.edu
Solution (contd)
4.25 2 5.25 2 7.81 2 9.20 2 10.60 2
 dy   dy   dy   dy   dy 
L 
2.00
1    dx   1      1      1    
 dx  4.25  dx  5.25  dx  7.81  dx 

9.20
1  
 dx 

4.25 5.25 7.81

 1    0.04444  dx   1    2.1111 x  8.9278 dx   1  1.3788 x  9.3945 dx


2 2 2

2.00 4.25 5.25
9.20 10.60

 1    3.5302 x  28.945 dx   1   6.5772 x  64.042  dx


2 2

7.81 9.20

 2.2522  1.5499  3.6596  2.6067  3.8080

 13.876

57 http://numericalmethods.eng.usf.edu
Comparison
Compare the answer from part (a) to linear spline
result and fifth order polynomial result.
We can find the length of the fifth order polynomial result in a similar fashion to the quadratic
splines without breaking the integrals into five intervals. The fifth order polynomial result
through the six points is given by
y ( x)  30.898  41.344 x  15.855 x 2  2.7862 x 3  0.23091x 4  0.0072923x 5 , 2  x  10.6
Therefore,
b 2
 dy 
L 1    dx
a  dx 
10.60
  1   41.344  31.710 x  8.3586 x 2  0.92364 x 3  0.036461x 4  dx
2.00

 13.133
58 http://numericalmethods.eng.usf.edu
C programming
#include<stdio.h>
/* interpolation using splines */
int main(void)
{
int n,i,i1,i2;
float x[30],fx[30],xx,ffx,a,b;
printf("Enter number of datapoints\n");
scanf("%d",&n);
printf("enter data points (values of x) \n");
for( i=0;i<n;i++)
scanf("%f",&x[i]);
printf(" enter function values (fx) \n");
for( i=0;i<n;i++) scanf("%f",&fx[i]);

59 http://numericalmethods.eng.usf.edu
C programming
printf(" enter interval x\n");
scanf("%f%f",&a,&b);
printf(" enter index of interval\n");
scanf("%d%d",&i1,&i2);
printf(" enter to be estimated value of x\n");
scanf("%f",&xx);
ffx=fx[i1]+((fx[i2]-fx[i1])/(b-a))*(xx-a);
printf(" at %10.3f ",xx);
printf(" function values \n");
printf("%10.3f",ffx);
return 0;
}
60 http://numericalmethods.eng.usf.edu

You might also like