top of page

Solving Multiple Linear Equations With Numpy



Here we have solved the below Multiple Linear Equations using numpy:


๐‘ฅ+2๐‘ฆโˆ’๐‘ง=42

๐‘ฅ+๐‘ฆ+๐‘ง=โˆ’2

๐‘ฅ+2๐‘ฆ+๐‘ง=2


Import Libraries

import numpy as np

Creating Array of values using numpy

# coefficient matrix 
A = np.array([[1, 2, -1], [2, 1, 1], [1, 2, 1]])

# numbers on the right without variables
b = np.array([4, -2, 2])

# solve using np.linagl.solve()
np.linalg.solve(A, b)

Output

array([-1.66666667, 2.33333333, -1. ])

Comments


bottom of page