Created
July 17, 2019 10:41
-
-
Save xtalax/872fc1dec342f91bb4a973528d74e5ed to your computer and use it in GitHub Desktop.
error benchmarking for centered difference operator
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
using DiffEqOperators, Plots | |
n = 10000 | |
@show n | |
x = range(0.0; length = n, stop = 2π) | |
dx = x[2]-x[1] | |
y = exp.(π*x) | |
y_ = y[2:(end-1)] | |
for dor in 1:4, aor in 2:6 | |
D1 = CenteredDifference(dor,aor,dx,length(x)) | |
#test result | |
@show dor | |
@show aor | |
#take derivatives | |
err_abs = abs.(D1*y .- (π^dor)*y_) | |
err_percent = 100*err_abs./abs.(((π^dor)*y_)) | |
max_error = maximum(err_percent) # test operator with known derivative of exp(kx) | |
avg_error = sum(err_percent)/length(err_percent) | |
@show max_error | |
@show avg_error | |
plot(x[2:(end-1)], err_percent, title="Percentage Error, n=$n aor = $aor, dor = $dor") | |
#test result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment