本文整理汇总了Python中sympy.matrices.Matrix.col_insert方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.col_insert方法的具体用法?Python Matrix.col_insert怎么用?Python Matrix.col_insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.matrices.Matrix
的用法示例。
在下文中一共展示了Matrix.col_insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: linear_eq_to_matrix
# 需要导入模块: from sympy.matrices import Matrix [as 别名]
# 或者: from sympy.matrices.Matrix import col_insert [as 别名]
def linear_eq_to_matrix(equations, *symbols):
r"""
Converts a given System of Equations into Matrix form.
Here `equations` must be a linear system of equations in
`symbols`. The order of symbols in input `symbols` will
determine the order of coefficients in the returned
Matrix.
The Matrix form corresponds to the augmented matrix form.
For example:
.. math:: 4x + 2y + 3z = 1
.. math:: 3x + y + z = -6
.. math:: 2x + 4y + 9z = 2
This system would return `A` & `b` as given below:
::
[ 4 2 3 ] [ 1 ]
A = [ 3 1 1 ] b = [-6 ]
[ 2 4 9 ] [ 2 ]
Examples
========
>>> from sympy import linear_eq_to_matrix, symbols
>>> x, y, z = symbols('x, y, z')
>>> eqns = [x + 2*y + 3*z - 1, 3*x + y + z + 6, 2*x + 4*y + 9*z - 2]
>>> A, b = linear_eq_to_matrix(eqns, [x, y, z])
>>> A
Matrix([
[1, 2, 3],
[3, 1, 1],
[2, 4, 9]])
>>> b
Matrix([
[ 1],
[-6],
[ 2]])
>>> eqns = [x + z - 1, y + z, x - y]
>>> A, b = linear_eq_to_matrix(eqns, [x, y, z])
>>> A
Matrix([
[1, 0, 1],
[0, 1, 1],
[1, -1, 0]])
>>> b
Matrix([
[1],
[0],
[0]])
* Symbolic coefficients are also supported
>>> a, b, c, d, e, f = symbols('a, b, c, d, e, f')
>>> eqns = [a*x + b*y - c, d*x + e*y - f]
>>> A, B = linear_eq_to_matrix(eqns, x, y)
>>> A
Matrix([
[a, b],
[d, e]])
>>> B
Matrix([
[c],
[f]])
"""
if not symbols:
raise ValueError('Symbols must be given, for which coefficients \
are to be found.')
if hasattr(symbols[0], '__iter__'):
symbols = symbols[0]
M = Matrix([symbols])
# initialise Matrix with symbols + 1 columns
M = M.col_insert(len(symbols), Matrix([1]))
row_no = 1
for equation in equations:
f = sympify(equation)
if isinstance(f, Equality):
f = f.lhs - f.rhs
# Extract coeff of symbols
coeff_list = []
for symbol in symbols:
coeff_list.append(f.coeff(symbol))
# append constant term (term free from symbols)
coeff_list.append(-f.as_coeff_add(*symbols)[0])
# insert equations coeff's into rows
M = M.row_insert(row_no, Matrix([coeff_list]))
row_no += 1
# delete the initialised (Ist) trivial row
M.row_del(0)
#.........这里部分代码省略.........
示例2: Matrix
# 需要导入模块: from sympy.matrices import Matrix [as 别名]
# 或者: from sympy.matrices.Matrix import col_insert [as 别名]
F2D = Matrix([Fx, Fy])
F3D = Matrix([Fx, Fy, Fz])
Force_str = "F"
F_phi_x = Symbol(Force_str + '.x')
F_phi_y = Symbol(Force_str + '.y')
F_phi_z = Symbol(Force_str + '.z')
omega_ade = Symbol('omega_ade')
omega_v = Symbol('omega_nu') # omega_nu = s_nu = 1 /(tau + 0.5)
omega_b = Symbol('omega_bulk') # results in bulk viscosity = 1/6 since : zeta = (1/sb - 0.5)*cs^2*dt
ex_D2Q9 = Matrix([0, 1, 0, -1, 0, 1, -1, -1, 1])
ey_D2Q9 = Matrix([0, 0, 1, 0, -1, 1, 1, -1, -1])
e_D2Q9 = ex_D2Q9.col_insert(1, ey_D2Q9)
# D3Q7 notation from TCLB
ex_D3Q7 = Matrix([0, 1, -1, 0, 0, 0, 0])
ey_D3Q7 = Matrix([0, 0, 0, 1, -1, 0, 0])
ez_D3Q7 = Matrix([0, 0, 0, 0, 0, 1, -1])
# D3Q15 - notation from 'LBM Principles and Practise' Book p. 89
ex_D3Q15 = Matrix([0, 1, -1, 0, 0, 0, 0, 1, -1, 1, -1, 1, -1, -1, 1])
ey_D3Q15 = Matrix([0, 0, 0, 1, -1, 0, 0, 1, -1, 1, -1, -1, 1, 1, -1])
ez_D3Q15 = Matrix([0, 0, 0, 0, 0, 1, -1, 1, -1, -1, 1, 1, -1, 1, -1])
S_relax_ADE_D3Q15 = diag(1, omega_ade, omega_ade, omega_ade, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)