def linear_eq_to_matrix(equations, *symbols):
    "\n    Converts a given System of Equations into Matrix form.\n    Here `equations` must be a linear system of equations in\n    `symbols`. The order of symbols in input `symbols` will\n    determine the order of coefficients in the returned\n    Matrix.\n\n    The Matrix form corresponds to the augmented matrix form.\n    For example:\n\n    .. math:: 4x + 2y + 3z  = 1\n    .. math:: 3x +  y +  z  = -6\n    .. math:: 2x + 4y + 9z  = 2\n\n    This system would return `A` & `b` as given below:\n\n    ::\n\n         [ 4  2  3 ]          [ 1 ]\n     A = [ 3  1  1 ]   b  =   [-6 ]\n         [ 2  4  9 ]          [ 2 ]\n\n    Examples\n    ========\n\n    >>> from sympy import linear_eq_to_matrix, symbols\n    >>> x, y, z = symbols('x, y, z')\n    >>> eqns = [x + 2*y + 3*z - 1, 3*x + y + z + 6, 2*x + 4*y + 9*z - 2]\n    >>> A, b = linear_eq_to_matrix(eqns, [x, y, z])\n    >>> A\n    Matrix([\n    [1, 2, 3],\n    [3, 1, 1],\n    [2, 4, 9]])\n    >>> b\n    Matrix([\n    [ 1],\n    [-6],\n    [ 2]])\n    >>> eqns = [x + z - 1, y + z, x - y]\n    >>> A, b = linear_eq_to_matrix(eqns, [x, y, z])\n    >>> A\n    Matrix([\n    [1,  0, 1],\n    [0,  1, 1],\n    [1, -1, 0]])\n    >>> b\n    Matrix([\n    [1],\n    [0],\n    [0]])\n\n    * Symbolic coefficients are also supported\n\n    >>> a, b, c, d, e, f = symbols('a, b, c, d, e, f')\n    >>> eqns = [a*x + b*y - c, d*x + e*y - f]\n    >>> A, B = linear_eq_to_matrix(eqns, x, y)\n    >>> A\n    Matrix([\n    [a, b],\n    [d, e]])\n    >>> B\n    Matrix([\n    [c],\n    [f]])\n\n    "
    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.
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]])
def linear_eq_to_matrix(equations, *symbols):
    "\n    Converts a given System of Equations into Matrix form.\n    Here `equations` must be a linear system of equations in\n    `symbols`. The order of symbols in input `symbols` will\n    determine the order of coefficients in the returned\n    Matrix.\n\n    The Matrix form corresponds to the augmented matrix form.\n    For example:\n\n    .. math:: 4x + 2y + 3z  = 1\n    .. math:: 3x +  y +  z  = -6\n    .. math:: 2x + 4y + 9z  = 2\n\n    This system would return `A` & `b` as given below:\n\n    ::\n\n         [ 4  2  3 ]          [ 1 ]\n     A = [ 3  1  1 ]   b  =   [-6 ]\n         [ 2  4  9 ]          [ 2 ]\n\n    Examples\n    ========\n\n    >>> from sympy import linear_eq_to_matrix, symbols\n    >>> x, y, z = symbols('x, y, z')\n    >>> eqns = [x + 2*y + 3*z - 1, 3*x + y + z + 6, 2*x + 4*y + 9*z - 2]\n    >>> A, b = linear_eq_to_matrix(eqns, [x, y, z])\n    >>> A\n    Matrix([\n    [1, 2, 3],\n    [3, 1, 1],\n    [2, 4, 9]])\n    >>> b\n    Matrix([\n    [ 1],\n    [-6],\n    [ 2]])\n    >>> eqns = [x + z - 1, y + z, x - y]\n    >>> A, b = linear_eq_to_matrix(eqns, [x, y, z])\n    >>> A\n    Matrix([\n    [1,  0, 1],\n    [0,  1, 1],\n    [1, -1, 0]])\n    >>> b\n    Matrix([\n    [1],\n    [0],\n    [0]])\n\n    * Symbolic coefficients are also supported\n\n    >>> a, b, c, d, e, f = symbols('a, b, c, d, e, f')\n    >>> eqns = [a*x + b*y - c, d*x + e*y - f]\n    >>> A, B = linear_eq_to_matrix(eqns, x, y)\n    >>> A\n    Matrix([\n    [a, b],\n    [d, e]])\n    >>> B\n    Matrix([\n    [c],\n    [f]])\n\n    "
    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)