Beruflich Dokumente
Kultur Dokumente
Pemrograman 2010
Joko Wintoko
Lab TMBGB JTK FT UGM
jwintoko@chemeng.ugm.ac.id
0813 2852 7309
Isi Kuliah
Penggunaan MATLAb dalam penyelesaian
persoalan-persoalan teknik kimia.
Metode yang dipakai:
Sistem penilaian
Tugas : 30%
USIP : 30%
UAS : 40%
Introduction to MATLAB
M-files
Basic operations and commands
Scalar, vectors, matrices
INPUT
OUTPUT
M-files
MATLAB provides a full programming
language that enables you to write a
series of MATLAB statements into a file
and then execute them with a single
command.
Types of M-Files:
Matlab scripts
Matlab functions
Types of M-Files
MATLAB scripts:
Are useful for automating a series of steps you need to perform
many times.
Do not accept input arguments or return output arguments.
Store variables in a workspace that is shared with other scripts
and with the MATLAB command line interface.
MATLAB functions:
Are useful for extending the MATLAB language for your
application.
Can accept input arguments and return output arguments.
Store variables in a workspace internal to the function.
Numerical variables
Scalar:
Vectors:
a = 5;
b=5
a1
a
2
a=
...
an
Numerical variables
Matrices
a = [a11 a12 ... a1n; a21 a22 ... a2n; ... ;
am1 am2 ... amn]
a11 a12
a 21 a 22
a=
...
...
am1 am2
... a1n
... a 2n
... ...
... amn
Arithmetic operators: +, - , * , / , \
= pi = 3.1416
sqrt(x) = x
x^2
Trigonometric functions (sin, cos, tan, cot, ...).
All results in radian.
Default: hasil hitungan ditampilkan hanya 4
digit desimal. Untuk tampilan lebih panjang
pergunakan perintah format
>> c=exp(pi)
c=
23.1407
>> format long,c
c=
23.14069263277927
>> format long e,c
c=
2.314069263277927e+001
>> format short,c
c=
23.1407
>> format short e,c
c=
2.3141e+001
INPUT DATA
From keyboard
From M-file
From other program (MS Excel)
Cara 2
Buat m file dengan nama dataku.m, yang berisi:
a = 3;
b = 4;
Dalam m file baru atau di command prompt tuliskan:
dataku
c = sqrt(a^2+b^2)
Kalimat
Memakai fungsi disp:
>> a=3;
>> disp(['Hasil perhitungan adalah = ', num2str(a)])
Hasil perhitungan adalah = 3
>> disp(['Hasil perhitungan adalah = ', num2str(a) , ' m2/s'])
Hasil perhitungan adalah = 3 m2/s
Memakai fungsi fprintf:
>> b=sqrt(2);
>> fprintf('Hasil perhitungan adalah = %0.2f m2/s',b)
ans =
Hasil perhitungan adalah = 1.41 m2/s
Tabel
Memakai fungsi disp:
>> disp('
Corn
0.9501
0.2311
0.6068
0.4860
0.8913
Corn
Oats
0.7621
0.4565
0.0185
0.8214
0.4447
Oats
Hay
0.6154
0.7919
0.9218
0.7382
0.1763
Hay'); disp(rand(5,3))
Tabel
Memakai fungsi fprintf:
>>a=(rand(5,3));
fprintf('Corn \t Oats \t Hay \n')
fprintf('%2.2f \t %2.2f \t %2.2f \n',a)
Corn
0.06
0.72
0.45
0.15
0.73
Oats
0.37
0.69
0.44
0.68
0.48
Hay
0.63
0.08
0.35
0.70
0.55
Grafik
Line graph
Bar graph
Area graph
Direction graph
Radial graph
Scatter graph
Grafik
Lihat & praktekkan contoh pembuatan
grafik di MATLAB dari An Introduction to
Matlab by Griffiths