python - How can I solve system of linear equations in SymPy? -
sorry, pretty new sympy , python in general.
i want solve following underdetermined linear system of equations:
x + y + z = 1 x + y + 2z = 3
sympy got new linear system solver: linsolve
in sympy.solvers.solveset
, can use follows:
in [38]: sympy import * in [39]: sympy.solvers.solveset import linsolve in [40]: x, y, z = symbols('x, y, z')
list of equations form:
in [41]: linsolve([x + y + z - 1, x + y + 2*z - 3 ], (x, y, z)) out[41]: {(-y - 1, y, 2)}
augmented matrix form:
in [59]: linsolve(matrix(([1, 1, 1, 1], [1, 1, 2, 3])), (x, y, z)) out[59]: {(-y - 1, y, 2)}
a*x = b form
in [59]: m = matrix(((1, 1, 1, 1), (1, 1, 2, 3))) in [60]: system = a, b = m[:, :-1], m[:, -1] in [61]: linsolve(system, x, y, z) out[61]: {(-y - 1, y, 2)}
note: order of solution corresponds order of given symbols.
Comments
Post a Comment