Skip to content
This repository was archived by the owner on Jul 19, 2023. It is now read-only.

Commit d28a0f5

Browse files
Merge pull request #143 from xtalax/fix-#136
Fix #136 - add error benchmarking
2 parents 72703b5 + 71a7cd4 commit d28a0f5

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/derivative_operators/derivative_operator.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct CenteredDifference{N} end
2020
function CenteredDifference{N}(derivative_order::Int,
2121
approximation_order::Int, dx::T,
2222
len::Int, coeff_func=nothing) where {T<:Real,N}
23-
23+
@assert approximation_order>1 "approximation_order must be greater than 1."
2424
stencil_length = derivative_order + approximation_order - 1 + (derivative_order+approximation_order)%2
2525
boundary_stencil_length = derivative_order + approximation_order
2626
dummy_x = -div(stencil_length,2) : div(stencil_length,2)

test/error_benchmarking.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using DiffEqOperators, Plots
2+
3+
n = 10000
4+
@show n
5+
x = range(0.0; length = n, stop = 2π)
6+
dx = x[2]-x[1]
7+
y = exp.(π*x)
8+
y_ = y[2:(end-1)]
9+
10+
for dor in 1:4, aor in 2:6
11+
12+
D1 = CenteredDifference(dor,aor,dx,length(x))
13+
14+
#test result
15+
@show dor
16+
@show aor
17+
#take derivatives
18+
err_abs = abs.(D1*y .-^dor)*y_)
19+
err_percent = 100*err_abs./abs.(((π^dor)*y_))
20+
max_error = maximum(err_percent) # test operator with known derivative of exp(kx)
21+
avg_error = sum(err_percent)/length(err_percent)
22+
23+
@show max_error
24+
@show avg_error
25+
plot(x[2:(end-1)], err_percent, title="Percentage Error, n=$n aor = $aor, dor = $dor")
26+
27+
#test result
28+
end

0 commit comments

Comments
 (0)