KnowledgeBoat Logo
|

Robotics & Artificial Intelligence

Write a Python program to solve the following linear equations:

2x + y = 5
x + 3y = 8

Python Modules

1 Like

Answer

import numpy as np
from scipy.linalg import solve
coefficients = np.array([[2, 1], [1, 3]])
constants = np.array([5, 8])
solution = solve(coefficients, constants)
x = solution[0]
y = solution[1]
print("x =", x)
print("y =", y)

Output

x = 1.3999999999999997
y = 2.2

Answered By

2 Likes


Related Questions