sympy

How do I use the `_backend` attribute of a Sympy `plot`

℡╲_俬逩灬. 提交于 2021-01-28 05:12:21
问题 In the following example I use Sympy to make a plot: from sympy import symbols, plot x = symbols('x') p = plot(x*x, x**3, (x, -2, 2), show=False) for n, line in enumerate(p, 2): line.label='$x^{%d}$'%n line.line_color = ['k', 'r'][n-2] p.legend = True As you can see, the legend is placed over the lines and Sympy doesn't offer a direct way to change the position of the legend. After some research I found, directly in the source code of */sympy/plotting/plot.py , this comment: Especially if you

Scientific/Exponential notation with sympy in an ipython notebook

谁都会走 提交于 2021-01-27 23:11:00
问题 How is the threshold for scientific notation set in an ipython notebook? I want to set all number outisde of something like [0.01, 100] to be printed in scientific notation, but the threshold seems to be much higher. i.e. In [165]: x = sympy.Symbol('x'); 1.e8*x Out[165]: 100000000.0*x but In [166]: 1.e28*x Out[166]: 1.0e+28*x Because I'm using sympy, I can't send the number to a formatted print statement, i.e. In [167]: print "%.2e" % (1.e8*x) ERROR: TypeError: float argument required, not

How do I get SymPy to collect partial derivatives?

前提是你 提交于 2021-01-27 19:59:03
问题 I have been using SymPy to expand the terms of a complex partial differential equation and would like to use the collect function to gather terms. However, it seems to have a problem dealing with second (or higher order) derivatives where the variables of differentiation differ. In the code example below collect(expr6... works, but collect(expr7 ... does not, returning the error message "NotImplementedError: Improve MV Derivative support in collect" . The error is clearly related to the psi

Sympy: using a symbolic expression as a numerical integrand

余生长醉 提交于 2021-01-27 19:40:38
问题 I need to manipulate a function symbolically, and then numerically integrate the function. How do I correctly use my expression f in the integrand function. How do I use lambdify correctly if that is even the sensible way to do it? Many thanks. from sympy import * import scipy.integrate as integrate r = symbols('r') #define symbol f = diff(r*r) #carry out symbolic manipulation def integrand(x): #define function to integrate return lambdify(x, f) #swap variable x into f result = integrate.quad

Generate C code with Sympy. Replace Pow(x,2) by x*x

孤人 提交于 2021-01-27 16:00:41
问题 I am generating C code with sympy the using the Common Subexpression Elimination (CSE) routine and the ccode printer. However, I would like to have powered expressions as (x*x) instead of pow(x,2). Anyway to do this? Example: import sympy as sp a= sp.MatrixSymbol('a',3,3) b=sp.Matrix(a)*sp.Matrix(a) res = sp.cse(b) lines = [] for tmp in res[0]: lines.append(sp.ccode(tmp[1], tmp[0])) for i,result in enumerate(res[1]): lines.append(sp.ccode(result,"result_%i"%i)) Will output: x0[0] = a[0]; x0[1

Extract coefficients and corresponding monomials from a given polynomial in SymPy

匆匆过客 提交于 2021-01-27 12:24:54
问题 Given a symbolic multivariate polynomial P , I need to extract both its coefficients and corresponding monomials as lists: def poly_decomp(P): .... return coeffs, monoms such that P is the dot product of coefficients and monomials, e.g., if P(x,y) = ax**2 + bxy + cy**2 then we should get coeffs = [a, b, c] and monoms = [x**2, x*y, y**2] . Getting the coefficients is easy since the function is built in coeffs = P.coeffs() . However, I'm having trouble getting the monomials. Here the build in

List of coefficients to polynomial

和自甴很熟 提交于 2021-01-27 06:08:18
问题 How do I create a polynomial out of a list of coefficients in SymPy? For example, given a list [1, -2, 1] I would like to get Poly(x**2 - 2*x + 1) . I tried looking at the docs but could not find anything close to it. 回答1: You could use Poly.from_list to construct the polynomial: >>> x = sympy.Symbol('x') >>> sympy.Poly.from_list([1, -2, 1], gens=x) Poly(x**2 - 2*x + 1, x, domain='ZZ') 回答2: It looks to me like you would do something like: from sympy.abc import x from sympy import poly lst =

sympy installed, however sympy.mpmath not found

倾然丶 夕夏残阳落幕 提交于 2021-01-27 06:02:16
问题 I want to use the jacobDN function in sympy, so I download it and python setup.py install it, successfully. When I want to use it as in the documentation does: >>> from sympy.mpmath import * Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named mpmath >>> Import everything from sympy is successful: >>> from sympy import * >>> Then I installed mpmath individually, then I can use the ellipfun from mpmath. However an annoying mpf is shown: >>> from

sympy installed, however sympy.mpmath not found

喜夏-厌秋 提交于 2021-01-27 06:00:40
问题 I want to use the jacobDN function in sympy, so I download it and python setup.py install it, successfully. When I want to use it as in the documentation does: >>> from sympy.mpmath import * Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named mpmath >>> Import everything from sympy is successful: >>> from sympy import * >>> Then I installed mpmath individually, then I can use the ellipfun from mpmath. However an annoying mpf is shown: >>> from

syntax for solving system of differential equations in sympy

删除回忆录丶 提交于 2021-01-27 04:39:35
问题 I am new to sympy and in the process of learning it. I was browsing through the documentation and questions in stack exchange regarding symbolically solving a system of differential equations with initial conditions using sympy. I have a simple system of ODE-s ( dV/dt ) = -( 1 / RC ) * ( V(t) ) + I(t)/C ( dI/dt ) = -( R1 / L ) * ( I(t) ) - ( 1 / L) * V(t) + Vs/L with initial conditions V(0) = V0 and I(0) = I0 I browsed through a lot of questions in stack exchange and not successful in finding