Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"GenerateMatrix" equivalent command in SymPy

In Maple there is a command "GenerateMatrix" that will take a collection of linear equations and generate a symbolic matrix A and symbolic vector b in "Ax=b" where "x" is a vector of variables specified by the command. The help page can be found here if this isn't clear:

http://www.maplesoft.com/support/help/maple/view.aspx?path=LinearAlgebra%2FGenerateMatrix

In Maxima a similar operation can be accomplished using the "augcoefmatrix" command. Is there a similar command in SymPy? How could this command be implemented if the command does not exist?

like image 763
John Avatar asked Sep 11 '25 13:09

John


1 Answers

The SymPy analog is linear_eq_to_matrix. Usage example:

from sympy import *
variables = symbols('x y z')
equations = [3*x-z+2, y-3*z-5, x+y-z]
A, b = linear_eq_to_matrix(equations, variables)
linsolve((A, b), variables)

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!