Beruflich Dokumente
Kultur Dokumente
Numerical Differentiation
Numerical differentiation is one of the most used techniques in numerical methods. In this
practice, Taylor Expansion based methods of backward, forward and central difference schemes
of various orders and 4th order Pade Scheme are utilized to different functions in the range of [-
1,1].
At the boundaries keeping same scheme is not possible, under this condition 2 different
approach can be enhanced: using artificial points and swiping direction of scheme while
conserving order. In this report latter is used.
1
Numerical Practice No2 | Bahadır Türkyılmaz
Figure 1. Derivative of function and estimation of it for 6th order Backward Finite Difference Scheme(a)
2
Numerical Practice No2 | Bahadır Türkyılmaz
The trend in Figure 1 is observed for all scheme types and all locations. Other comparison
graphs can be drawn using MATLAB code of ‘graphofcalculated1.m’. Calculated data
for each method can be found files of ‘datacalcualted%%.txt’. The calculation codes are
can be found name of ‘q1findifsch.f90’ and ‘q1padesch.f90’.
Each discrete size determined as Δx=2/n where N=2**k+1. The Figures 2,3, and 4
represent error plots for second order finite difference schemes for k=4:10 in logarithmic
scale. The red lines in the Figures are linear fit of error curves. The form of fit is y=a*x+b,
the coefficients for every Finite Difference scheme can be found in Table 1. The slopes
linear fit is very close to order of scheme, even though the relative difference between
slope and order can increase. The first reason of the difference is that schemes cannot be
applied purely in every point, for instance in boundaries different schemes are embraced
and structure is changed. The second reason is when error curves become more curved
and quality of linear fit reduces. In addition, in Figure 5 error plot for forth order Pade
scheme for k=4:20 can be seen. In graph, it is observed that error decreases with decrease
of discretization size until some point, however after that point it starts to increase. The
reason of this trend is in the first region truncation error reduces and round-off error is
not significant, then in the second region the round-off error becomes significant and
increases total error.
Method a b
Second O Forward -1.89808778227885 1.60181693421081
Second O Centered -2.44595709303987 3.15250305169143
Second O Backward -2.49091362114419 4.03036620671545
Forth O Forward -4.34216741444836 9.67129012123499
Forth O Centered -4.09078555003972 6.84053841170034
Forth O Backward -3.33628176743672 2.52356720525630
Sixth O Forward -6.37135104934356 11.7666803609797
Sixth O Centered -6.40153110968432 1.78965879214528
Sixth O Backward -6.67478041144824 11.9970650011996
Forth O Pade -4.41943139147760 7.24333652325779
Table 1. Coefficients of linear fit of error
Figure 5. Error graph of Forth Order Pade FD for increased number of iteration
5
Numerical Practice No2 | Bahadır Türkyılmaz
6
Numerical Practice No2 | Bahadır Türkyılmaz
Figure 6. The graph of Second Function (Red) and Its First Order Derivative (Orange)
Figure 7. The graph of First Order Derivative of Second Function (Red) and Its Second Order
Derivative (Orange)
7
Numerical Practice No2 | Bahadır Türkyılmaz
Figure 8. The graph of Second Order Derivative of Second Function (Red) and Its Third Order
Derivative (Orange)
Figure 9. Detailed Graph of Discontinuity of Third Order Derivative of Second Function (Orange)
8
Numerical Practice No2 | Bahadır Türkyılmaz
In Table 2, the derivative of the second function in various orders and exact and calculated values
of them at x=0 are shown. The values of the first derivative for different schemes have similar
magnitude because of continuity of function 2. The first derivative is not differentiable at x=0
because left and right side of it involves different trends even though both approaches to 0 at x=0.
That’s why forward and backward schemes have high amount of error for second derivative in
this point. However, the central finite difference schemes can compensate property of first
derivative by taking data both side of zero. For the third derivative, the error increases due to
discontinuity of derivative function as can be seen in Figure 9.
Method a b
Second O Forward -2.30603575574742 3.26782185970784
Second O Centered -2.30604255959462 3.26777447673901
Second O Backward -2.49448884864289 3.35337159026522
Forth O Forward -4.92414561269646 8.29582667481417
Forth O Centered -4.20750459295045 7.24985886517311
Forth O Backward -4.87949447457906 8.16526994614468
Sixth O Forward -6.14089930306327 7.75102497515126
Sixth O Centered -6.30204187006424 1.57580601047048
Sixth O Backward -6.14473727702804 7.77177004151712
Forth O Pade -4.64490508633646 7.98535351817607
Table 3 Coefficients of linear fit of error for function 2
The Table 3 represents coefficients of linear fit for log-log scale curve of Number of discretization
points and error. The slope of curve is linearly proportional with order of precision of the scheme
utilizing. The errors of slopes can be sourced by same reasons discussed for Function 1.
CONCLUSION
In the Tutorial 2, various Finite Difference Schemes are utilized two different functions. The
relation between Number of discretization points, error and precision of the scheme are observed.
Also, importance of continuity and differentiability of function for applying numerical
differentiation is recognized.