Hello I have this code:
import numpy as np
from sympy import *
import sympy
x = Symbol('x')
x0 = Symbol('x0')
B = Symbol('B')
E = Symbol('E')
linewidth = Symbol('linewidth')
f = 1/pi*(linewidth/2)/((x - (E+2*B))**2 + (linewidth/2)**2)
def makeOneMeasurement(pCov,f,sigma,pvec,pmean):
Iprior = np.linalg.inv(pCov)
derivative_f = [f.diff(E),f.diff(B)]
F = []
for i in range(len(derivative_f)):
for j in range(len(derivative_f)):
g = derivative_f[i]*derivative_f[j]
for k in range(len(pvec)):
g = g.subs(pvec[k], pmean[k])
F = F + [g]
F = np.reshape(F,(2,2))/sigma**2
F = sympy.Matrix(F)
Iprior = sympy.Matrix(Iprior)
return (Iprior + F).det()
If I call this function like this:
makeOneMeasurement([[1,0],[0,1]],f,0.1,["linewidth","E","B"],[0.1,990,0.11]).subs(x,990).evalf()
I get the output 1 (exactly 1). However, if instead of returning return (Iprior + F).det()
I return just return (Iprior + F)
, and I call:
makeOneMeasurement([[1,0],[0,1]],f,0.1,["linewidth","E","B"],[0.1,990,0.11]).subs(x,990).evalf().det()
(basically exactly the same thing, but the det is called outside instead of inside the function), I get:
3653.9564196053
What am I doing wrong? I want to be able to return the determinant as a function of x (so I would like the use the first version). Why do I get 1 all the time instead of a function of x? Thank you!