asistensi permodasdsa

31
ASISTENSI PERMODELAN TK: TUTORIAL MATLAB

Upload: aba-shiddiq

Post on 14-Nov-2015

244 views

Category:

Documents


2 download

DESCRIPTION

asd

TRANSCRIPT

Slide 1

ASISTENSI PERMODELAN TK: TUTORIAL MATLAB

MATLABMATLAB = MATRIX LABORATORYBekerja dgn basis matriksCase-sensitiveKeunggulan:User Friendly (GUI)Mudah dipakai programming tingkat tinggiDapat menyelesaikan problem matematik kompleksDapat mem-plot grafik 2D dan 3DDapat import data dari excelAda demo dan tutorial yang dapat dipelajari sendiriGunakan help command

OUTLINEInput Variabel (Matriks)Operasi MatriksPerintah dasarPlot grafikFlow control:If..elseForWhileDoFungsi:Eliminasi GaussMencari akar: fzero & rootsSPANL: solvePersamaan Diferensial Biasa (PDB): ode45

COMMAND WINDOW:Menuliskan perintah2/program utama Memasukkan data Mengeksekusi program dan keluar hasilEDITOR:Function/subroutinesWORKSPACE:Variabel2 yg sudah diinput1. INPUT VARIABELa vectorx = [1 2 5 1]x = 1 2 5 1

a matrixx = [1 2 3; 5 1 4; 3 2 -1]

x = 1 2 3 5 1 4 3 2 -1

transposey = x y = 12 51

t =1:7t = 1234567k =2:-0.5:0 k = 21.5 1 0.5 0

B = [1:4; 5:8]

x = 1 2 3 4 5 6 7 8

1. INPUT VARIABELInformasi TambahanAgar hasil tdk tampil setelah mengetikkan perintah pada akhir baris tambahkan tanda(;)Cth: A=[1 2 3];Pemisah antar kolom matriks : spasi ( ) atau koma (,)Pemisah antar baris matriks: titik koma (;)Matriks khususx = zeros(1,3)x =0 0 0

x = ones(1,3)x =1 1 1

x = eye(3)x =100010001zeros (M,N) = Matriks 0 orde MxN

ones (M,N) = Matriks 1 orde MxN

eye (n) = Matriks identitas nxn

Matriks khususx = linspace(1,10,5)x =1 3.25 5.5 7.75 10linspace (a,b,n) = Vektor ruang linier dari a sampai b dengan jumlah titik/elemen sebanyak n(mengikuti barisaritmatika)2. OPERASI MATRIKSSimbol/perintahJenis operasi+Penjumlahan-Pengurangan*Perkalian/Pembagian^PangkatTranspose.*Perkalian elemen2./Pembagian elemen2.^Pangkat elemen2inv(A)Invers dari matriks A2. OPERASI MATRIKS ARRAY INDEXINGA = 1 2 3 4 5 6 7 8 9PerintahHasilA(1,3)3A(2,:)4 5 6A(:,3)369A(2,1:2)5A(1:2,1:2)25A(8)6LATIHANCari Penyelesaian SPAL:

x + 2y z = 104y 2z = 153x + 2y + z = 83. PERINTAH-PERINTAH DASARPerintahKeteranganclcMenghapus semua command pada command windowclearMenghapus semua variabel pada workspacewhosMenampilkan variabel yg sudah tersimpan di workspace pada command windowsaveMenyimpan variabel (workspace)4. FLOW CONTROLif for while do 14Operators (relational, logical)== Equal to~= Not equal to< Strictly smaller> Strictly greater= Greater than equal to& And operator | Or operator

15Control Structures If Statement Syntax

if (Condition_1)Matlab Commandselseif (Condition_2)Matlab Commandselseif (Condition_3)Matlab CommandselseMatlab Commandsend

Some Dummy Examples

if ((a>3) & (b==5)) Some Matlab Commands;end

if (a>x=linspace(0,4*pi,100);>>y=sin(x);>>y1=exp(-x/3);>>y2=y.*y1;215. PLOT GRAFIKPlot y vs x

>>plot(x,y2)6. FUNGSI-FUNGSIFzero mencari akar fungsiRoots mencari akar polinomialFsolve solusi SPANLOde45 solusi PDB6. FUNGSI-FUNGSIMencari akar fungsiNon-linier: fzeroSyntax: fzero(function,x0)x0 = tebakan awalPolynomial: rootsSyntax: roots([matriks koefisien])Mencari akar - ContohSOAL:f(x)=x32x5

Solution #1>>fun=@(x) (x^3-2*x-5);>>xroot=fzero(fun,0)Result:xroot = 2.0946Solution #2>>roots([1 0 -2 -5])Result: ans = 2.0946 + 0.0000i -1.0473 + 1.1359i -1.0473 - 1.1359i

LATIHANF(x) = x5 + 3x4 -5x2 +4x +126. Fungsi-fungsiSPANL fsolvesyntax: fsolve(fun,x0)

PDB/ODE ode45

SPANL contoh soal

Solusi-Functionfunction F = myfun(x)F = [2*x(1) - x(2) - exp(-x(1)); -x(1) + 2*x(2) - exp(-x(2))];end

x0 = [-5; -5]; options = optimoptions('fsolve','Display','iter'); [x,fval] = fsolve(@myfun,x0,options) % Call solverRESULT Norm of First-order Trust-region Iteration Func-count f(x) step optimality radius 0 3 47071.2 2.29e+04 1 1 6 12003.4 1 5.75e+03 1 2 9 3147.02 1 1.47e+03 1 3 12 854.452 1 388 1 4 15 239.527 1 107 1 5 18 67.0412 1 30.8 1 6 21 16.7042 1 9.05 1 7 24 2.42788 1 2.26 1 8 27 0.032658 0.759511 0.206 2.5 9 30 7.03149e-06 0.111927 0.00294 2.5 10 33 3.29525e-13 0.00169132 6.36e-07 2.5