What proof do you have that your iterative method for the EKF converges to anything, let alone a global or even local minimum? You also seem to have bad numerical scaling, with some input data being very small or large magnitude; and that’s on the first iteration. Subsequent iterations could get more and more extreme.
EKF’s can be tricky. Your crude implementation might not be up to the job.