Created
January 11, 2017 16:24
-
-
Save aviks/2e85bdb5da192d02593fdc6d10c86336 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function sum_diff_fast(x) | |
n=length(x); d = 1/(n-1) | |
s = zero(eltype(x)) | |
@fastmath s = s + (x[2] - x[1]) / d | |
@fastmath for i = 2:n-1 | |
s = s + (x[i+1] - x[i+1]) / (2*d) | |
end | |
@fastmath s = s + (x[n] - x[n-1])/d | |
end | |
function sum_diff(x) | |
n = length(x); d = 1/(n-1) | |
s = zero(eltype(x)) | |
s = s + (x[2] - x[1]) / d | |
for i = 2:length(x)-1 | |
s = s + (x[i+1] - x[i+1]) / (2*d) | |
end | |
s = s + (x[n] - x[n-1])/d | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment