Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Jacobian calculation #293

Open
mattsignorelli opened this issue Jun 9, 2024 · 0 comments
Open

Incorrect Jacobian calculation #293

mattsignorelli opened this issue Jun 9, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@mattsignorelli
Copy link

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

@oxinabox oxinabox added the bug Something isn't working label Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants