I need to solve an equation in x which can be simplified as an MWE into
x = \int_{x}^\infty A(z) dz
Importantly, A(z) is decreasing, integrable, and goes to 0 at infinity.
Possible solution concept
I thought I would define
K(x) = \int_x^\infty A(z) dz - x
and evaluate eg K(0) using quadrature, then use an ODE solver on
K'(x) = -A(x) - 1
starting from eg 0 and see where it crosses 0.
I just don’t know how to implement this with the DifferentialEquations ecosystem. I looked at the integrator interface, but all I could think of is finding where I cross 0, then backtracking.
Other suggestions for solution methods are appreciated.
For an MWE, consider
A(z) = exp(-z)
for which the (numerically obtained) solution should satisfy z = e^{-z}.
OK, I see that you and @stevengj suggest that I just use a univariate solver directly on K(x), and Newton should be a good choice since K'(x) is available at no cost. Got it, thanks!
function mysolve(A, x, rtol)
while true
f = x - quadgk(A, x, Inf, rtol=rtol)[1]
println("f($x) = $f")
Δx = -f / (1 + A(x)) # Newton step
x += Δx
abs(Δx) ≤ abs(x)*rtol && break
end
return x
end
converges to about 10 digits in only 4 steps for A(x) = e^{-x} / (x^2 + 1) starting at an initial guess of x=1:
Wouldn’t you have to use the full Leibniz integration rule here? I believe the correct derivative of K(x) should then be -2A(x) - 1.
Edit: Ah, never mind. The A inside the integral only depends on z, not x explicitly, so you were right.