solving linear equation using numpy
import numpy as np
a = np.array([[6,2,-5], [3,3,-2], [7,5,-3]])
b = np.array([13,13,26])
x = np.linalg.solve(a, b)
print(x)
solving linear equation using numpy
import numpy as np
a = np.array([[6,2,-5], [3,3,-2], [7,5,-3]])
b = np.array([13,13,26])
x = np.linalg.solve(a, b)
print(x)
python system of equations
import numpy as np
A = np.array([[8, 3, -2], [-4, 7, 5], [3, 4, -12]])
b = np.array([9, 15, 35])
x = np.linalg.solve(A, b)
x
python linear equation components
def liner(x,y):
""" 'y(x) = ax + b' --> get a & b by providing arrays x & y"""
sum_xy = sum([i*j for i,j in zip(x,y)])
sum_x2 = sum([pow(i,2)for i in x ])
a = ( len(y)*sum_xy - sum(x)*sum(y) ) / ( len(y)*sum_x2 - pow(sum(x),2))
b = ( sum(y)*sum_x2 - sum(x)*sum_xy) / ( len(y)*sum_x2 - pow(sum(x),2))
return a,b
xx = [0,2,6,11,12,13,17,21,24,26,31,36,37]
yy = [0,4,7,11,16,26,27,31,39,47,49,57,58]
a,b = liner(xx,yy)
print("a:",a," b:",b) # a: 1.631407787762088 b: -1.000941377834831
# Or use numpy
import numpy as np
np.polyfit(xx, yy, 1) # [ 1.63140779 -1.00094138]
solve linear system python
>>> a = np.array([[3,1], [1,2]])
>>> b = np.array([9,8])
>>> x = np.linalg.solve(a, b)
>>> x
array([2., 3.])
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us