Skip to content

Incorrect Jacobian calculation #293

Open
@mattsignorelli

Description

@mattsignorelli
using ForwardDiff
using Diffractor: DiffractorForwardBackend
import AbstractDifferentiation as AD
 
function test(z0)
  z = Vector{eltype(z0)}(undef, length(z0))
  L  =  0.5 
  k1 = 0.36
  z[1] =  cos(sqrt(k1)*L)*z0[1]+1/sqrt(k1)*sin(sqrt(k1)*L)*z0[2]
  z[2] =  -sqrt(k1)*sin(sqrt(k1)*L)*z0[1]+cos(sqrt(k1)*L)*z0[2]
  return z
end

m(z) = test([z[1], z[2]])

Then:

julia> j = AD.jacobian(DiffractorForwardBackend(), m, zeros(2)) |> only
2×2 Matrix{Float64}:
  0.29552   0.492534
 -0.177312  0.29552

julia> j = AD.jacobian(AD.ForwardDiffBackend(), m, zeros(2)) |> only
2×2 Matrix{Float64}:
  0.955336  0.492534
 -0.177312  0.955336

ForwardDiff.jl's Jacobian was also cross-checked with GTPSA.jl

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions