Skip to content

Comparing equivalent functions with unequal finite difference results? #33

@jessebett

Description

@jessebett

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions