相关疑难解决方法(0)

在什么情况下__rmul__被称为?

说我有一个清单l.在什么情况下被l.__rmul__(self, other)称为?

我基本上理解了文档,但我也希望看到一个例子,毫无疑问地澄清它的用法.

python operators

46
推荐指数
2
解决办法
2万
查看次数

函数矩阵,SymPy和SciPy的数值积分

从我的SymPy输出我有下面显示的矩阵,我必须在2D中集成.目前我正在以元素方式进行,如下所示.此方法适用,但它变得太慢(用于sympy.mpmath.quadscipy.integrate.dblquad)为我的真实案例(其中A,其职能是更大(见下面编辑):

from sympy import Matrix, sin, cos
import sympy
import scipy
sympy.var( 'x, t' )
A = Matrix([[(sin(2-0.1*x)*sin(t)*x+cos(2-0.1*x)*cos(t)*x)*cos(3-0.1*x)*cos(t)],
            [(cos(2-0.1*x)*sin(t)*x+sin(2-0.1*x)*cos(t)*x)*sin(3-0.1*x)*cos(t)],
            [(cos(2-0.1*x)*sin(t)*x+cos(2-0.1*x)*sin(t)*x)*sin(3-0.1*x)*sin(t)]])

# integration intervals
x1,x2,t1,t2 = (30, 75, 0, 2*scipy.pi)

# element-wise integration
from sympy.utilities import lambdify
from sympy.mpmath import quad
from scipy.integrate import dblquad
A_int1 = scipy.zeros( A.shape, dtype=float )
A_int2 = scipy.zeros( A.shape, dtype=float )
for (i,j), expr in scipy.ndenumerate(A):
    tmp = lambdify( (x,t), expr, 'math' )
    A_int1[i,j] = quad( tmp, (x1, x2), …
Run Code Online (Sandbox Code Playgroud)

python symbolic-math sympy scipy numerical-integration

7
推荐指数
1
解决办法
1924
查看次数

在表达式中使所有符号可交换

假设你在一个表情符号中有许多非交换符号,比如说

a, c = sympy.symbols('a c', commutative=False)
b = sympy.Symbol('b')
expr = a * c + b * c
Run Code Online (Sandbox Code Playgroud)

使表达式中的所有符号都可交换的首选方法是什么,例如,sympy.simplify(allcommutative(expr)) = c * (a + b)

这个答案中,声明在没有替换符号的情况下,没有办法在创建之后改变符号的交换性,但也许有一种简单的方法可以在块中更改像这样的表达式的所有符号?

python sympy commutativity

2
推荐指数
1
解决办法
195
查看次数