1

Basically what the title states. I'm getting what I think to be numerical errors propagating in my code, so am attempting to improve by changing all the types to mpcs, with a high precision. However, some of my calculations are symbolic and sympy doesn't seem to like the mpcs.

val += (1.0/2.0)*(1.0/kConversionFactor)**(ci) * ( A*k**(ln-lm+2*ci) - 1.0j*B*k**(ln+lm+1+2*ci) )
TypeError: unsupported operand type(s) for *: 'mpc' and 'Symbol'

k is the sympy symbol A and B are mpc's

Jibbity jobby
  • 1,255
  • 2
  • 12
  • 26
  • I'm thinking perhaps this could help http://mattpap.github.io/scipy-2011-tutorial/html/basics.html#foreign-types-in-sympy – Jibbity jobby May 05 '16 at 20:39

1 Answers1

0

Updated following comments:

val += (1.0/2.0)*(1.0/kConversionFactor)**(ci) * (mpcToSympy(A)*k**(ln-lm+2*ci) - sy.I*mpcToSympy(B)*k**(ln+lm+1+2*ci) )
....
def mpcToSympy(mpc_):
    return ( sy.Float(str(mpc_.real),DPS) + sy.Float(str(mpc_.imag),DPS)*sy.I )

See here: Convert from mpf to Sympy Float without losing precision

Community
  • 1
  • 1
Jibbity jobby
  • 1,255
  • 2
  • 12
  • 26
  • `sympify` will convert them to SymPy types. However, if you want high precision floats, you can just use [`sympy.Float`](http://docs.sympy.org/latest/modules/core.html#sympy.core.numbers.Float). – asmeurer May 06 '16 at 16:44
  • Thank you. So the Sympy types will lose the precision and the sympy Float wont? Implicitly? – Jibbity jobby May 06 '16 at 20:19
  • Now that I remember, I had indeed tried Float but the problem is that I require a complex type and sympy doesn't appear to have one. Also, you are correct the sympify seems to drop the precision. I think If I use Flaot with the sympy I. – Jibbity jobby May 06 '16 at 20:40