I’m computing a probability function P
and its derivative dP
with respect to a variable θ
. Analytically, as an example, the function and its derivative could be:
P = sin(θ)**2
dP = sin(θ) * cos(θ)
From this, I derived that when θ = 0, the expression (dP)**2 / P should evaluate to cos(θ)**2, which equals 1.
Issue:
However, numerically, I am encountering unexpected results when θ = 0 (as an example):
Computed P = 8.45359967e-32
Computed dP = 1.22464680e-16
Using these values, the expression (dP)**2 / P calculates to approximately 0.17 instead of the expected 1.
Details:
This discrepancy seems to arise from a numerical “0/0” situation, as both P and dP approach zero when θ=0. Here are the questions:
-
What numerical techniques can I use to address this instability and avoid the “0/0” issue at θ = 0?
-
Are there adjustments or corrections that can be applied to ensure that the theoretical and numerical calculations align more closely?
If something is wrong or unclear, please point it out. Thank you very much in advance!