# Python to Solve Linear Equation and return 3D Graph with Full Source Code For Beginners

Enter values through spaces for each of the three equations, return the solution and a 3D graph.

• Numpy
• Matplotlib

## Install Prerequisites:

pip install numpy
pip install matplotlib

## Run the Script:

python3 linearEquations.pyCode language: CSS (css)

## Source Code:

linearEquations.py

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm

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')

print('Enter values for equation 1: ')
a, b, c, d = map(float, input().split())

print('Enter values for equation 2: ')
e, f, g, h = map(float, input().split())

print('Enter values for equation 3: ')
i, j, k, l = map(float, input().split())
#solve the linear equation
A = np.array([[a,b,c],[e,f,g],[i,j,k]])
b_a = np.array([d,h,l])
sol = np.linalg.solve(A,b_a)
print(sol)

x,y = np.linspace(0,10,10), np.linspace(0,10,10)
X,Y = np.meshgrid(x,y)

Z1 = (d-a*X-b*Y)/c
Z2 =(h-e*X-f*Y)/g
Z3 =(l+X-Y)/k

#create 3d graphics

fig = plt.figure()