Solving the linear equations
The linalg.solve function is used to solve the given linear equations. It is used to evaluate the equations automatically and find the values of the unknown variables.
Syntax: scipy.linalg.solve(a, b, sym_pos, lower, overwrite_a, overwrite_b, debug, check_finite, assume_a, transposed)
Let’s consider an example where two arrays a and b are taken by the linalg.solve function. Array a contains the coefficients of the unknown variables while Array b contains the right-hand-side value of the linear equation. The linear equation is solved by the function to determine the value of the unknown variables. Suppose the linear equations are:
7x + 2y = 8 4x + 5y = 10
Python
# Import the required libraries from scipy import linalg import numpy as np # The function takes two arrays a = np.array([[ 7 , 2 ], [ 4 , 5 ]]) b = np.array([ 8 , 10 ]) # Solving the linear equations res = linalg.solve(a, b) print (res) |
Output:
[0.74074074 1.40740741]
SciPy Linear Algebra – SciPy Linalg
The SciPy package includes the features of the NumPy package in Python. It uses NumPy arrays as the fundamental data structure. It has all the features included in the linear algebra of the NumPy module and some extended functionality. It consists of a linalg submodule, and there is an overlap in the functionality provided by the SciPy and NumPy submodules.
Let’s discuss some methods provided by the module and its functionality with some examples.