Difference between revisions of "Tugas rungekutta MFS"

From ccitonlinewiki
Jump to: navigation, search
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[File:gambarsoalmetnummfs.jpg]]
+
[[File:soalrunge.png]]
  
 
'''Koding'''
 
'''Koding'''
Line 5: Line 5:
 
import numpy as np
 
import numpy as np
  
v0 = eval(input('kecepatan awal benda: '))
+
m = eval(input('massa benda: '))
 +
 
 
g = eval(input('percepatan gravitasi: '))
 
g = eval(input('percepatan gravitasi: '))
 +
 
u = eval(input('koefisien gesek bidang: '))
 
u = eval(input('koefisien gesek bidang: '))
 +
 +
cd = eval(input('koefisien gesek udara: '))
 +
 
teta = eval(input('sudut kemiringan bukit: ')) * (np.pi / 180)
 
teta = eval(input('sudut kemiringan bukit: ')) * (np.pi / 180)
 +
 
sint = np.sin(teta)
 
sint = np.sin(teta)
 +
 
cost = np.cos(teta)
 
cost = np.cos(teta)
print(sint)
+
 
a = g * (sint + u * cost)
+
v0 = 0
ay = a * sint
+
 
s0 = 0
 
 
t0 = 0
 
t0 = 0
 +
 
dt = 1  
 
dt = 1  
 +
 
error = 100
 
error = 100
v = v0 ** 2
+
 
 
tries = []
 
tries = []
  
def dsdt(t0, s0):
+
p = g * (sint - u * cost)
   return v - (2 * ay * s0) ** 0.5
+
 
 +
q = cd / m
 +
 
 +
def dvdt(t0, v0):
 +
   return p - q * (v0 ** 1.5)
  
 
while error > 0.005:
 
while error > 0.005:
   k1 = dsdt(t0, s0)  
+
   k1 = dvdt(t0, v0)  
   k2 = dsdt(t0 + 0.5 * dt, s0 + 0.5 * dt * k1)
+
   k2 = dvdt(t0 + 0.5 * dt, v0 + 0.5 * dt * k1)
   k3 = dsdt(t0 + 0.5 * dt, s0 + 0.5 * dt * k2)  
+
   k3 = dvdt(t0 + 0.5 * dt, v0 + 0.5 * dt * k2)  
   k4 = dsdt(t0 + dt, s0 + dt * k3)  
+
   k4 = dvdt(t0 + dt, v0 + dt * k3)  
   s1 = s0 + (1.0 / 6.0) * (k1 + 2 * k2 + 2 * k3 + k4)
+
   v1 = v0 + (1.0 / 6.0) * (k1 + 2 * k2 + 2 * k3 + k4)
 
   t0 = t0 + dt
 
   t0 = t0 + dt
   error = ((s1 - s0) / s1) * 100  
+
   error = ((v1 - v0) / v1) * 100  
   s0 = s1
+
   v0 = v1
   tries.append(s1)
+
   tries.append(v1)
 
    
 
    
 
t1 = len(tries)
 
t1 = len(tries)
  
print(f'jarak maksimum yang dapat dicapai adalah {round(s1, 2)} m dengan waktu {t1 + 1} s')
+
print(f'kecepatan maksimum yang dapat dicapai adalah {round(v1, 2)} m/s dengan waktu {t1 + 1} s')
 +
 
 +
[[File:hasilmfs.png]]
 +
 
 +
'''Video'''
 +
 
 +
[[File:Videorugekuttamfs.mkv]]

Latest revision as of 16:02, 6 November 2019

Soalrunge.png

Koding

import numpy as np

m = eval(input('massa benda: '))

g = eval(input('percepatan gravitasi: '))

u = eval(input('koefisien gesek bidang: '))

cd = eval(input('koefisien gesek udara: '))

teta = eval(input('sudut kemiringan bukit: ')) * (np.pi / 180)

sint = np.sin(teta)

cost = np.cos(teta)

v0 = 0

t0 = 0

dt = 1

error = 100

tries = []

p = g * (sint - u * cost)

q = cd / m

def dvdt(t0, v0):

 return p - q * (v0 ** 1.5)

while error > 0.005:

 k1 = dvdt(t0, v0) 
 k2 = dvdt(t0 + 0.5 * dt, v0 + 0.5 * dt * k1)
 k3 = dvdt(t0 + 0.5 * dt, v0 + 0.5 * dt * k2) 
 k4 = dvdt(t0 + dt, v0 + dt * k3) 
 v1 = v0 + (1.0 / 6.0) * (k1 + 2 * k2 + 2 * k3 + k4)
 t0 = t0 + dt
 error = ((v1 - v0) / v1) * 100 
 v0 = v1
 tries.append(v1)
 

t1 = len(tries)

print(f'kecepatan maksimum yang dapat dicapai adalah {round(v1, 2)} m/s dengan waktu {t1 + 1} s')

Hasilmfs.png

Video