Algoritma Rudal X dan Y

From ccitonlinewiki
Revision as of 22:17, 5 November 2019 by Alesdaniel (talk | contribs) (Created page with "''Sumbu X'' : from math import * g = 9.81 m = eval(input("Massa rudal dalam kg: ")) sudut = eval(input("Sudut kemiringan rudal dalam derajat: ")) a = eval(input("Percepat...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Sumbu X :

from math import *

g = 9.81

m = eval(input("Massa rudal dalam kg: "))

sudut = eval(input("Sudut kemiringan rudal dalam derajat: "))

a = eval(input("Percepatan yang diinginkan: "))

cd = eval(input("Koefisien hambat udara: "))

alpha = sudut*0.0174

ay = a*(sin(alpha))

ax = a*(cos(alpha))

v0 = 0

x0 = 0

t0 = 0

dt = 0.1

error = 100

lst = []

def dxdt(t0, v0):

 return ((ax-(cd*v0**3/2)/m))

while error > 0.005:

 k1 = dt*dxdt(t0, v0)
 k2 = dt*dxdt(t0+0.5*dt, v0+0.5*dt*k1)
 k3 = dt*dxdt(t0+0.5*dt, v0+0.5*dt*k2)
 k4 = dt*dxdt(t0+dt, v0+k3*dt)
 v1 = v0 + (1/6)*(k1+2*k2+2*k3+k4)
 x0 = x0 + dt
 v0 = v1
 error = ((v1-v0)/v1)
 lst.append(1)
  1. dihasilkan perhitungan untuk sumbu X

print('Kecepatan yang dihasilkan rudal pada sumbu x adalah', v1, 'm/s')


Sumbu Y :

from math import *

g = 9.81

m = eval(input("Massa rudal dalam kg: "))

sudut = eval(input("Sudut kemiringan rudal dalam derajat: "))

a = eval(input("Percepatan yang diinginkan: "))

cd = eval(input("Koefisien hambat udara: "))

alpha = sudut*0.0174

ay = a*(sin(alpha))

ax = a*(cos(alpha))

v0 = 0

x0 = 0

t0 = 0

dt = 0.1

error = 100

lst = []

def dydt(t0, v0):

 return ((ay-(g*(cd*v0**3/2)/m)))

while error > 0.005:

 k1 = dt*dydt(t0, v0)
 k2 = dt*dydt(t0+0.5*dt, v0+0.5*dt*k1)
 k3 = dt*dydt(t0+0.5*dt, v0+0.5*dt*k2)
 k4 = dt*dydt(t0+dt, v0+k3*dt)
 v1 = v0 + (1/6)*(k1+2*k2+2*k3+k4)
 x0 = x0 + dt
 v0 = v1
 error = ((v1-v0)/v1)
 lst.append(1)
  1. dihasilkan perhitungan untuk sumbu Y

print('Kecepatan yang dihasilkan rudal pada sumbu Y adalah', v1, 'm/s')