04 Integrasi Numerik
04 Integrasi Numerik
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
• 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
ba n 1 n2
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
(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.