Skip to content

Instantly share code, notes, and snippets.

@GregVernon
Created March 25, 2019 02:57
Show Gist options
  • Save GregVernon/b1c6ba8e31032a4532c4c3bad060771e to your computer and use it in GitHub Desktop.
Save GregVernon/b1c6ba8e31032a4532c4c3bad060771e to your computer and use it in GitHub Desktop.
Finite Difference Coefficient Generation
order = 4
stencil = [-3 -2 -1 0 1]
S = zeros(Int64,order+1,length(stencil))
for i = 1:length(stencil)
for j = 0:order
S[j+1,i] = stencil[i] ^ j
end
end
D = zeros(Int64,order+1)
D[order+1] = factorial(order)
C = S\D
x = range(0,2*pi,length=1000)
F = sin.(x)
DF = zeros(Float64,1000)
for i = 4:999
DF[i] = sum((C .* F[i.+stencil]') ./ (x[2]-x[1])^order)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment