<jupyter_start><jupyter_text>What is Symbolic Computation?Symbolic computation deals with the computation of mathematical objects symbolically. This means that the mathematical objects are represented exactly, not approximately, and mathematical expressions with unevaluated variables are left in symbolic form. SymPy Solver Demolet's create a symbolic variable $z$, and define an arbitrary equation of $55.9728340445699z^2+32z−28.1086638217203=0$, and solve it symbolically.<jupyter_code># Written by <NAME> and <NAME>
# SymPy is the python library for symbolic mathematics.
# https://docs.sympy.org/latest/index.html
import sympy as sp
import math
sp.init_printing(use_unicode=True)

# Define z as a symbolic variable.
z = sp.symbols('z')

# Get the k-value, substitute it into the function. 
# Note that cos() takes angles in radians, so convert from degrees. 
k = math.cos(math.radians(33))
k
# Define our function. 
f = (81*k**2 - 1)*z**2 + 32*z + (324*k**2 - 256)
f
# Define the related equation. 
eqn = sp.Eq(f,0)
eqn
# Solve the equation
sp.solveset(eqn, z)<jupyter_output><empty_output><jupyter_text>How calculate RREF and solve system of linear equations in SymPy?Assume the following system of linear equations. SymPy can reduce the following matrices to RREF:$\left(\begin{array}{ccc|c}1 & 2 & -4 & 12 \\ 2 & 6 & 8 & 14 \\ 0 & 1 & 8 & -5\end{array}\right)$\begin{alignedat}{3}% R & L   &  R & L   &  R & L   x & +{} &  2y & +{} & -4z & = 12 \\  2x & +{} &  6y & +{} &  8z & = 14 \\ & {} &  y & +{} &  8z & = -5 \\\end{alignedat}To calculate RREF we can use augmented matrix as follows:<jupyter_code>#Defining symbolic augmented matrix
A = sp.Matrix([[1,2,-4,12],[2,6,8,14],[0,1,8,-5]])
A

# print RREF
A.rref()<jupyter_output><empty_output><jupyter_text>Solving system of linear equations in SymPyRREF method does not provide final solutions for the following system of linear equations:\begin{alignedat}{3}% R & L   &  R & L   &  R & L   x & +{} &  2y & +{} & -4z & = 12 \\  2x & +{} &  6y & +{} &  8z & = 14 \\ & {} &  y & +{} &  8z & = -5 \\\end{alignedat}To find solutions in Sympy you should use the *Sandard Matrix Representation*, $A\mathbf{x}=\mathbf{b}$:\begin{alignedat}{3}\left[\begin{array}{ccc}1 & 2 & -4 \\ 2 & 6 & 8 \\ 0 & 1 & 8\end{array}\right]\left[\begin{array}{l}x \\ y \\ z\end{array}\right]=\left[\begin{array}{c}12 \\ 14 \\ -5\end{array}\right]\end{alignedat}- $A$ is called the coefficient matrix- $\mathbf{x}$ is the unknowns or solution vector- $\mathbf{b}$ is the constant vectorWhere- $A=\left[\begin{array}{ccc}1 & 2 & -4 \\ 2 & 6 & 8 \\ 0 & 1 & 8\end{array}\right]$- $\mathbf{x}=\left[\begin{array}{c}x \\ y \\ z\end{array}\right]$- $\mathbf{b}=\left[\begin{array}{c}12 \\ 14 \\ -5\end{array}\right]$To solve the system you can use `sp.linsolve` as follows:<jupyter_code>x, y, z = sp.symbols('x, y, z')
A = sp.Matrix([[1, 2, -4], [2, 6, 8], [0, 1, 8]])
b = sp.Matrix([12, 14, -5])
sp.linsolve((A, b), x, y, z)<jupyter_output><empty_output><jupyter_text>The above answer is equivalent to what we find manually after solving using RREF method:$$\begin{aligned}&z=t \in \mathbb{R}\\&y=-5-8 t \\&x=22+20 t\end{aligned}$$  Calculating the Inverse MatrixYou can calculate the inverse of matrix using `inv()` method as follows:  Note:A square matrix is invertible if and only if the determinant is not equal to zero.<jupyter_code>A = sp.Matrix([[1, 2, -4], [2, 6, 8], [0, 1, 8]])
if(A.det()!=0):
  A_inv=A.inv()
else:
  A_inv=[]
  print ("Non Invertible Matrix: Matrix det == 0; not invertible.")
A_inv
A = sp.Matrix([[2, 1, 0], [0, 4, -3], [1, -3, 2]])
if(A.det()!=0):
  A_inv=A.inv()
else:
  A_inv=[]
  print ("Non Invertible Matrix: Matrix det == 0; not invertible.")

A_inv<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17557455905932656, 'fraction_numerical': 0.046499198289684664, 'mean_word_length': 3.984021304926764, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '62937', 'license': 'CC0-1.0', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1348, 'n_words': 422, 'path': 'Solving_The_System_of_Linear_Equations_Using_SymPy.ipynb', 'repo_name': 'tofighi/Linear-Algebra', 'size': '3762'}