Eliminasi Gauss dengan Python
Eliminasi Gauss dengan Python
Coding Python
#python 2.7.15
#Nama = Muhammad Ikhwan Fathulloh
#Kelas = TIF RP19C
#NPM = 19552011024
#Mata Kuliah = Metode Numerik
#Nama = Muhammad Ikhwan Fathulloh
#Kelas = TIF RP19C
#NPM = 19552011024
#Mata Kuliah = Metode Numerik
b1k1=int("1")
b1k2=int("1")
b1k3=int("-1")
b1k4=int("1")
b1k2=int("1")
b1k3=int("-1")
b1k4=int("1")
b2k1=int("2")
b2k2=int("2")
b2k3=int("1")
b2k4=int("5")
b2k2=int("2")
b2k3=int("1")
b2k4=int("5")
b3k1=int("-1")
b3k2=int("1")
b3k3=int("2")
b3k4=int("5")
print("1x + 1y + -1z = 1")
print("2x + 2y + 1z = 5")
print("-1x - 1y - 2z = 5")
b3k2=int("1")
b3k3=int("2")
b3k4=int("5")
print("1x + 1y + -1z = 1")
print("2x + 2y + 1z = 5")
print("-1x - 1y - 2z = 5")
print("\n |",b1k1," ",b1k2," ",b1k3," ",b1k4,"|")
print(" |",b2k1," ",b2k2," ",b2k3," ",b2k4,"|")
print(" |",b3k1," ",b3k2," ",b3k3," ",b3k4,"|")
print("---------------------------------")
print(" |",b2k1," ",b2k2," ",b2k3," ",b2k4,"|")
print(" |",b3k1," ",b3k2," ",b3k3," ",b3k4,"|")
print("---------------------------------")
b2k1=(b2k1-b1k1)
b2k2=(b2k2-b1k2)
b2k3=(b2k3-b1k3)
b2k4=(b2k4-b1k4)
print("B2 - B1")
print(" |",b1k1," ",b1k2," ",b1k3," ",b1k4,"|")
print(" |",b2k1," ",b2k2," ",b2k3," ",b2k4,"|")
print(" |",b3k1," ",b3k2," ",b3k3," ",b3k4,"|")
print("---------------------------------")
b2k2=(b2k2-b1k2)
b2k3=(b2k3-b1k3)
b2k4=(b2k4-b1k4)
print("B2 - B1")
print(" |",b1k1," ",b1k2," ",b1k3," ",b1k4,"|")
print(" |",b2k1," ",b2k2," ",b2k3," ",b2k4,"|")
print(" |",b3k1," ",b3k2," ",b3k3," ",b3k4,"|")
print("---------------------------------")
b3k1=(b3k1-(2*b1k1))
b3k2=(b3k2-(2*b1k2))
b3k3=(b3k3-(2*b1k3))
b3k4=(b3k4-(2*b1k4))
print("B3 - 2 * B1")
print(" |",b1k1," ",b1k2," ",b1k3," ",b1k4,"|")
print(" |",b2k1," ",b2k2," ",b2k3," ",b2k4,"|")
print(" |",b3k1," ",b3k2," ",b3k3," ",b3k4,"|")
print("---------------------------------")
b3k2=(b3k2-(2*b1k2))
b3k3=(b3k3-(2*b1k3))
b3k4=(b3k4-(2*b1k4))
print("B3 - 2 * B1")
print(" |",b1k1," ",b1k2," ",b1k3," ",b1k4,"|")
print(" |",b2k1," ",b2k2," ",b2k3," ",b2k4,"|")
print(" |",b3k1," ",b3k2," ",b3k3," ",b3k4,"|")
print("---------------------------------")
b3k1=(b3k1+(6*b2k1))
b3k2=(b3k2+(6*b2k2))
b3k3=(b3k3+(6*b2k3))
b3k4=(b3k4+(6*b2k4))
print("B3 : 4")
print(" |",b1k1," ",b1k2," ",b1k3," ",b1k4,"|")
print(" |",b2k1," ",b2k2," ",b2k3," ",b2k4,"|")
print(" |",b3k1," ",b3k2," ",b3k3," ",b3k4,"|")
print("---------------------------------")
b3k2=(b3k2+(6*b2k2))
b3k3=(b3k3+(6*b2k3))
b3k4=(b3k4+(6*b2k4))
print("B3 : 4")
print(" |",b1k1," ",b1k2," ",b1k3," ",b1k4,"|")
print(" |",b2k1," ",b2k2," ",b2k3," ",b2k4,"|")
print(" |",b3k1," ",b3k2," ",b3k3," ",b3k4,"|")
print("---------------------------------")
b3k1=round(b3k1/4)
b3k2=round(b3k2/4)
b3k3=round(b3k3/4)
b3k4=round(b3k4/4)
b3k2=round(b3k2/4)
b3k3=round(b3k3/4)
b3k4=round(b3k4/4)
print(" |",b1k1," ",b1k2," ",b1k3," ",b1k4,"|")
print(" |",b2k1," ",b2k2," ",b2k3," ",b2k4,"|")
print(" |",b3k1," ",b3k2," ",b3k3," ",b3k4,"|")
print("---------------------------------")
print(" |",b2k1," ",b2k2," ",b2k3," ",b2k4,"|")
print(" |",b3k1," ",b3k2," ",b3k3," ",b3k4,"|")
print("---------------------------------")
print("Hasil Eliminasi Gauss")
print(b1k4, b2k4, b3k4)
print(b1k4, b2k4, b3k4)
Output Program
1x + 1y + -1z = 1
2x + 2y + 1z = 5
-1x - 1y - 2z = 5
('\n |', 1, ' ', 1, ' ', -1, ' ', 1, '|')
(' |', 2, ' ', 2, ' ', 1, ' ', 5, '|')
(' |', -1, ' ', 1, ' ', 2, ' ', 5, '|')
---------------------------------
B2 - B1
(' |', 1, ' ', 1, ' ', -1, ' ', 1, '|')
(' |', 1, ' ', 1, ' ', 2, ' ', 4, '|')
(' |', -1, ' ', 1, ' ', 2, ' ', 5, '|')
---------------------------------
B3 - 2 * B1
(' |', 1, ' ', 1, ' ', -1, ' ', 1, '|')
(' |', 1, ' ', 1, ' ', 2, ' ', 4, '|')
(' |', -3, ' ', -1, ' ', 4, ' ', 3, '|')
---------------------------------
B3 : 4
(' |', 1, ' ', 1, ' ', -1, ' ', 1, '|')
(' |', 1, ' ', 1, ' ', 2, ' ', 4, '|')
(' |', 3, ' ', 5, ' ', 16, ' ', 27, '|')
---------------------------------
(' |', 1, ' ', 1, ' ', -1, ' ', 1, '|')
(' |', 1, ' ', 1, ' ', 2, ' ', 4, '|')
(' |', 0.0, ' ', 1.0, ' ', 4.0, ' ', 6.0, '|')
---------------------------------
Hasil Eliminasi Gauss
(1, 4, 6.0)
Process finished.
Komentar
Posting Komentar