Anda di halaman 1dari 6

Matlab

Matlab is a tool for doing numerical computations with matrices and


vectors. Matlab adalah alat untuk melakukan perhitungan numerik dengan matriks
dan vektor. It can also display information graphically. Hal ini juga dapat
menampilkan informasi secara grafis. The best way to learn what Matlab
can do is to work through some examples at the computer . Cara
terbaik untuk mempelajari apa Matlab dapat lakukan adalah untuk bekerja melalui
beberapa contoh di komputer. After reading the " getting started " section,
you can use the tutorial below for this. Setelah membaca " memulai
"bagian, Anda dapat menggunakan tutorial di bawah ini untuk ini.
Getting started Memulai
Tutorial Tutorial
o Matrices Matriks
o Vectors Vektor
o Systems of equations Sistem persamaan
o Loops: a bit of programming Loop: sedikit pemrograman
o Graphing Graphing
Functions of one variable Fungsi-fungsi satu variabel
Functions of two variables Fungsi dua variabel
Getting started Memulai
Here is a sample session with Matlab. Berikut adalah sesi sampel dengan
Matlab. Text in bold is what you type, ordinary text is what the
computer "types." Teks dalam huruf tebal adalah apa yang Anda ketik, teks biasa
adalah apa yang komputer "jenis." You should read this example, then
imitate it at the computer. Anda harus membaca contoh ini, kemudian
menirunya di depan komputer.
% matlab % Matlab
>> a = [ 1 2; 2 1 ] >> A = [1 2; 2 1]
a==a
1212
2121
>> a*a > A> a *
ans = ans =
5454
4545
>> quit >> Quit
16 flops. 16 jepit.
%%
In this example you started Matlab by (you guessed it) typing
matlab . Dalam contoh ini Anda mulai Matlab oleh (coba tebak) mengetik matlab.
Then you defined matrix a and computed its square ("a times a").
Kemudian Anda mendefinisikan matriks dan dihitung persegi nya ("satu kali").

Finally (having done enough work for one day) you quit Matlab.
Akhirnya (setelah dilakukan cukup banyak pekerjaan untuk satu hari) Anda berhenti
Matlab.
The tutorial below gives more examples of how to use Matlab.
Tutorial di bawah ini memberikan lebih banyak contoh bagaimana menggunakan
Matlab. For best results, work them out using a computer: learn by
doing! Untuk hasil terbaik, bekerja mereka dengan menggunakan komputer: belajar
dengan melakukan!
Matlab Tutorial Tutorial Matlab
Matrices Matriks
To enter the matrix Untuk memasukkan matriks
1212
3434
and store it in a variable a, do this: dan menyimpannya dalam suatu variabel,
lakukan ini:
>> a = [ 1 2; 3 4 ] >> A = [1 2; 3 4]
Do this now: define the matrix a. Lakukan sekarang: mendefinisikan
a. matriks Do the same with the examples below: work out
each of them with matlab. Lakukan hal yang sama dengan contoh di
bawah ini: bekerja di luar masing-masing dengan matlab. Learn by doing!
Belajar dengan melakukan!
To redisplay the matrix, just type its name: Untuk menampilkan kembali
matriks, cukup ketik namanya:
>> a > A>
Once you know how to enter and display matrices, it is easy to
compute with them. Setelah Anda tahu bagaimana untuk memasukkan dan
menampilkan matriks, mudah untuk menghitung dengan mereka. First we will
square the matrix a : Pertama kita akan alun-alun matriks:
>> a * a > A> a *
Wasn't that easy? Bukankah itu mudah? Now we'll try something a little
harder. Sekarang kita akan mencoba sesuatu yang sedikit lebih keras. First we
define a matrix b: Pertama kita mendefinisikan matriks b:
>> b = [ 1 2; 0 1 ] >> B = [1 2; 0 1]
Then we compute the product ab: Kemudian kita menghitung produk ab:
>> a*b >> A * b
Finally, we compute the product in the other order: Akhirnya, kita
menghitung produk dalam urutan lain:
>> b*a >> B * a
Notice that the two products are different: matrix multiplication is
noncommmutative. Perhatikan bahwa dua produk yang berbeda: perkalian
matriks adalah noncommmutative.
Of course, we can also add matrices: Tentu saja, kita juga dapat
menambahkan matriks:
>> a + b >> A + b
Now let's store the result of this addition so that we can use it later:
Sekarang mari kita menyimpan hasil dari penambahan ini sehingga kita dapat
menggunakannya nanti:
>> s = a + b >> S = a + b
Matrices can sometimes be inverted: Matriks kadang bisa terbalik:
>> inv(s) > Inv> (s)

To check that this is correct, we compute the product of s and its


inverse: Untuk memastikan bahwa ini benar, kita menghitung produk dan invers:
>> s * inv(s) >> S * inv (s)
The result is the unit, or identity matrix. Hasilnya adalah unit, atau matriks
identitas. We can also write the computation as Kita juga dapat menulis
perhitungan sebagai
>> s/s >> S / s
We can also write Kita juga dapat menulis
>> s\s >> S \ s
which is the same as yang sama seperti
>> inv(s) * s >> Inv (s) * s
To see that these operations, left and right division, are really
different, we do the following: Untuk melihat bahwa operasi ini, pembagian
kiri dan kanan, benar-benar berbeda, kita lakukan hal berikut:
>> a/b >> A / b
>> a\b >> A \ b
Not all matrices can be inverted, or used as the denominator in
matrix division: Tidak semua matriks dapat terbalik, atau digunakan sebagai
penyebut dalam divisi matriks:
>> c = [ 1 1; 1 1 ] >> C = [1 1; 1 1]
>> inv(c); >> Inv (c);
A matrix can be inverted if and only if its determinant is nonzero:
Matriks A dapat dibalik jika dan hanya jika determinannya adalah nol:
>> det(a) >> Det (a)
>> det(c) >> Det (c)
Vectors Vektor
Systems of equations Sistem persamaan
Now consider a linear equation Sekarang perhatikan persamaan linier
ax + by = p ax + by = p
cx + dy = q cx + dy = q
We can write this more compactly as Kita bisa menulis ini lebih kompak sebagai
AX = B AX = B
where the coefficient matrix A is di mana matriks koefisien A adalah
ab ab
cd CD
the vector of unknowns is vektor tidak diketahui adalah
xx
yy
and the vector on the right-hand side is dan vektor pada sisi kanan adalah
pp
qq
If A is invertible, X = (1/A)B, or, using Matlab notation, X = A\B. Jika A dapat
dibalik, X = (1 / A) B, atau, menggunakan Matlab notasi, X = A \ B. Lets try this out
by solving ax = b with a as before and b = [ 1; 0 ]. Mari kita mencoba hal ini dengan
memecahkan ax = b dengan seperti sebelumnya dan b = [1; 0]. Note that b is a
column vector. Perhatikan bahwa b adalah vektor kolom.
>> b = [ 1; 0 ] >> B = [1; 0]
>> a\b >> A \ b
Loops Loops

Finally, we will do a little piece of programming. Akhirnya, kita akan melakukan


sepotong kecil pemrograman. Let a be the matrix Misalkan a adalah matriks
0.8 0.1 0.8 0.1
0.2 0.9 0.2 0.9
and let x be the column vector dan misalkan x adalah vektor kolom
11
00
We regard x as representing (for example) the population state of an island. Kami
menganggap x sebagai mewakili (misalnya) negara penduduk pulau. The first entry
(1) gives the fraction of the population in the west half of the island, the second entry
(0) give the fraction in the east half. Entri pertama (1) memberikan sebagian kecil dari
penduduk di paruh barat pulau, entri kedua (0) memberikan fraksi di paruh timur. The
state of the population T units of time later is given by the rule y = ax. Keadaan unit
populasi T waktu kemudian diberikan oleh aturan y = ax. This expresses the fact that
an individual in the west half stays put with probability 0.8 and moves east with
probability 0.2 (note 0.8 + 0.2 = 1), and the fact that in individual in the east stays put
with probability 0.9 and moves west with probability 0.1. Hal ini mengungkapkan
fakta bahwa seorang individu pada paruh barat tetap menempatkan dengan
probabilitas 0,8 dan bergerak ke timur dengan probabilitas 0,2 (0,8 + 0,2 Catatan = 1),
dan fakta bahwa dalam individu di timur tetap menempatkan dengan probabilitas 0,9
dan bergerak ke barat dengan probabilitas 0,1. Thus, successive population states can
be predicted/computed by repeated matrix multiplication. Dengan demikian, populasi
negara berturut-turut dapat diprediksi / dihitung dengan perkalian matriks berulang.
This can be done by the following Matlab program: Hal ini dapat dilakukan oleh
program Matlab berikut:
>> a = [ 0.8 0.1; 0.2 0.9 ] >> A = [0,8 0,1; 0,2 0,9]
>> x = [ 1; 0 ] >> X = [1; 0]
>> for i = 1:20, x = a*x, end >> Untuk i = 1:20, x = a * x, akhir
What do you notice? Apa yang Anda perhatikan? Is there an explanation? Apakah ada
penjelasan? Is there a lesson to be learned? Apakah ada pelajaran yang harus
dipelajari?
Remark: you have just learned to write a kind of loop, a so-called for loop . Catatan:
Anda baru saja belajar menulis semacam lingkaran, yang disebut untuk loop. This is
an easy way to command the machine, in just a few words, to do much repetitive
work. Ini adalah cara mudah untuk perintah mesin, hanya dalam beberapa kata, untuk
melakukan pekerjaan berulang-ulang banyak.
Graphing Graphing
Functions of one variable Fungsi-fungsi satu variabel
To make a graph of y = sin(t) on the interval t = 0 to t = 10 we do the following:
Untuk membuat grafik y = sin (t) pada interval t = 0 sampai t = 10 kita lakukan hal
berikut:
>> t = 0:.3:10; >> T = 0: .3:10;
>> y = sin(t); >> Y = sin (t);
>> plot(t,y) >> Plot (t, y)

Here

is

the

result:

Berikut

adalah

hasilnya:

The command t = 0:.3:10; defines a vector with components ranging from 0 to 10 in


steps of 0.3. T perintah = 0: .3:10; mendefinisikan sebuah vektor dengan komponen
mulai dari 0 sampai 10 dalam langkah 0,3. The y = sin(t); defines a vector whose
components are sin(0), sin(0.3), sin(0.6), etc. Finally, plot(t,y) use the vector of t and y
values to construct the graph. Y = sin (t); mendefinisikan sebuah vektor yang
komponen dosa (0), dosa (0,3), dosa (0,6), dll Akhirnya, plot (t, y) menggunakan
vektor t dan nilai-nilai y untuk membangun grafik.
Functions of two variables Fungsi dua variabel
Here is how we graph the fuction z(x,y) = x exp( - x^2 - y^2): Berikut adalah
bagaimana kita grafik fuction z (x, y) = x exp (- x ^ 2 - y ^ 2):
>> [x,y] = meshgrid(-2:.2:2, -2:.2:2); >> [X, y] = meshgrid (-2: .2:2, -2: .2:2);
>> z = x .* exp(-x.^2 - y.^2); >> Z = x .* exp (-x ^ 2 - y ^ 2.);
>> surf(x,y,z) >> Surfing (x, y, z)

The first command creates a matrix whose entries are the points of a grid in the square
-2 <= x <= 2, -2 <= y <= 2. Perintah pertama menciptakan suatu matriks yang entrientrinya adalah poin dari sebuah grid dalam persegi -2 <= x <= 2, -2 <= y <= 2. The
small squares which make up the grid are 0.2 units wide and 0.2 unit tall. Kotak kecil
yang membentuk grid yang 0,2 dan 0,2 unit satuan luas tinggi. The second command
creates a matrix whose entries are the values of the function z(x,y) at the grid points.
Perintah kedua menciptakan suatu matriks yang entri-entrinya adalah nilai-nilai fungsi
z (x, y) pada titik-titik grid. The third command uses this information to construct the
graph. Perintah ketiga menggunakan informasi ini untuk membangun grafik.
Back to Department of Mathematics, University of Utah Kembali ke Departemen
Matematika, Universitas Utah

Anda mungkin juga menyukai