### Choosing between different expression factorizations in SymPy

Say I have an expression as follows: a*b*c + b*c + a*d One could factorize it as: b*(a*c + c) + (a*d) or as c*(a*b + b) + (a*d) or as a*d + b*c*(a + 1) among other possibilities. For other...

### Best way to access name mangled names outside the class?

I would like to use a name mangled name in Python, to avoid subclasses from accessing the attribute. I know I can just do _classname__attributename, but according to the documentation, "If the...

### Any way to solve a system of coupled differential equations in python?

I've been working with sympy and scipy, but can't find or figure out how to solve a system of coupled differential equations (non-linear, first-order). So is there any way to solve coupled...

### ImportError: No module named matplotlib.pyplot

I am currently practicing matplotlib. This is the first example I practice. #!/usr/bin/python import matplotlib.pyplot as plt radius = [1.0, 2.0, 3.0, 4.0] area = [3.14159, 12.56636, 28.27431,...

### Collecting a fraction expression within a larger fraction (sympy)

I am using IPython (Anaconda distribution) with the sympy symbolic maths library. I have the following expression: tâ(h + l) ...

### How to simplify very small number to 0 in SymPy?

I am doing some matrix computation with sympy 0.7.6 in python 2.7.10. For example, M = [cos(q1), -6.12323399573677e-17*sin(q1), -1.0*sin(q1), 150*sin(q1)] [sin(q1), ...

### Python eval: is it still dangerous if I disable builtins and attribute access?

We all know that eval is dangerous, even if you hide dangerous functions, because you can use Python's introspection features to dig down into things and re-extract them. For example, even if you...

### Get a value from solution set returned as finiteset by Sympy

I`m creating a script in Python Sympy library and trying to access the result returned by solveset() and linsolve() functions. My problem is that the object returned by these functions is of type...

### Is there any way to get the step-by-step solution in SymPy?

Is there any way to get the step-by-step solution in SymPy? For example: x**2-5 = 4 step 1 x**2-5+5=4+5 step 2 : x**2=9 step 3 :x = 3 or x= -3

### SymPy and square roots of complex numbers

When using solve to compute the roots of a quadratic equation, SymPy returns expressions which could be simplified but I can't get it to simplify them. A minimal example looks like so: from sympy...

### How to calculate derivative and integral of the bessel functions in PYTHON

I want to calculate the integral or derivative of the modified Bessel functions in python. I want to calculate the infinite integral (without limits). Recently I found a method to do this. You can...

### Flask python app crashes on heroku

I tried pushing my code directly to Heroku for hosting but I got so many errors. Now, what I did was host the code on Github, and then link the git repo with Heroku. Now, the Heroku app was...

### one hot encoding for frequent values only

I am looking to do one hot encoding to a column, but only for those that are very frequent. All that are below a threshold T will be put in their own category. My strategy was to create a...

### Comparing symbolic mathematical expressions with Python using Sympy

I would like to check which mathematical expressions are equal. I want to do this using Python I tried it with Sympy. My idea was to use simplify in order to reduce the expressions such that a...

### Combine sympy and matplotlib plots in one picture

I need to build an expression graph and a graph set by an array of points, and return the images. To build an expression graph, I use sympy.plot, and to build a graph on points I use...

### an access violation writing location error the third time when calling a python function in c code

I am coding in c to solve a question. In the c code, I need to call a self-defined python to solve a equation. I am able to call the python function for twice time, however when i call the third...

### I can't install Jupyter and Matplotlib in my anaconda env

I have an environment of Anaconda (apart of root) and I'm trying to install this two libraries with no success. I tried: Install libraries by the environment tools of Anaconda Navigator...

### Fourier Series Fit in Python

I have some data I want to fit using a Fourier series of 2nd, 3rd, or 4th degree. While this question and answer on stack overflow gets close to what I want to do using scipy, they already...

### Convert a function defined in NumPy to SymPy

I have a function defined in numpy which I would like to convert to sympy, so I can apply it to symbolic sympy variables. Trying to directly apply the numpy function to a sympy variable...

### Solution for system of equations returns empty set

I have a system of five equations with five unknowns. The returned solution is an EmptySet(). Solving only for two variables, e.g. Ta2, Tb2 returns the correct solution, but only as parametric...

### How to speed up the expansion of very large polynomials in sympy?

I am working with very large polynomials in sympy and I need to have them in expanded form to find certain terms and coefficients. However, the expansion of these polynomials takes a long time. Is...

### Given a matrix A, find all matrices such that AB = BA

Given a square matrix A, find all matrices X such that AX = XA. This is a particular case of a Sylvester equation (one of the form AX + XB = Q) when A = B and Q is the zero matrix. I know SciPy...

### How to specify the region of convergence in `inverse_laplace_transform` function of SymPy?

In the documentation of SymPy, it says: The plane can be specified by argument plane, but will be inferred if passed as None. However, there are no examples of methods used to specify this...

### How to plot a phase portrait of Verhulst equation with SciPy (or SymPy) and Matplotlib?

The equation which describes competing species is given by dx/dt = beta\*x - delta\*x\**2 - gamma\*x\*y dy/dt = b\*y - d\*y\**2 - c\*x\*y I attempted to express this equation as follows: beta,...

### What does r() function mean in the return value of SymPy's dsolve?

I want to evaluate the value of phi(+oo) where phi(xi) is the solution of ODE Eq(Derivative(phi(xi), (xi, 2)), (-K + xi**2)*phi(xi)) and K is a known real variable. By dsolve, I got the...

### Colab running Pennylane with DeviceError

I tried to run Pennylane on Colab, so I install it first. But the "Installed devices" are null, what's going on? I have restart and rebuilt for several times. Here is my code. !pip install...

### how to get SymPy to replace ints like 1.0 with 1

Sorry for the newbie question but I have not found the answer elsewhere so far. Say we have a symbol and we multiply it by the float number one: import sympy x = sympy.Symbol('x') x = 1.0 *...

### 7 DOF Inverse kinematics with jacobian matrix in python

I am having problem calculating dtheta. to calculating the dtheta this is a following code according to my lecture Guess initial jointangles Î¸ Solve the equation JâdÎ¸=dp=pfâpi Increment...

### Why does this dictionary, returned by Sympy, appear to have and also not have the key 'w'?

I have a dictionary returned by Sympy. It appears to have an entry with a key, w. >>> stationary_points {w: 542.962336871418, b: 0.887349275879595} >>> type(stationary_points) <class 'dict'> And...

### How to get sympy to give solutions with smaller coefficients

Consider the following example Diophantine equation -118w + 989x + 918y -512z == 0 You can solve this in sympy with: import sympy from sympy.solvers.diophantine import diophantine w, x, y, z =...