Created
June 29, 2020 22:21
-
-
Save MasonProtter/5eace1fd6fd3697343a3d70483e4d776 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#+BEGIN_SRC jupyter-julia | |
using Interpolations | |
xs = range(-10, 10, length=50) # 50 evenly spaced points from -5 to 5 | |
# model function, some Gaussian | |
f(x; A=1, σ=2, b=0) = A * exp(-x^2/2σ) + b | |
ys = f.(xs) | |
method = BSpline(Cubic(Line(OnGrid()))) #interpolation method | |
f_itp = scale(interpolate(ys, method), xs) # interpolation function | |
using FiniteDifferences: fdm, central_fdm | |
fdm(central_fdm(5, 1), f_itp, 1.0, Val(true)) | |
#+END_SRC | |
#+RESULTS: | |
: (FiniteDifferenceMethod: | |
: order of method: 5 | |
: order of derivative: 1 | |
: grid: -2:2 | |
: coefficients: [0.08333333333333333, -0.6666666666666666, 0.0, 0.6666666666666666, -0.08333333333333333] | |
: roundoff error: 1.42e-14 | |
: bounds on derivatives: 6.89e-02 | |
: step size: 4.25e-03 | |
: accuracy: 6.26e-12 | |
: , -0.3892357438391503) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment