All problems
Kalman Gain with Observation Matrix
Problem
Compute the Kalman gain for a scalar state observed through z = h * x + v, with prior variance p_prior and observation noise variance r. The gain is K = p_prior * h / (h^2 * p_prior + r).
Return 0.0 when the denominator is zero.
Hint
The observation matrix scales both the prior variance and the numerator.
Test cases
case 1
in: [1,2,1]
expected: 0.4
case 2
in: [4,0.5,1]
expected: 1
case 3
in: [0,1,1]
expected: 0
case 4
in: [2,0,0.5]
expected: 0
Starter codePython
def kalman_gain_observation_matrix(p_prior, h, r):
# Your code here
pass4 test cases · run your code against them in the editor