Dosen:
Novriana Sumarti,Ph.D.
Dr. Rinovia G. Simanjuntak
Prof. Dr. M. Wono Setya Budi
1
Fungsi Transenden
Bagian I: Pengenalan Pemrograman
dengan Matlab
1. Function
2. Flow control
3. Plot garis
4. Plot permukaan
5. Vektorisasi
2
Fungsi Transenden
Function sama seperti Script tapi ada satu perbedaan:
function harus memuat deklarasi fungsi.
3
function [x, y, z] = funName( inp1, inp2)
x, y, z : 3 variabel output
funName : nama function yang akan dipanggil di Script
Inp1, inp2 : 2 variabel input
4
Operator
5
Fungsi Transenden
if /else/elseif
6
7
Command akan dilaksanakan bila syarat cond terpenuhi.
HATI-HATI : command harus suatu saat tidak terpenuhi
agar loop dapat berhenti (tak berhingga loop).
8
Plotting
Contoh
>> x = linspace( 0, 4*pi, 10);
>> y = sin (x);
Menggambar nilai y terhadap indeks
>> plot(y);
Menggambar nilai y terhadap x
>> plot( x, y)
9
Plotting
Contoh
>> x = linspace( 0, 4*pi, 10);
>> y = sin (x);
Menggambar nilai y terhadap indeks
>> plot(y);
Menggambar nilai y terhadap x
>> plot( x, y)
10
Pilihan menu untuk plotting:
>> plot (x, y, ‘k.-’);
k : warna hitam, . (titik) : marker nilai fungsi, - : line-style
Contoh:
>> x = 0 : pi/10: 2*pi;
>> y1 = sin(x);
>> y2 = sin(x - 0.25);
>> y3 = sin(x – 0.5);
Figure
plot (x, y1, ‘g’, x, y2, ‘bo-’, x, y3, ‘c*-’);
11
Menganalisis Plot
12
13
14
Copy/Paste Gambar
Gambar hasil program MATLAB dapat dimasukkan ke
aplikasi lain seperti word, ppt, dll.
Edit → copy options → figure copy template
Dapat mengubah ukuran font, line properties
15
Cara: Edit → copy figure
Lalu paste ke aplikasi yang dikehendaki.
Format gambar:
.fig mengawetkan semua
informasi
.bmp uncompressed
image
.eps high-quality
scaleable format
.pdf compressed image
16
Menggambar Permukaan
Membuat vector x dan y
>> x = -pi : 0.1 : pi;
>> y = -pi : 0.1 : pi;
Menggambar permukaan
>> surf(X, Y, Z)
>> surf(x, y, Z)
17
Apa bedanya?
18
19
Find
Fungsi penting menghasilkan indeks dari vector yang bernilai
tak nol, sehingga menyederhanakan program menghindari
loops.
Index = find( cond )
>> x = rand(1, 100);
>> inds = find( x > 0.4 & x < 0.6);
21
Kode lebih efisien
22