Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
hersle committed Jan 17, 2025
1 parent f5937ae commit 60e4723
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions test/extensions/ad.jl
Original file line number Diff line number Diff line change
@@ -115,11 +115,12 @@ fwd, back = ChainRulesCore.rrule(remake_buffer, sys, ps, idxs, vals)

# Find initial throw velocity that reaches exactly 10 m after 1 s
dprob0 = ODEProblem(sys, [D(y) => NaN], (0.0, 1.0), []; guesses = [y => 0.0])
nprob = NonlinearProblem((ics, _) -> begin
function f(ics, _)
dprob = remake(dprob0, u0 = Dict(D(y) => ics[1]))
dsol = solve(dprob, Tsit5())
return [dsol[y][end] - 10.0]
end, [1.0])
end
nprob = NonlinearProblem(f, [1.0])
nsol = solve(nprob, NewtonRaphson())
@test nsol[1] 10.0/1.0 + 9.81*1.0/2 # anal free fall solution is y = v0*t - g*t^2/2 -> v0 = y/t + g*t/2
@test nsol[1] 10.0 / 1.0 + 9.81 * 1.0 / 2 # anal free fall solution is y = v0*t - g*t^2/2 -> v0 = y/t + g*t/2
end

0 comments on commit 60e4723

Please sign in to comment.