0

I am trying desperately to be able to integrate a matrix and this is my 3rd or 4th approach. Every time I try to resolve an error, I get a new one and get stuck. This time, I am getting the error:

---------------------------------------------------------------------------
PolynomialError                           Traceback (most recent call last)
<ipython-input-20-445ad8aa95c1> in <module>
     25 var = 0.16
     26 A = (1/var)*transpose@M
---> 27 A.integrate((s,0,1))
PolynomialError: 1.0*(6.25000000000002*_t0 + 0.0359195402298851)/(1.0*_t0 + 0.00574712643678161) is not an element of K[_t0, 1/_t0].

I have looked at every other post with regards to this error (including the one about cosine) and nothing resolves my error. I have tried np.exp, sym.exp, etc.

import sympy
from scipy.integrate import odeint
%matplotlib inline
import matplotlib.pyplot as plt
import scipy.integrate as integrate
from scipy.linalg import inv
from sympy.matrices import Matrix
from sympy.abc import s
from sympy import symbols, diff, exp, log, power


#M = Matrix([[x, y], [1, 0]])
#M.integrate((x, ))

K = 17.5
r = 0.7
x0 = 0.1

dxdK = (x0*x0-x0*x0*sympy.exp(-r*s))/((x0+K*sympy.exp(-r*s)-x0*sympy.exp(-r*s))**2)
dxdr = (K*K*x0*s*sympy.exp(-r*s)-K*x0*x0*s*sympy.exp(-r*s))/((x0+K*sympy.exp(-r*s)-x0*sympy.exp(-r*s))**2)
dxdx0 = (K*x0+K*K*sympy.exp(-r*s)-K*x0*sympy.exp(-r*s)-K*x0+K*x0*sympy.exp(-r*s))/((x0+K*sympy.exp(-r*s)-x0*sympy.exp(-r*s))**2)

M = Matrix([[dxdK, dxdr, dxdx0]])
transpose = M.T
var = 0.16
A = (1/var)*transpose@M
A.integrate((s,0,1))

As stated before, my only real goal is to be able to integrate the matrix (1/var)*tranpose@M with respect to s. I'm currently trying to resolve the error above, but am also open to suggestions to changing the code entirely to just be able to integrate the thing (which is why I provided so much of the code). I have another post with previous code I had to try and integrate it, but never got a good answer.

  • Since `s` is a `sympy.core.symbol.Symbol` object you should use `sympy.exp`. So at the top, `import sympy` and replace all `sym.exp` with `sympy.exp` – Buckeye14Guy Jul 11 '19 at 19:49
  • Ah. I accidentally imported scipy instead of sympy. However, now I'm getting a new error code that I can't resolve. I've updated the above. – Amanda Lococo Jul 12 '19 at 02:13
  • I am not sure how to resolve this or what code to suggest but is it possible some expressions you have are wrong? `(6.25000000000002*x+ 0.0359195402298851)/(*x+ 0.00574712643678161)` as a polynomial is fairly interesting. It has a discontinuity at it's root but the limits converge (special case of 0/0) and the whole thing just seems to be a constant. Sorry – Buckeye14Guy Jul 12 '19 at 13:37
  • I will check this out. I have checked my derivatives a few times and can't see any error, but maybe I've missed something. Thank you for the suggestion! – Amanda Lococo Jul 12 '19 at 21:24

0 Answers0