Difference between revisions of "Nomor 2"
(Created page with "File:uts.jpg") |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | + | import numpy as np | |
+ | # Python program to implement Runge Kutta method | ||
+ | # with acceleration of car is 8 m/s**2 | ||
+ | # air friction and road friction is -0.0015*V m/s and -2.5m/s**2 | ||
+ | # so equation became v = 8*t - 2.5*t - 0.0015*v | ||
+ | # A sample differential equation "dv / dt = 8/1.001" | ||
+ | def dvdt(t,v): | ||
+ | return (8/1.001) | ||
+ | # Finds value of y for a given x using step size h | ||
+ | # and initial value y0 at x0. | ||
+ | def rungeKutta(t0, v0, t, h): | ||
+ | #count number of step size | ||
+ | #step h | ||
+ | n = (int)((t - t0)/h) | ||
+ | |||
+ | v = v0 | ||
+ | for i in range (1, n + 1): | ||
+ | "apply rungakutta" | ||
+ | k1 = h * dvdt(t0, v) | ||
+ | k2 = h * dvdt(t0 + 0.5 * h, v + 0.5 * k1) | ||
+ | k3 = h * dvdt(t0 + 0.5 * h, v + 0.5 * k2) | ||
+ | k4 = h * dvdt(t0 + h, v + k3) | ||
+ | |||
+ | #next value of v | ||
+ | v = v + (1.0 / 6.0)*(k1 + 2 * k2 + 2 * k3 + k4) | ||
+ | # Update next value of t | ||
+ | t0 = t0 + h | ||
+ | return v | ||
+ | # Driver method | ||
+ | t0 = 0 | ||
+ | v = 8 | ||
+ | t = 15 | ||
+ | h = 0.25 | ||
+ | print ('Nilai Y pada saat X adalah:', rungeKutta(t0, v, t, h)) | ||
+ | |||
+ | dengan ini didapatkan hasil sebesar | ||
+ | |||
+ | Nilai Y pada saat X adalah: 127.8801198801198 |
Latest revision as of 23:48, 27 October 2019
import numpy as np
- Python program to implement Runge Kutta method
- with acceleration of car is 8 m/s**2
- air friction and road friction is -0.0015*V m/s and -2.5m/s**2
- so equation became v = 8*t - 2.5*t - 0.0015*v
- A sample differential equation "dv / dt = 8/1.001"
def dvdt(t,v):
return (8/1.001)
- Finds value of y for a given x using step size h
- and initial value y0 at x0.
def rungeKutta(t0, v0, t, h):
#count number of step size #step h n = (int)((t - t0)/h)
v = v0 for i in range (1, n + 1): "apply rungakutta" k1 = h * dvdt(t0, v) k2 = h * dvdt(t0 + 0.5 * h, v + 0.5 * k1) k3 = h * dvdt(t0 + 0.5 * h, v + 0.5 * k2) k4 = h * dvdt(t0 + h, v + k3)
#next value of v v = v + (1.0 / 6.0)*(k1 + 2 * k2 + 2 * k3 + k4) # Update next value of t t0 = t0 + h return v
- Driver method
t0 = 0 v = 8 t = 15 h = 0.25 print ('Nilai Y pada saat X adalah:', rungeKutta(t0, v, t, h))
dengan ini didapatkan hasil sebesar
Nilai Y pada saat X adalah: 127.8801198801198