Step04-Numerical Difference
The purpose of implementing Variable and Function class was to compute differential automatically. So, what is differential?
Differential is simply a gradient, which is a change in an extremely short time interval. We can describe defferential as a following formula:
$f^{'}=\displaystyle \lim_{h \to 0}\frac{f(x+h)-f(x)}{h}$
Then how could we implement numerical difference as a code? We can replace the variable h(which is an extremely small number) with 1e-4. Also instead of forward and backward difference, it's better to use central difference because of relatively low error. (증명 정리하기) Next code is a function that computes central difference.
Let's caclulate the central difference of Square function.
The result is 4.000000000004, which includes a very small amount of error, 0.000000000004.
Also, this function can calculate a central difference of composite function:
Although the error is tiny here, numerical difference still has some limitations. Error might be increase depending on which calculation it is executing, and the amount of computation can also increase dramatically.
댓글
댓글 쓰기