Question

I have been searching for a bit and I am at the point that I believe I may be asking google the wrong question. If there is another thread out there that has this issue as well, please let me know.

I am relatively new to sympy, but the documentation is very good, so I haven't had any problems thus far. I am trying to convert to Python from MATLAB and I am testing some scripts that have worked in MATLAB. I am using Python 3.3.

I am trying to solve a relatively simple equality and I am failing. When I run the script below, I only receive an empty list as the output.

# define the symbols we wish to use
se = symbols('se')

# assign some constants
D = S(0.24)
sn = S(38e6)
Q = S(0.64)

Dprime = 1.0 - D

mc = 1 + (se/sn)

# this is the expression that we wish to make equal to Q
expr = (S(1)/(pi * (mc * Dprime - S(0.5))))

# this should print the value for se
print(solve(Eq(expr, Q),se))

This block of code works perfectly right up until the "solve" function is executed.

>>> Eq(expr, Q)
             1                 
──────────────────── = 0.64
π⋅(2.0e-8⋅se + 0.26)  

I have looked at the documentation and I have found that there are several flags that I could utilize. I first tried the ones that I thought may be relevant. I then tried the ones that I didn't think were very relevant. I then tried them all.

I have also tried various operations on the inputs to the variables. One of them that I left in is the S(), which I understand to be the "symplify" function. Perhaps I over-did this one, but I suspect that one can't overuse the function.

The problem seems to be related to having a variable in the denominator. I have tried many of the examples that are contained in the sympy documentation and all of them work for me, so I am fairly confident in the install itself.

Thank you for your time,

J

Was it helpful?

Solution

Of course, while searching for the answer, I came across a bit about using 'scipy' instead of 'sympy' for this. As it happens, simply placing a from scipy import * solved the problem.

OTHER TIPS

The flag you want is rational=False. I think this is a bug in SymPy, but probably your coefficient 2.0e-8 is too small.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top