|
| 1 | +import numpy as np |
| 2 | +import matplotlib.pyplot as plt |
| 3 | +from mpl_toolkits.mplot3d import Axes3D |
| 4 | +from matplotlib import cm |
| 5 | + |
| 6 | +print('The 3 equations are entered individually, each value of the equation is entered separated by a space, for example: \ninput = 6 5 -3 4 \nThis will be equal to 6x + 5y- 3z = 4') |
| 7 | + |
| 8 | +print('Enter values for equation 1: ') |
| 9 | +a, b, c, d = map(float, input().split()) |
| 10 | + |
| 11 | +print('Enter values for equation 2: ') |
| 12 | +e, f, g, h = map(float, input().split()) |
| 13 | + |
| 14 | +print('Enter values for equation 3: ') |
| 15 | +i, j, k, l = map(float, input().split()) |
| 16 | +#solve the linear equation |
| 17 | +A = np.array([[a,b,c],[e,f,g],[i,j,k]]) |
| 18 | +b_a = np.array([d,h,l]) |
| 19 | +sol = np.linalg.solve(A,b_a) |
| 20 | +print(sol) |
| 21 | + |
| 22 | + |
| 23 | +x,y = np.linspace(0,10,10), np.linspace(0,10,10) |
| 24 | +X,Y = np.meshgrid(x,y) |
| 25 | + |
| 26 | +Z1 = (d-a*X-b*Y)/c |
| 27 | +Z2 =(h-e*X-f*Y)/g |
| 28 | +Z3 =(l+X-Y)/k |
| 29 | + |
| 30 | +#create 3d graphics |
| 31 | + |
| 32 | +fig = plt.figure() |
| 33 | +ax = fig.add_subplot(111,projection='3d') |
| 34 | +ax.plot_surface(X,Y,Z1,alpha=0.5,cmap=cm.Accent,rstride=100,cstride=100) |
| 35 | +ax.plot_surface(X,Y,Z2,alpha=0.5,cmap=cm.Paired,rstride=100,cstride=100) |
| 36 | +ax.plot_surface(X,Y,Z3,alpha=0.5,cmap=cm.Pastel1,rstride=100,cstride=100) |
| 37 | +ax.plot((sol[0],),(sol[1],),(sol[2],),lw=2,c='k', marker='o', markersize=7, markeredgecolor='g', markerfacecolor='white') |
| 38 | +ax.set_xlabel('X axis') |
| 39 | +ax.set_ylabel('Y axis') |
| 40 | +ax.set_zlabel('Z axis') |
| 41 | + |
| 42 | +plt.show() |
| 43 | + |
| 44 | + |
0 commit comments