-
Notifications
You must be signed in to change notification settings - Fork 27
Closed
Description
I am a bit confused by a difference between two functions I've written to be equivalent. I am trying to make a function more general by summing over get index operations instead of hard coding the number of terms. I produced what I thought are equivalent functions, and when they are evaluated they are equivalent. However, when I finite difference them the results are slightly different. Is this a numerical error?
method = central_fdm(10,3)
expansion1 = ϵ -> f(x + ϵ.^1 * v[1]/factorial(1) + ϵ.^2 * v[2] / factorial(2) + ϵ.^3 * v[3] / factorial(3))
expansion2 = ϵ -> f(x + sum(ϵ.^i * v[i] / factorial(i) for i in 1:3))
f=sin
x= 2.
v = (1.,1.,1.)
method(expansion1,0.)
method(expansion2,0.)
Which produces:
julia> method(expansion1,0.)
-2.727892280564907
julia> method(expansion2,0.)
-2.7278922805817447
Where is this difference coming from?
oxinabox
Metadata
Metadata
Assignees
Labels
No labels