# Applied Mathematics and Computation 156 (2004) 499–505

www.elsevier.com/locate/amc

Lagrange interpolation to compute
the derivatives of a function
M.T. Rashed
Department of Mathematics, Faculty of Science, Sohag University, Sohag 82516, Egypt

Abstract
Recently eﬀorts have been made to quantify the diﬃculties in numerically to compute
the derivative of a function [Computing Methods, Pergamon Press, Oxford, vol. 1, 1965;
Comput. Math. Appl. 19 (5) (1990) 1; Numerical Analysis, Wiley, New York, 1955] The
only disadvantage of approximation by Chebyshev polynomials lies in the fact that the
abscissas xi cannot be chosen freely. On other hand, Lagrange interpolation is suitable
to use with equal or nonequal step. This paper describes a method to compute the ﬁrst
or the second derivative of a function. The method is tested by diﬀerent examples.
Ó 2003 Elsevier Inc. All rights reserved.
Keywords: Lagrange interpolation; Indeﬁnite integral; Chebyshev interpolation

1. Introduction
Lagrange interpolation of a function y 0 ðxÞ is given by (for further reading,
see Refs. [1–3])
y 0 ðxÞ ¼

n
X

yj0 ‘j;n ðxÞ;

ð1:1Þ

A 6 x 6 B;

j¼0

where 

n 
Y
x  xk
‘j;n ðxÞ ¼
;
xj  xk

xk ¼ A þ kh;

BA
;
n

k¼0
k6¼j

E-mail address: taha_123452002@yahoo.com (M.T. Rashed).
0096-3003/\$ - see front matter Ó 2003 Elsevier Inc. All rights reserved.
doi:10.1016/j.amc.2003.08.025

k ¼ 0ð1Þn:

500

M.T. Rashed / Appl. Math. Comput. 156 (2004) 499–505

Integrating both side of (1.1) from A to x
n
X

yðxÞ  yðAÞ ¼

bj ðxÞyj0 ;

ð1:2Þ

j¼0

where
Z

bj ðxÞ ¼ 

n 
Y
t  xk
dt:
xj  xk

x

A

ð1:3Þ

k¼0
k6¼j

The integral in (1.3) may be computed approximately as follows 

Z
n  xA
t þ xþA 
xk
xA 1 Y
2
2
bj ðxÞ ¼
dt;
2
xj  xk 
1

ð1:3Þ

k¼0
k6¼j 

N
n  xA
Y
t þ xþA 
xk
xA X
2 s
2
bs
;
2 s¼0
xj  xk

bj ðxÞ ¼

ð1:3aÞ

k¼0
k6¼j

bs ¼  

N 00
2ds X
ksp
Ik cos
;
N
N k¼0

8
< 2;
Ik ¼ 0;
: 2

1k 2

dk ¼

k ¼ 0;
k is odd;
k is even;

;

0:5;
1;

k ¼ 0; N ;
0 < k < N;

sp
;
N

s ¼ 0ð1ÞN :

ts ¼ cos

The problem in using (1.2) to ﬁnd the ﬁrst derivative of yðxÞ is bj ðx0 Þ ¼ 0, 8j.
To remove this diﬃculty, we may choose x by zi ¼ BA
cosðði0:45Þp
Þ þ BþA
.
2
2
n
Hence, Eq. (1.2) becomes
yðzi Þ  yðAÞ ¼

n
X

bj ðzi Þy 0 ðxj Þ;

i ¼ 0ð1Þn:

ð1:4Þ

j¼0

Eq. (1.4) give the ﬁrst derivative of the function yðxÞ at points xi ¼ A þ ih,
h ¼ BA
, i ¼ 0ð1Þn.
n

M.T. Rashed / Appl. Math. Comput. 156 (2004) 499–505

501

2. Second derivative of a function
Consider Lagrange interpolation of the second derivative of a function y 00 ðxÞ
may be
y 00 ðxÞ ¼

n
X

yj00 ‘j;n ðxÞ;

A 6 x 6 B:

j¼0

Integrating twice from A to x
y 0 ðxÞ  y 0 ðAÞ ¼

n
X

yj00 bj ðxÞ

ð2:1Þ

j¼0

and
yðxÞ  yðAÞ  ðx  AÞy 0 ðAÞ ¼

n
X

yj00 cj ðxÞ;

ð2:2Þ

j¼0

where
cj ðxÞ ¼

Z
A

x

Z

x

‘j;n ðtÞ dt dx ¼

Z

A

x

ðx  tÞ‘j;n ðtÞ dt;
A

 

xA
ðx  AÞ
xA
xþA
t

‘j;n
dt;
2
2
2
2 
1

n  xA 

N
t þ xþA 
xk
xA X
xA
ðx þ AÞ Y
2 s
2
ts 
cj ðxÞ ¼
bs x 
:
2 s¼0
2
2
xj  xk
cj ðxÞ ¼

xA
2

Z

1

x

k¼0
k6¼j

Also, the problem in using (2.2) is cj ðx0 Þ ¼ 0, 8j. To remove that problem we
may choose x by zi ¼ BA
cosðði0:45Þp
Þ þ BþA
, i ¼ 0ð1Þn. Eq. (2.2) has the form
2
2
n
yðzi Þ  yðAÞ  ðzi  AÞy 0 ðAÞ ¼

n
X

cj ðzi Þyj00 ;

i ¼ 0ð1Þn:

ð2:3Þ

j¼0

Eq. (2.3) gives the second derivative of yðxÞ at the points xi ¼ A þ ih, h ¼ BA
,
n
i ¼ 0ð1Þn. If y 0 ðAÞ is not well known, let x ¼ B in (2.2)
"
#
n
X
1
yðBÞ  yðAÞ 
y 0 ðAÞ ¼
cj ðBÞyj00 :
ð2:4Þ
BA
j¼0
Substitute from (2.4) in (2.1) and (2.2)

n

X
1
1
½yðBÞ  yðAÞ
¼
cj ðBÞ yj00
bj ðxÞ 
y 0 ðxÞ 
BA
BA
j¼0

ð2:5Þ

502

M.T. Rashed / Appl. Math. Comput. 156 (2004) 499–505

and
yðxÞ 

n

X
xA
xA
½yðBÞ  yðAÞ
 yðAÞ ¼
cj ðBÞ yj00 :
cj ðxÞ 
BA
BA
j¼0

ð2:6Þ

On other hand, we can use relation (1.4) to ﬁnd y 0 ðAÞ ﬁrstly and hence use (2.3).
It is clear that the suggested method can be extended to n-derivative of a
function.

3. Numerical examples
3.1. First derivatives
ð1Þ yðxÞ ¼ loge ðx þ 3Þ;

1
y 0 ðxÞ ¼ xþ3
;

ð2Þ yðxÞ ¼ ex ;

y 0 ðxÞ ¼ ex ;

ð3Þ yðxÞ ¼ tan1 x;

1
y 0 ðxÞ ¼ 1þx
2 ;

ð4Þ yðxÞ ¼ cosðp2 xÞ;

y 0 ðxÞ ¼  p2 sinðp2 xÞ;

ð5Þ yðxÞ ¼ tan1 ð4x þ 3Þ;

4
y 0 ðxÞ ¼ 1þð4xþ3Þ
2 ;

ð6Þ yðxÞ ¼ ðx þ 3Þ

xþ3

;

2

y 0 ðxÞ ¼ ðx þ 3Þ

xþ3

½1 þ loge ðx þ 3Þ
;

2

ð7Þ yðxÞ ¼ ex ;

y 0 ðxÞ ¼ 2xex ;

ð8Þ yðxÞ ¼ ex loge ðx þ 3Þ;

1
y 0 ðxÞ ¼ ex ½xþ3
þ loge ðx þ 3Þ
:

(i) rn , for the ﬁrst derivative A ¼ 0, B ¼ 1:0
Examples n

1

2

3

4

2
3
4
5
6
7
8
9
10

3.6D)04
1.7D)05
1.1D)06
7.9D)08
5.9D)09
4.4D)10
3.1D)11
2.1D)12
1.4D)13

1.6D)02
6.9D)04
2.8D)05
1.2D)06
4.3D)08
1.4D)09
3.7D)11
8.8D)13
1.4D)13

2.6D)02
2.6D)03
4.2D)04
1.7D)04
1.3D)05
7.1D)06
1.7D)06
6.1D)08
7.4D)08

3.4D)02
2.8D)03
1.6D)04
1.1D)05
6.6D)07
3.4D)08
1.4D)09
5.3D)11
1.8D)12

M.T. Rashed / Appl. Math. Comput. 156 (2004) 499–505

503

Examples n

5

6

7

8

2
3
4
5
6
7
8
9
10
14

1.7D)02
2.7D)03
5.4D)04
1.2D)04
2.6D)05
5.0D)06
8.9D)07
1.4D)07
2.1D)08
2.4D)11

3.3D+01
3.6D+00
3.8D)01
4.2D)02
4.2D)03
3.8D)04
2.9D)05
2.1D)06
1.3D)07
6.1D)11

4.5D)01
6.3D)02
9.9D)03
1.5D)03
2.5D)04
3.5D)05
4.7D)06
5.5D)07
6.2D)08

3.4D)02
1.5D)03
6.5D)05
2.8D)06
1.1D)07
3.5D)09
9.7D)11
2.5D)12
1.3D)13

3.2. Second derivatives
ð1Þ yðxÞ ¼ loge ðx þ 3Þ; 

1
y 00 ðxÞ ¼ ðxþ3Þ
2 ;

ð2Þ yðxÞ ¼ ex ;

y 00 ðxÞ ¼ ex ;

ð3Þ yðxÞ ¼ tan1 x; 

2x
y 00 ðxÞ ¼ ð1þx
;
2 Þ2

ð4Þ yðxÞ ¼ cosðp2 xÞ;

y 00 ðxÞ ¼ ðp2Þ cosðp2 xÞ;

ð5Þ yðxÞ ¼ tan1 ð4x þ 3Þ; 

32ð4xþ3Þ
y 00 ðxÞ ¼ ð1þð4xþ3Þ
2 2 ;
Þ

ð6Þ yðxÞ ¼ ðx þ 3Þ

xþ3

2

;

2

y 00 ðxÞ ¼ ðx þ 3Þ

xþ3

2

1
½xþ3
þ ð1 þ loge ðx þ 3ÞÞ
;
2

ð7Þ yðxÞ ¼ ex ;

y 00 ðxÞ ¼ ð4x2 þ 2Þex ;

ð8Þ yðxÞ ¼ ex loge ðx þ 3Þ;

2
1
y 00 ðxÞ ¼ ex ½xþ3 
ðxþ3Þ
2 þ loge ðx þ 3Þ
:

(ii) rn , for the second derivative A ¼ 0, B ¼ 1:0
Examples n

1

2

3

4

2
3
4
5
6
7
8
9
10

9.9D)04
1.4D)04
8.6D)06
4.0D)07
6.2D)08
3.8D)09
4.1D)10
2.5D)11
8.4D)12

3.5D)02
8.2D)03
1.2D)04
9.7D)06
1.9D)07
9.3D)09
1.7D)10
6.9D)12
3.5D)12

1.0D)01
4.8D)02
1.7D)02
2.6D)04
9.9D)04
2.2D)04
1.1D)05
1.6D)05
2.7D)06

1.4D)01
3.5D)02
1.2D)03
1.2D)04
4.5D)06
3.1D)07
9.9D)09
5.1D)10
1.5D)11

504

M.T. Rashed / Appl. Math. Comput. 156 (2004) 499–505

Examples n

5

6

7

8

2
3
4
5
6
7
8
9
10
13
14
17

1.8D)01
2.4D)02
1.4D)02
2.7D)03
7.5D)04
1.4D)04
2.9D)05
4.5D)06
6.6D)07
7.6D)09
2.6D)09
2.1D)10

1.7D+02
5.2D+01
4.2D+00
6.3D)01
5.1D)02
5.5D)03
3.9D)04
3.3D)05
2.0D)06
3.8D)09

2.8D+00
1.0D+00
1.5D)01
3.3D)02
4.7D)03
7.9D)04
1.0D)04
1.5D)05
1.7D)06

7.6D)02
1.8D)02
2.9D)04
2.4D)05
4.8D)07
2.4D)08
4.6D)10
1.5D)11
7.3D)13

2.6D)10

(iii) rn , for the ﬁrst derivative, A ¼ 0, B ¼ 0:5
Examples n

5

6

7

8

2
3
4
5
6
7
8
9
10

4.9D)03
4.7D)04
5.3D)05
6.7D)06
7.9D)07
8.5D)08
7.8D)09
5.6D)10
2.0D)11

1.8D+00
9.9D)02
5.3D)03
2.9D)04
1.5D)05
6.9D)07
2.7D)08
9.2D)10
3.2D)11

2.1D)02
1.0D)03
1.0D)04
5.9D)06
5.8D)07
3.2D)08
2.5D)09
1.2D)10
7.4D)12

3.1D)03
6.9D)05
1.5D)06
3.3D)08
6.4D)10
1.1D)11
1.5D)13
8.9D)14
2.3D)14

(iv) rn , for the second derivative, A ¼ 0, B ¼ 0:5
Examples n

5

6

7

8

2
3
4
5
6
7
8
9
10

5.7D)02
6.6D)03
1.5D)03
1.4D)04
2.4D)05
2.0D)06
2.1D)07
5.2D)09
1.9D)09

9.8D+00
2.5D+00
6.1D)02
5.9D)03
1.9D)04
1.1D)05
3.4D)07
1.4D)08
5.4D)10

9.5D)02
2.9D)02
1.2D)03
1.8D)04
8.6D)06
9.2D)07
4.4D)08
3.7D)09
1.9D)10

7.2D)03
1.6D)03
6.9D)06
4.3D)07
2.9D)09
1.1D)10
2.9D)12
1.1D)11
5.1D)11

M.T. Rashed / Appl. Math. Comput. 156 (2004) 499–505

505

4. Conclusion
We can make the following comments concerning these results.
1. The results for the derivatives show an excellent precision.
2. The formulae written in the convenient form of FORTRAN subroutines
which can be run on a personal computer.
3. The derivatives are given at the points xi ¼ A þ ih, h ¼ BA
, i ¼ 0ð1Þn.
n
4. The computed errors rn in these tables are deﬁned to be
"
#1=2
Z
1=2
n
B
X
2
rn ¼
en ðxj Þ=n

e2n ðxÞ dx
;
j¼0

A

, j ¼ 0ð1Þn and en ¼ yn  yexact .
where xj ¼ A þ jh, h ¼ BA
n
5. The very rapid convergence obtain shows that the method, indeed succefully
treats the problem of ﬁnding derivatives of a function.
6. Eq. (1.4) may be written in the form
2 0
2
3
3
y ðx0 Þ
yðz0 Þ  yðAÞ
6 y 0 ðx1 Þ 7
6 yðz1 Þ  yðAÞ 7
6
7
6
7
ð4:1Þ
6 .. 7 ¼ B1 6
7:
..
4 . 5
4
5
.
y 0 ðxn Þ

yðzn Þ  yðAÞ

Also, Eq. (2.3) may be written in the form
2 00
3
2
3
yðz0 Þ  ðz0  AÞy 0 ðAÞ  yðAÞ
y ðx0 Þ
00
0
6 y ðx1 Þ 7
6 yðz1 Þ  ðz1  AÞy ðAÞ  yðAÞ 7
6
7
6
7
6 .. 7 ¼ E1 6
7:
..
4 . 5
4
5
.
y 00 ðxn Þ

ð4:2Þ

yðzn Þ  ðzn  AÞy 0 ðAÞ  yðAÞ

The main advantages of the suggested method in using (4.1) or (4.2) is only
computing B1 or E1 for n ¼ 16 and hence computing the ﬁrst or the second
derivative of diﬀerent functions with excellent precision.
7. The method gives an excellent precision if jB  Aj 6 1:0 as showing from (iii)
and (iv) tables.

References
[1] I.S. Berezin, N.P. Zhidkor, Computing Methods, vol. 1, Pergamon Press, Oxford, 1965.
[2] F. Feuilebcis, Precise calculation of numerical derivatives using Lagrange and Hermite
interpolation, Comput. Math. Appl. 19 (5) (1990) 1–11.
[3] Z. Kopal, Numerical Analysis, Wiley, New York, 1955.

Sign up to vote on this title