How to solve 3 equations in Python without matrix?
Question:
Hi I have 3 simple equation that I wanted to solve in python.
5x+9y=23 2x+3z=11 7x+5y+6z=35
first I wanted to solve with np.array but first two equation has 2 different unknowns. I can’t find similar problems in internet and I don’t know what should I use to solve this.
Answers:
Use np.linalg.solve
and assign a coefficient of 0 to the missing unknowns
import numpy as np
A = np.array([[5, 9, 0], [2, 0, 3], [7, 5, 6]])
b = np.array([23, 11, 35])
x = np.linalg.solve(A, b)
print(x)
[1., 2., 3.]
So the solution is x=1, y=2, z=3
Hi I have 3 simple equation that I wanted to solve in python.
5x+9y=23 2x+3z=11 7x+5y+6z=35
first I wanted to solve with np.array but first two equation has 2 different unknowns. I can’t find similar problems in internet and I don’t know what should I use to solve this.
Use np.linalg.solve
and assign a coefficient of 0 to the missing unknowns
import numpy as np
A = np.array([[5, 9, 0], [2, 0, 3], [7, 5, 6]])
b = np.array([23, 11, 35])
x = np.linalg.solve(A, b)
print(x)
[1., 2., 3.]
So the solution is x=1, y=2, z=3