1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| import numpy as np import matplotlib.pyplot as plt
A = np.array([[7, 2], [-7, 5]]) b = np.array([-5, 12])
x = np.linalg.solve(A, b)
x1, y1 = x print(x1, y1)
fig = plt.figure() ax = fig.add_subplot(1, 1, 1)
a1 = A[:, 0] b1 = A[:, 1] c1 = -b
for c1, c2, c3 in zip(A[:, 0], A[:, 1], b): x = np.linspace(-7, 7, 100) y = (c3-c1*x)/c2 ax.plot(x, y, color="black")
ax.plot(x1, y1, 'ro')
ax.axis([-7, 7, -7, 7]) ax.set_xticks(range(-7, 7)) ax.set_yticks(range(-7,7)) ax.grid() ax.set_axisbelow(True) ax.set_aspect('equal', adjustable='box')
ax.spines['left'].set_position('zero') ax.spines['bottom'].set_position('zero')
ax.spines['right'].set_color('none') ax.spines['top'].set_color('none')
plt.show()
|