Skip to content

Instantly share code, notes, and snippets.

@xtalax
Created July 17, 2019 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xtalax/872fc1dec342f91bb4a973528d74e5ed to your computer and use it in GitHub Desktop.
Save xtalax/872fc1dec342f91bb4a973528d74e5ed to your computer and use it in GitHub Desktop.
error benchmarking for centered difference operator
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