0% found this document useful (0 votes)
28 views19 pages

04 Integrasi Numerik

Berikut adalah langkah-langkah penyelesaiannya: 1. Buat fungsi untuk menghitung kecepatan roket sebagai fungsi waktu seperti di Contoh 1 2. Buat looping untuk menghitung jarak yang ditempuh dari waktu awal sampai waktu akhir menggunakan metode Simpson 1/3 3. Bandingkan hasil perhitungan jarak dengan 100.000 m. Jika lebih besar, ubah waktu akhir. Ulangi looping sampai ditemuk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views19 pages

04 Integrasi Numerik

Berikut adalah langkah-langkah penyelesaiannya: 1. Buat fungsi untuk menghitung kecepatan roket sebagai fungsi waktu seperti di Contoh 1 2. Buat looping untuk menghitung jarak yang ditempuh dari waktu awal sampai waktu akhir menggunakan metode Simpson 1/3 3. Bandingkan hasil perhitungan jarak dengan 100.000 m. Jika lebih besar, ubah waktu akhir. Ulangi looping sampai ditemuk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Integrasi

Numerik
Praktikum Komputasi
Minggu IV
Semester I – Tahun Ajaran 2020/2021
Tujuan pembelajaran
• Mampu mengaplikasikan integrasi numerik dengan metode Simpson
1/3 dalam pemrograman Python.
FUNCTION
def / return
Function
• Functions are used to create code that can be used in a program or in
other programs.
• The use of functions to logically separate the program into discrete
computational steps.
• Programs that make heavy use of function definitions tend to be easier
to develop, debug, maintain, and understand.
Python functions

• The return value can be any Python type


• If the return statement is omitted a special None value is still
returned.
• The arguments are optional but the parentheses are required!
• Functions must be defined before they can be called.
Function Return Values
• A function can return any Python value.
• Function call syntax:

A = some_func() # return a value


Another_func() # ignore return value (nothing returned)
b,c = multiple_vals(x,y,z) # return multiple values
Function arguments
• Function arguments can be required or optional.
• Optional arguments are given a default value
• To call a function with optional arguments:
def my_func(a,b,c=10,d=-1):
…some code…

• Optional arguments can be used in the order they’re declared or out of order if
their name is used.
my_func(x,y,z) # a=x, b=y, c=z, d=-1
my_func(x,y) # a=x, b=y, c=10, d=-1
my_func(x,y,d=w,c=z) # a=x, b=y, c=z, d=w
Return multiple values from a function
• Tuples are more useful
than they might seem at
first glance.
• They can be easily used
to return multiple
values from a function.
• Python syntax can
automatically unpack a
tuple return value.
Integrasi Numerik
Metode Simpson 1/3
Integrasi Simpson 1/3
• Persamaan umum integrasi Simpson 1/3
• Jumlah segmen perhitungan harus genap (jumlah titiknya
ganjil)

b  
ba  n 1 n2

 f ( x)dx  f ( x0 )  4  f ( xi )  2  f ( xi )  f ( xn )
3n  i 1 i 2

a
 i  odd i  even 
Contoh 1
• Kecepatan v (m/det) sebuah roket sebagai fungsi waktu t (detik), dapat
ditunjukkan dengan persamaan:

• Jarak vertical yang ditempuh sebuat roket antara 8 sampai 30 detik dapat dihitung
dengan persamaan:
Coding Python (1/5)
# -*- coding: utf-8 -*-
"""
04 Integrasi Numerik
Contoh 04Intgrl-01
"""
import numpy as np
import matplotlib.pyplot as plt

def fungsi(ti):
vi = 2000*np.log(140000/(140000-2100*ti))-9.8*ti
return vi
Coding Python (2/5)
# Prosedur metode Simpson 1/3
# Data
ta, tb = 8, 30
n = 88 # jumlah segmen (harus genap)
dt = (tb-ta)/n

# Membuat array t dan v


t = np.linspace(ta,tb,n+1)
v = np.zeros(n+1)
vsim = np.zeros(n+1) # dummy variabel utk integrasi
Coding Python (3/5)
for i in range(n+1):
v[i] = fungsi(t[i])
if i == 0:
vsim[i] = v[i]
elif i == n:
vsim[i] = v[i]
elif (-1)**i < 0: # ganjil
vsim[i] = 4*v[i]
else:
vsim[i] = 2*v[i]
Coding Python (4/5)
# Menghitung x
x = sum(vsim)*dt/3

# Menampilkan grafik v vs. t


plt.plot(t,v,'.r')
plt.title('Kecepatan roket dari 8-30 det')
plt.xlabel('Waktu, det')
plt.ylabel('Kecepatan, m/det')
# Menampilkan hasil perhitungan
Coding header = ['Waktu, det', 'Kecepatan, m/det']
Python tabel = np.zeros([n+1,2]) # membuat array utk tabel

(5/5) tabel[:,0]= t
tabel[:,1] = v
print('Hasil perhitungan contoh 04.01')
print('-'*30)
print('_'*35)
print('{:^15s} {:^17s}'.format(*header))
print('_'*35)
# cetak data tiap kelipatan 4
for baris in tabel[0:-1:4,:]:
print('{:^15.2f} {:^15.2f}'.format(*baris))
print('_'*35)
print('Jarak yang ditempuh roket {:.2f}'.format(x))
Hasil
Hasil perhitungan contoh 04.01 18.00 453.02
------------------------------ 19.00 484.75
___________________________________ 20.00 517.35
Waktu, det Kecepatan, m/det 21.00 550.87
___________________________________ 22.00 585.36
8.00 177.27 23.00 620.84
9.00 201.85 24.00 657.37
10.00 227.04 25.00 695.01
11.00 252.85 26.00 733.79
12.00 279.30 27.00 773.79
13.00 306.43 28.00 815.05
14.00 334.24 29.00 857.66
15.00 362.78 ___________________________________
16.00 392.07 Jarak yang ditempuh roket 11061.34 m
17.00 422.14
Contoh 2
• Dengan data di Contoh 1, hitunglah waktu yang ditempuh oleh roket
untuk mencapak jarak 100.000 m.

You might also like