Wednesday, March 27, 2013

Eliminasi Gauss dan Implementasinya di Matlab

SOAL: 

x + 3y + 2z = 9
2x + y + 2z = 12
x + 2y + z = 6


PENYELESAIAN:
  • Merubah pers. linear menjadi sebuah bentuk matriks (biasa disebut matriks teraugmentasi)
  • Merubah matriks teraugmentasi menjadi bentuk matriks eselon-baris, sebelumnya perlu diketahui apa saja syarat matriks eselon-baris, yakni:
          1.) Di setiap baris, angka pertama selain 0 harus 1 (leading 1).
        (Contoh syarat 1)

2.) Jika ada baris yang semua elemennya nol, maka harus dikelompokkan di baris akhir dari matriks.


                                                       (Contoh syarat 2)
3.) Jika ada baris yang leading 1 maka leading 1 di bawahnya, angka 1-nya harus berada lebih kanan dari leading 1 di atasnya.


                                                 (contoh syarat 3)
4.) Jika kolom yang memiliki leading 1 angka selain 1 adalah nol maka matriks tersebut disebut Eselon-baris tereduksi


                                                             (contoh syarat 4)
setelah mengetahui syarat-syaratnya, kali ini kita operasikan matriks teraugmentasi diatas tadi agar menjadi eselon-baris
  • Mencari nilai x, y, z dari matriks penyelesaian

Percabangan dan Perulangan Pada MatLab

1. Percabangan 

A. Menggunakan if
    (if...else if...else..end)

B. Menggunakan switch
    Jika tidak ada pernyataan yang di eksekusi pada case 1-n maka di taruh pada otherwise.

contoh :

    switch nama
    case a
    "pernyataan"
    otherwise
    "pernyataan"

2. Perulangan
   
    A. (for..end)
      
Contoh :
       
        for i=1:10
        if rem(i,2)==0
        disp(i)
        end
        end;

maka akan tampil
2
4
6
8
10

    B. while
   
    (while..end)

Contoh :

    i=10
    while (i>=1)
    if rem(i,2)==1
    disp(i)
    end
    i=i+1;
    end;

maka akan tampil
9
7
5
3
1

Langkah-Langkah Membuat Program Di MATLAB.

1. Pertama-tama buka Start menu Windows, pilih All Program-MatLab.












 2. Pilih menu File - New - Blank M-File.













3. Maka Secara Otomatis MatLab akan membuka teks editor guna untuk membuat code yang akan kita buat, seperti yang dibawah ini:












4. Setelah semua telah selesai tinggal kita Save As.













5. Untuk memangil/melihat hasil kerja dari program yang kita buat tadi, kita hanya perlu mengetikan nama dari program yang kita simpan tadi lewat Command window.

Sekian Trims..

Matlab









Definition of MATLAB and Implementations

MATLAB (matrix laboratory) is a numerical computing environment and fourth-generation programming language. Developed by MathWorks, MATLAB allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages, including C, C++, Java, and Fortran.
Although MATLAB is intended primarily for numerical computing, an optional toolbox uses the MuPAD symbolic engine, allowing access to symbolic computing capabilities. An additional package, Simulink, adds graphical multi-domain simulation and Model-Based Design for dynamic and embedded systems. In 2004, MATLAB had around one million users across industry and academia. MATLAB users come from various backgrounds of engineering, science, and economics.  MATLAB is widely used in academic and research institutions as well as industrial enterprises.

History

Cleve Moler, the chairman of the computer science department at the University of New Mexico, started developing MATLAB in the late 1970s. He designed it to give his students access to LINPACK and EISPACK without them having to learn Fortran. It soon spread to other universities and found a strong audience within the applied mathematics community. Jack Little, an engineer, was exposed to it during a visit Moler made to Stanford University in 1983. Recognizing its commercial potential, he joined with Moler and Steve Bangert. They rewrote MATLAB in C and founded MathWorks in 1984 to continue its development. These rewritten libraries were known as JACKPAC.  In 2000, MATLAB was rewritten to use a newer set of libraries for matrix manipulation, LAPACK. MATLAB was first adopted by researchers and practitioners in control engineering, Little's specialty, but quickly spread to many other domains. It is now also used in education, in particular the teaching of linear algebra and numerical analysis, and is popular amongst scientists involved in image processing.

Syntax

The MATLAB application is built around the MATLAB language, and most use of MATLAB involves typing MATLAB code into the Command Window (as an interactive mathematical shell), or executing text files containing MATLAB code and functions.

Variables

Variables are defined using the assignment operator, =. MATLAB is a weakly typed programming language. It is a weakly typed language because types are implicitly converted. It is a dynamically typed language because variables can be assigned without declaring their type, except if they are to be treated as symbolic objects, and that their type can change. Values can come from constants, from computation involving values of other variables, or from the output of a function. For example:

>> x = 17
x =
 17
>> x = 'hat'
x =
hat
>> y = x + 0
y =
       104        97       116
>> x = [3*4, pi/2]
x =
   12.0000    1.5708
>> y = 3*sin(x)
y =
   -1.6097    3.0000

Vectors/matrices

As suggested by its name (a contraction of "Matrix Laboratory"), MATLAB can create and manipulate arrays of 1 (vectors), 2 (matrices), or more dimensions. In the MATLAB vernacular, a vector refers to a one dimensional (1×N or N×1) matrix, commonly referred to as an array in other programming languages. A matrix generally refers to a 2-dimensional array, i.e. an m×n array where m and n are greater than 1. Arrays with more than two dimensions are referred to as multidimensional arrays. Arrays are a fundamental type and many standard functions natively support array operations allowing work on arrays without explicit loops.

A simple array is defined using the syntax: init:increment:terminator. For instance:

>> array = 1:2:9
array =
 1 3 5 7 9

defines a variable named array (or assigns a new value to an existing variable with the name array) which is an array consisting of the values 1, 3, 5, 7, and 9. That is, the array starts at 1 (the init value), increments with each step from the previous value by 2 (the increment value), and stops once it reaches (or to avoid exceeding) 9 (the terminator value).

Tugas Pratikum Ke 2

1. TARIF SURAT KABAR

clear all
disp('TarifPemasanganIklanSuratKabar');
disp('**********************************');
disp ('(Minggu, Senin, Selasa, Rabu, KamisdanJumat, per barisRp. 33.000,-');
disp (' Sabtu, per barisRp. 40.000,-)');
disp(' ');
disp('Harike 1 = Minggu - Harike 2 = Senin - Harike 3 = Selasa');
disp('Harike 4 = Rabu - Harike 5 = Kamis - Harike 6 = Jumat - Harike 7 = Sabtu');
disp(' ');
hari = input('PasangIklan di Harike = ');
bar = input('JumlahBaris yang Akan di Buat = ');
a = bar * 33000;
b = bar * 40000;
if hari == 1 || hari == 2 || hari == 3 || hari == 4 || hari == 5 || hari == 6;
disp(['Total yang Harus di Bayar Adalah ', num2str(a)]);
elseif hari == 7
disp(['Total yang Harus di Bayar Adalah ', num2str(b)]);
end

2. TARIF PDAM

clear all
disp ('Berikutiniadalahtarifpemakaian Air PDAM Kota Surabaya');
disp ('JumlahPemakaian (m3)    Harga/m3');
disp ('Pemakaian I      (     <  50 m3) Rp.  200,-');
disp ('Pemakaian II     (    51 – 150 ) Rp.  500,-');
disp ('Pemakaian III    ( 151 – 300 )   Rp.  1.000,-');
disp ('Pemakaian I V    ( >  300 m3 )   Rp.  1.500,-');
disp(' ');
tot = input('jumlahpemakaian = ');
p1 = 50 * 200;
p2 = 100 * 500;
p3 = 150 * 1000;
p4 = (tot - 300) * 1500;
p4i = tot-300;
jum = p1 + p2 + p3 + p4;
disp (['JumlahPemakaian = ', num2str(tot), 'm3']);
disp (['Pemakaian I     (<  50 m3)         Rp.   200,-  *   50  = Rp.', num2str(p1),',-']);
disp (['Pemakaian II    (51 -  150 m3)     Rp.   500,-  *   100 = Rp.', num2str(p2),',-']);
disp (['Pemakaian III   (151 -  300 m3)    Rp.   1000,- *   150 = Rp.', num2str(p3),',-']);
disp (['Pemakaian IV    ( >  300 m3)       Rp.   1500,- *   ', num2str(p4i),' = Rp.',num2str(p4),',-']);
disp (['Biaya Total                                             = Rp.', num2str(jum), ',-']);

3. NILAI PAJAK

clear all
disp('RincianPajakPenhasilandanBesar Take Home Pay');
disp(' ');

peng = input('BesarnyaPenghasilan = ');
p1= 0.05 * 25000000;
p2= 0.10 * 25000000;
p3= 0.15 * 50000000;
p4= 0.25 * 100000000;
p5= 0.35 * (peng-200000000);
a5=(peng-200000000);
jum=p1+p2+p3+p4+p5;
bay=peng-jum;

disp('5%      x     Rp 25000000         =   Rp  1250000');
disp('10%     x     Rp 25000000         =   Rp  2500000');
disp('15%     x     Rp 50000000         =   Rp  7500000');
disp('25%     x     Rp 100000000        =   Rp  25000000');
disp(['35%    x     Rp ',num2str(a5),'  =   Rp  ',num2str(p5)]);
disp(['Total                            =   Rp  ',num2str(jum)]);
disp(['TakeHomePay = ',num2str(peng),' – ',num2str(jum),' = Rp.  ',num2str(bay)]);

4. KONVERSI NILAI

clear all
t1=input('MasukkanNilaiTugas 1 = ');
t2=input('MasukkanNilaiTugas 2 = ');
t3=input('MasukkanNilaiTugas 3 = ');
UTC=input('MasukkanNilai UTC  = ');
UAC=input('MasukkanNilai UAC = ');
rata=(t1+t2+t3)/3;
nil=((rata*0.3)+(UTC*0.3)+(UAC*0.4));

if nil > 80 && nil <= 100
disp('NilaiAndaAdalah A');
elseif nil > 70 && nil <= 80
disp('NilaiAndaAdalah AB');
elseif nil > 65 && nil <= 70
disp('NilaiAndaAdalah B');
elseif nil > 60 && nil <= 65
disp('NilaiAndaAdalah BC');
elseif nil > 55 && nil <= 60
disp('NilaiAndaAdalah C');
elseif nil > 40 && nil <= 55
disp('NilaiAndaAdalah D');
elseif nil > 0  && nil <= 40
disp('NilaiAndaAdalah E');
end


5. TARIF BIOSKOP

clear all
disp('HargaTiket di Surabaya City');
disp('- Senin – Kamis       : Rp 15.000,-');
disp('- Jumat s/d Minggu    : Rp 35.000,-');
disp('- HariLibur          : Rp 35.000,-');
disp('1 = Senin - 2 = Selasa - 3 = Rabu');
disp('4 = Kamis - 5 = Jumat - 6 = Sabtu - 7 = Minggu ');
disp('8 = HariLibur - 9 = BukanHariLibur');
hari = input('MasukkanKodeHari = ');
jum = input('JumlahTiket = ');
lib = input('ApakahHariLibur = ');
a = jum * 15000;
b = jum * 35000;
ifhari == 1 && lib ~= 8 || hari == 2 && lib ~= 8 || hari == 3 && lib ~= 8 || hari == 4 && lib ~= 8
disp(['Total yang Harus di Bayar Adalah ', num2str(a)]);
elseifhari == 1 && lib == 8 || hari == 2 && lib == 8 || hari == 3 && lib == 8 || hari == 4 && lib == 8
disp(['Total yang Harus di Bayar Adalah ', num2str(b)]);
elseifhari == 5 ||  hari == 6 || hari == 7
% disp(['Total yang Harus di Bayar Adalah ', num2str(b)]);