def linear_eq_to_matrix(equations, *symbols):
 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])
 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)
  coeff_list = []
  for symbol in symbols:
   coeff_list.append(f.coeff(symbol))
  coeff_list.append((- f.as_coeff_add(*symbols)[0]))
  M = M.row_insert(row_no, Matrix([coeff_list]))
  row_no += 1
 M.row_del(0)
 (A, b) = (M[:, :(-1)], M[:, (-1):])
 return (A, b)

def linear_eq_to_matrix ( equations , * symbols ) : 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 ] ) 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 ) coeff_list = [ ] for symbol in symbols : coeff_list . append ( f . coeff ( symbol ) ) coeff_list . append ( ( - f . as_coeff_add ( * symbols ) [ 0 ] ) ) M = M . row_insert ( row_no , Matrix ( [ coeff_list ] ) ) row_no += 1 M . row_del ( 0 ) ( A , b ) = ( M [ : , : ( - 1 ) ] , M [ : , ( - 1 ) : ] ) return ( A , b )
converts a given system of equations into matrix form .