In this brief blog post I post a small code that can be used to solve a system of linear equations using SciPy package of Python and in particular the linalg module within the SciPy package.
The code is pretty much self-explanatory, and there is also a YouTube video where I walk you through the procedure.
import numpy as np from scipy import linalg #Solve a system of equations A.X=B #Define the LHS coefficient matrix A A = np.array([ [1, 3, -2], [3, 5, 6], [2, 4, 3] ]) #Print the matrix A print(A) #Define the RHS column vector B B = np.array([ [5, 7, 8] ]) #This is a single row #Transpose it to make a column B = B.T #Print the RHS vector print(B) #Solve the system of equations and store the result in X X = linalg.solve(A, B) #Print the solution print(X)
Ph.D. researcher at Friedrich-Schiller University Jena, Germany. I’m a physicist specializing in computational material science. I write efficient codes for simulating light-matter interactions at atomic scales. I like to develop Physics, DFT, and Machine Learning related apps and software from time to time. Can code in most of the popular languages. I like to share my knowledge in Physics and applications using this Blog and a YouTube channel.