Merge pull request #76 from fangliu-tju/main
Update numeric_derivatives.qmd
This commit is contained in:
commit
d1db1d300e
@ -102,7 +102,7 @@ There are some other ways to compute derivatives numerically that give much more
|
||||
The `ForwardDiff` package provides one of [several](https://juliadiff.org/) ways for `Julia` to compute automatic derivatives. `ForwardDiff` is well suited for functions encountered in these notes, which depend on at most a few variables and output no more than a few values at once.
|
||||
|
||||
|
||||
The `ForwardDiff` package was loaded in this section; in general its features are available when the `CalculusWithJulia` package is loaded, as that package provides a more convenient interface. The `derivative` function is not exported by `FiniteDiff`, so its usage requires qualification. To illustrate, to find the derivative of $f(x)$ at a *point* we have this syntax:
|
||||
The `ForwardDiff` package was loaded in this section; in general its features are available when the `CalculusWithJulia` package is loaded, as that package provides a more convenient interface. The `derivative` function is not exported by `ForwardDiff`, so its usage requires qualification. To illustrate, to find the derivative of $f(x)$ at a *point* we have this syntax:
|
||||
|
||||
|
||||
```{julia}
|
||||
@ -226,7 +226,7 @@ The use of `'` to find derivatives provided by `CalculusWithJulia` is convenient
|
||||
## Questions
|
||||
|
||||
|
||||
##### Question
|
||||
###### Question
|
||||
|
||||
|
||||
Find the derivative using a forward difference approximation of $f(x) = x^x$ at the point $x=2$ using `h=0.1`:
|
||||
@ -253,7 +253,7 @@ val = f'(c)
|
||||
numericq(val)
|
||||
```
|
||||
|
||||
##### Question
|
||||
###### Question
|
||||
|
||||
|
||||
Mathematically, as the value of `h` in the forward difference gets smaller the forward difference approximation gets better. On the computer, this is thwarted by floating point representation issues (in particular the error in subtracting two like-sized numbers in forming $f(x+h)-f(x)$.)
|
||||
@ -269,7 +269,7 @@ f(x) = sin(x)
|
||||
h = 1e-16
|
||||
c = 0
|
||||
approx = (f(c+h)-f(c))/h
|
||||
val = abs(cos(0) - approx)
|
||||
val = abs(cos(c) - approx)
|
||||
numericq(val)
|
||||
```
|
||||
|
||||
@ -283,7 +283,7 @@ f(x) = sin(x)
|
||||
h = 1e-16
|
||||
c = pi/4
|
||||
approx = (f(c+h)-f(c))/h
|
||||
val = abs(cos(0) - approx)
|
||||
val = abs(cos(c) - approx)
|
||||
numericq(val)
|
||||
```
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user