This notebook can be useful to quickly make a latex representation of linear systems of 2 variables.


```python
pre_str = r"""
$
\left\{
\begin{align}
"""

post_str = r"""\end{align}
\right.
$
"""

def complete_matrix_to_latex(Ab):
    #6 x_1 + 7 x_2 &  = 11

    sys_str = ""
    
    for eq in Ab:
        
        eq_str = ""
        
        for coef_index, coef in enumerate(eq[:-1]):
            
            if coef != 0:
                if len(eq_str) > 0:
                    eq_str += "+ "
                if coef == 1:
                    eq_str += "x_{" + str(coef_index + 1) + "} "
                elif coef == -1:
                    eq_str += "-x_{" + str(coef_index + 1) + "} "
                else:
                    eq_str += str(coef) + " x_{" + str(coef_index + 1) + "} "
                        
        eq_str = eq_str.replace("+ -", "- ")
        eq_str += "& = {} \\\\\n".format(eq[-1])
        sys_str += eq_str
    
    return pre_str + sys_str + post_str

```


```python
Ab = np.array([[0, -1, 1],
               [2, 0, 1],
               [1, -1, 2]])

print(complete_matrix_to_latex(Ab))
```

d60dc9a64077ea08eccf4686af2509e0a445ba8f
ipynb
Jupyter Notebook
nb_sci_maths/maths_algebra_system_of_linear_equations_complete_matrix_to_latex_fr.ipynb
jdhp-docs/python-notebooks
91a97ea5cf374337efa7409e4992ea3f26b99179
MIT
2017-05-03T12:23:36.000Z
2020-10-26T17:30:56.000Z
nb_sci_maths/maths_algebra_system_of_linear_equations_complete_matrix_to_latex_fr.ipynb
jdhp-docs/python-notebooks
91a97ea5cf374337efa7409e4992ea3f26b99179
MIT
nb_sci_maths/maths_algebra_system_of_linear_equations_complete_matrix_to_latex_fr.ipynb
jdhp-docs/python-notebooks
91a97ea5cf374337efa7409e4992ea3f26b99179
MIT
2020-10-26T17:30:57.000Z
2020-10-26T17:30:57.000Z
Qwen/Qwen-72B
1. YES
2. YES