Skip to content
Kinematika Dengan Matplotlib & Python
Kinematika Dengan Matplotlib & Python
Dimastio Setiawan (2404993)
# Import the course packages
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
waktu = [0, 1, 2, 3, 4, 5]
jarak = [0, 2.3, 9.2, 20.7, 36.8, 57.5]
data = {'t':waktu, 'x':jarak}
tabel_data = pd.DataFrame(data)
print(tabel_data)
plt.plot(waktu, jarak, 'bo')
plt.plot(waktu, jarak)
for x, y in zip(waktu, jarak):
label = "{: .2f}".format(y)
plt.annotate(label, (x, y), textcoords="offset points", xytext=(0, 10), ha='center')
plt.ylabel("X (m)")
plt.xlabel("T (s)")
plt.grid(True)
plt.show()
# Import the course packages
import numpy as np
import matplotlib.pyplot as plt
waktu = [0, 1, 2, 3, 4, 5]
jarak = [0, 2.3, 9.2, 20.7, 36.8, 57.5]
np_waktu = np.array(waktu)
np_jarak = np.array(jarak)
s = jarak[-1]
t = waktu[-1]
a = [s * 2 / t**2 for i in range(len(np_waktu))]
v = [a[i] * np_waktu[i] for i in range(len(a))]
data = {'t':waktu, 'x':jarak, 'v':v}
tabel_data = pd.DataFrame(data)
print(tabel_data)
plt.plot(np_waktu, v, 'bo')
plt.plot(np_waktu, v)
for x, y in zip(np_waktu, v):
label = "{: .2f}".format(y)
plt.annotate(label, (x, y), textcoords="offset points", xytext=(0, 10), ha='center')
plt.ylabel("V (m/s)")
plt.xlabel("T (s)")
plt.grid(True)
plt.show()
# Import the course packages
import numpy as np
import matplotlib.pyplot as plt
waktu = [0, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3, 3.25, 3.5, 3.75, 4, 4.25, 4.5, 4.75, 5]
tinggi = [5, 5.75, 6.4, 6.94, 7.38, 7.72, 7.96, 8.10, 8.13, 8.07, 7.9, 7.62, 7.25, 6.77, 6.2, 5.52, 4.73, 3.85, 2.86, 1.77, 0.58]
data = {'t':waktu, 'h':tinggi}
tabel_data = pd.DataFrame(data)
print(tabel_data)
plt.plot(waktu, tinggi, 'bo')
plt.plot(waktu, tinggi)
for x, y in zip(waktu, tinggi):
label = "{: .2f}".format(y)
plt.annotate(label, (x, y), textcoords="offset points", xytext=(0, 10), ha='center')
plt.ylabel("H (m)")
plt.xlabel("T (s)")
plt.grid(True)
plt.show()
# Import the course packages
import numpy as np
import matplotlib.pyplot as plt
waktu = [0, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3, 3.25, 3.5, 3.75, 4, 4.25, 4.5, 4.75, 5]
tinggi = [5, 5.75, 6.4, 6.94, 7.38, 7.72, 7.96, 8.10, 8.13, 8.07, 7.9, 7.62, 7.25, 6.77, 6.2, 5.52, 4.73, 3.85, 2.86, 1.77, 0.58]
np_waktu = np.array(waktu)
np_tinggi = np.array(tinggi)
s_naik = 3.13
s_jatuh = np_tinggi[-1] - np_tinggi[8]
t_naik = np_waktu[8] - np_waktu[0]
t_jatuh = np_waktu[-1] - np_waktu[8]
v0_naik = s_naik
a_naik = np.array([(v0_naik - (s_naik * 2)) / t_naik for i in range(len(np_waktu[0:8]))])
a_jatuh = np.array([(s_jatuh * 2) / t_jatuh**2 for i in range(len(np_waktu[8:]))])
a = np.append(a_naik, a_jatuh)
data = {'t':np_waktu, 'h':np_tinggi, 'a':a}
tabel_data = pd.DataFrame(data)
print(tabel_data)
plt.plot(np_waktu, a, 'bo')
plt.plot(np_waktu, a)
plt.ylim(-2, 0)
for x, y in zip(np_waktu, a):
label = "{: .2f}".format(y)
plt.annotate(label, (x, y), textcoords="offset points", xytext=(0, 10), ha='center')
plt.ylabel("a (m/s^2)")
plt.xlabel("T (s)")
plt.grid(True)
plt.show()
# Import the course packages
import numpy as np
import matplotlib.pyplot as plt
waktu = [0, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3, 3.25, 3.5, 3.75, 4, 4.25, 4.5, 4.75, 5]
tinggi = [5, 5.75, 6.4, 6.94, 7.38, 7.72, 7.96, 8.10, 8.13, 8.07, 7.9, 7.62, 7.25, 6.77, 6.2, 5.52, 4.73, 3.85, 2.86, 1.77, 0.58]
np_waktu = np.array(waktu)
np_tinggi = np.array(tinggi)
s_naik = 3.13
s_jatuh = np_tinggi[-1] - np_tinggi[8]
t_naik = np_waktu[8] - np_waktu[0]
t_jatuh = np_waktu[-1] - np_waktu[8]
v0_naik = s_naik
a_naik = np.array([(v0_naik - (s_naik * 2)) / t_naik for i in range(len(np_waktu[0:8]))])
a_jatuh = np.array([(s_jatuh * 2) / t_jatuh**2 for i in range(len(np_waktu[8:]))])
a = np.append(a_naik, a_jatuh)
v = np.array([a[i] * np_waktu[i] for i in range(len(np_waktu))])
data = {'t':np_waktu, 'h':np_tinggi, 'a':a, 'v':v}
tabel_data = pd.DataFrame(data)
print(tabel_data)
plt.plot(np_waktu, v, 'bo')
plt.plot(np_waktu, v)
for x, y in zip(np_waktu, v):
label = "{: .2f}".format(y)
plt.annotate(label, (x, y), textcoords="offset points", xytext=(0, 10), ha='center')
plt.ylabel("a (m/s^2)")
plt.xlabel("T (s)")
plt.grid(True)
plt.show()
# Import the course packages
import numpy as np
import matplotlib.pyplot as plt
# 45 derajat, 95.5 m/s
sudut = float(input("Sudut (derajat): "))
kecepatan_awal = 100
# kecepatan_awal = float(input("Kecepatan Awal (m/s): "))
g = 10
letak_target_x = 800
letak_target_y = 100
np_sudut_optimal = np.arctan(letak_target_y / letak_target_x)
sudut_optimal = np.degrees(np_sudut_optimal)
np_sudut = np.radians(sudut)
kecepatan_awal_x = kecepatan_awal * np.cos(np_sudut)
kecepatan_awal_optimal_x = kecepatan_awal * np.cos(np_sudut_optimal)
# v0x = v0 cos0
kecepatan_awal_y = kecepatan_awal * np.sin(np_sudut)
kecepatan_awal_optimal_y = kecepatan_awal * np.sin(np_sudut_optimal)
# v0y = v0 sin0
waktu_terbang = (2 * kecepatan_awal_y)
waktu = np.linspace(0, waktu_terbang, num=100)
jarak = np.sqrt(letak_target_x**2 + letak_target_y**2)
waktu_ke_target = jarak / kecepatan_awal
x = kecepatan_awal_x * waktu
y = kecepatan_awal_y * waktu
x_optimal = kecepatan_awal_optimal_x * waktu
y_optimal = kecepatan_awal_optimal_y * waktu
print("Sudut optimal: ", sudut_optimal, "derajat")
print("Selang waktu: ", waktu_ke_target, "s")
plt.plot(x, y)
plt.plot(x_optimal, y_optimal, color='red', linestyle='dashed')
plt.plot(letak_target_x, letak_target_y, marker='o', color='red', label='Target')
plt.xlim(0, 1000)
plt.ylim(0, 200)
plt.xlabel("X (m)")
plt.ylabel("Y (m)")
plt.grid(True)
plt.show()
# Import the course packages
import numpy as np
import matplotlib.pyplot as plt
# 45 derajat, 95.5 m/s
sudut = float(input("Sudut (derajat): "))
kecepatan_awal = 100
# kecepatan_awal = float(input("Kecepatan Awal (m/s): "))
g = 10
letak_target_x = 800
letak_target_y = 100
np_sudut = np.radians(sudut)
kecepatan_awal_x = kecepatan_awal * np.cos(np_sudut)
# v0x = v0 cos0
kecepatan_awal_y = kecepatan_awal * np.sin(np_sudut)
# v0y = v0 sin0
waktu_terbang = (2 * kecepatan_awal_y) / g
waktu = np.linspace(0, waktu_terbang, num=100)
x = kecepatan_awal_x * waktu
y = kecepatan_awal_y * waktu - 0.5 * g * waktu**2
# plt.plot(x, y, 'bo')
print("Selang waktu: ", waktu_terbang, "s")
plt.plot(x, y)
plt.plot(letak_target_x, letak_target_y, marker='o', color='red', label='Target')
plt.xlabel("X (m)")
plt.ylabel("Y (m)")
plt.grid(True)
plt.show()
# Import the course packages
import numpy as np
import matplotlib.pyplot as plt
# 45 derajat, 95.5 m/s
sudut = float(input("Sudut (derajat): "))
kecepatan_awal = 100
# kecepatan_awal = float(input("Kecepatan Awal (m/s): "))
g = 10
letak_target_x = 800
letak_target_y = 100
np_sudut = np.radians(sudut)
kecepatan_awal_x = kecepatan_awal * np.cos(np_sudut)
# v0x = v0 cos0
kecepatan_awal_y = kecepatan_awal * np.sin(np_sudut)
# v0y = v0 sin0
waktu_terbang = (2 * kecepatan_awal_y) / g
waktu = np.linspace(0, waktu_terbang, num=100)
x = kecepatan_awal_x * waktu
y = kecepatan_awal_y * waktu - 0.5 * g * waktu**2
# plt.plot(x, y, 'bo')
print("Selang waktu: ", waktu_terbang, "s")
plt.plot(x, y)
plt.plot(letak_target_x, letak_target_y, marker='o', color='red', label='Target')
plt.xlabel("X (m)")
plt.ylabel("Y (m)")
plt.grid(True)
plt.show()