Free Essay

Matlab

In:

Submitted By stevenboo
Words 2781
Pages 12
Bab 1
Memulai Menggunakan Matlab
Matlab merupakan bahasa canggih untuk komputansi teknik. Matlab merupakan integrasi dari komputansi, visualisasi dan pemograman dalam suatu lingkungan yang mudah digunakan, karena permasalahan dan pemecahannya dinyatakan dalam notasi matematika biasa. Kegunaan Matlab secara umum adalah untuk :






Matematika dan Komputansi
Pengembangan dan Algoritma
Pemodelan,simulasi dan pembuatan prototype
Analisa Data,eksplorasi dan visualisasi
Pembuatan apilikasi termasuk pembuatan graphical user interface

Matlab adalah sistem interaktif dengan elemen dasar array yang merupakan basis datanya. Array tersebut tidak perlu dinyatakan khusus seperti di bahasa pemograman yang ada sekarang. Hal ini memungkinkan anda untuk memecahkan banyak masalah perhitungan teknik, khususnya yang melibatkan matriks dan vektor dengan waktu yang lebih singkat dari waktu yang dibutuhkan untuk menulis program dalam bahasa C atau
Fortran. Untuk memahami matlab, terlebih dahulu anda harus sudah paham mengenai matematika terutama operasi vektor dan matriks, karena operasi matriks merupakan inti utama dari matlab. Pada intinya matlab merupakan sekumpulan fungsi-fungsi yang dapat dipanggil dan dieksekusi. Fungsi-fungsi tersebut dibagi-bagi berdasarkan kegunaannya

Kuliah Berseri IlmuKomputer.Com
Copyright © 2004 IlmuKomputer.Com

yang dikelompokan didalam toolbox yang ada pada matlab. Untuk mengetahui lebih jauh mengenai toolbox yang ada di matlab dan fungsinya anda dapat mencarinya di website http://www.mathworks.com, atau anda dapat membuka cd dokumentasi matlab.

I.1. Desktop Matlab
Ketika anda mulai membuka program Matlab, akan muncul desktop Matlab yang berisi tools ( Graphical user interface ) untuk mengatur file, variabel dan aplikasi yang berhubungan dengan Matlab.
Sebagai ilustrasi dibawah ini digambarkan desktop yang pertama muncul di Matlab 6.5.

Gambar 1. Desktop Matlab versi 6.5.

Kuliah Berseri IlmuKomputer.Com
Copyright © 2004 IlmuKomputer.Com

Desktop Tools

Pada bagian ini diperkenalkan beberapa desktop tools yang ada pada Matlab

Command Window
Gunakan command window untuk memasukan variabel dan menjalankan function atau M-files. Setiap perintah yang ditulis di command window langsung ditampilkan. Bila perintah anda salah akan keluar pesan error. Sebagai ilustrasi dapat dilihat pada gambar 2 dibawah ini, disini dieksekusi perintah magic(4) yang artinya kita membuat “matriks ajaib” ukuran 4 x 4. Prinsip dasar untuk memulai menggunakan Matlab, anda anggap Matlab adalah sebuah kalkulator. Untuk itu coba dengan mengerjakan operasi matematika sederhana layaknya sebuah kalkulator di command window.

Gambar 2. Command window.

Kuliah Berseri IlmuKomputer.Com
Copyright © 2004 IlmuKomputer.Com

Command History
Statemen yang anda buat di command window tersimpan semuanya di command history. Di command history anda dapat melihat statemen yang lalu dan mengkopi lalu mengeksekusi statemen yang dipilih.

Gambar 3. Command History.

Tombol Start dan Launch Pad
Tombol start memudahkan akses ke tools,demo dan dokumentasi ,anda hanya tinggal mengklik tombol untuk melihat pilihannya.

Gambar 4. Launch pad menggambarkan beberapa akses dengan tree view.

Kuliah Berseri IlmuKomputer.Com
Copyright © 2004 IlmuKomputer.Com

Teks Editor
Gunakan teks editor untuk membuat dan menjalankan M-files.

Gambar 5. Text Editor.

I.2. Ruang Kerja Matlab
Saat anda bekerja di command window semua perintah, variable dan data yang disimpan berada di dalam ruang kerja Matlab. Ruang kerja “default” dari Matlab yaitu di folder work di dalam folder Matlab. Apabila kita menginstal Matlab versi 6.1 di C maka folder work akan berada di C:/Matlab6p1/work. Untuk merubah ruang kerja lakukan di
Command Window, seperti anda merubah direktori di DOS.
Coba anda ketik tes=2 pada command window, maka akan keluar output sebagai berikut : tes =
2

Ini berarti variable tes telah tersimpan di dalam ruang kerja kita.
Untuk melihat data yang telah tersimpan coba anda ketik tes pada commands window. tes =
2

Kuliah Berseri IlmuKomputer.Com
Copyright © 2004 IlmuKomputer.Com

Jika anda tidak dapat mengingat nama setiap variable, maka anda dapat meminta Matlab untuk menampilkan namanya, menggunakan perintah who atau whos. whos Name

Size

tes tes2 Bytes

1x1
1x1

8
8

Class double array double array

Grand total is 2 elements using 16 bytes

Untuk mengetahui isi variabel tersebut anda harus memasukkan nama variabelnya dalam command window.
Untuk memanggil perintah sebelumnya, di Matlab menggunakan tombol panah pada keyboard anda ( ←↑↓→ ) .
Untuk menghapus semua semua variabel yang sudah kita masukkan digunakan perintah clear all
Untuk melihat keterangan dari function di Matlab atau program yang kita buat digunakan perintah : ' help function ' , sebagai contoh : help plot
PLOT
Linear plot.
PLOT(X,Y) plots vector Y versus vector X. If X or Y is a matrix, then the vector is plotted versus the rows or columns of the matrix, whichever line up. If X is a scalar and Y is a vector, length(Y) disconnected points are plotted.
PLOT(Y) plots the columns of Y versus their index.
If Y is complex, PLOT(Y) is equivalent to PLOT(real(Y),imag(Y)).
In all other uses of PLOT, the imaginary part is ignored.
Various line types, plot symbols and colors may be obtained with
PLOT(X,Y,S) where S is a character string made from one element from any or all the following 3 columns: b g r c m y k blue green red cyan magenta yellow black

. o x
+
* s d v ^
<
> p point circle x-mark plus star square diamond triangle (down) triangle (up) triangle (left) triangle (right) pentagram :
-.
--

solid dotted dashdot dashed Kuliah Berseri IlmuKomputer.Com
Copyright © 2004 IlmuKomputer.Com

h

hexagram

For example, PLOT(X,Y,'c+:') plots a cyan dotted line with a plus at each data point; PLOT(X,Y,'bd') plots blue diamond at each data point but does not draw any line.
PLOT(X1,Y1,S1,X2,Y2,S2,X3,Y3,S3,...) combines the plots defined by the (X,Y,S) triples, where the X's and Y's are vectors or matrices and the S's are strings.
For example, PLOT(X,Y,'y-',X,Y,'go') plots the data twice, with a solid yellow line interpolating green circles at the data points.
The PLOT command, if no color is specified, makes automatic use of the colors specified by the axes ColorOrder property. The default
ColorOrder is listed in the table above for color systems where the default is blue for one line, and for multiple lines, to cycle through the first six colors in the table. For monochrome systems,
PLOT cycles over the axes LineStyleOrder property.
PLOT returns a column vector of handles to LINE objects, one handle per line.
The X,Y pairs, or X,Y,S triples, can be followed by parameter/value pairs to specify additional properties of the lines.
See also SEMILOGX, SEMILOGY, LOGLOG, PLOTYY, GRID, CLF, CLC, TITLE,
XLABEL, YLABEL, AXIS, AXES, HOLD, COLORDEF, LEGEND, SUBPLOT, STEM.
Overloaded methods help cfit/plot.m help fints/plot.m help idmodel/plot.m help iddata/plot.m help cgrules/Plot.m help xregtwostage/plot.m help xregtransient/plot.m help xregmodel/plot.m help localmod/plot.m help sweepset/plot.m help mdevtestplan/plot.m help cgdatasetnode/plot.m help cgdatadisplay/plot.m help ntree/plot.m help dtree/plot.m help wvtree/plot.m help rwvtree/plot.m help edwttree/plot.m

Kuliah Berseri IlmuKomputer.Com
Copyright © 2004 IlmuKomputer.Com

I.3. Struktur File
Tipe file yang sering dipakai di Matlab terdiri dari *.mat dan *.m. File dengan ekstensi
*.mat biasanya untuk menyimpan workspace yang kita kerjakan di command window, sedangkan file dengan ekstensi *.m biasanya untuk menyimpan program dan disebut "mfile". Untuk "m-file" akan dibahas selanjutnya.
Untuk meyimpan pekerjaan anda pilih File
Save Workspace As ketik work_1.mat, maka anda telah meyimpan pekerjaan anda di file work_1.mat. File ini hanya bisa di buka lagi di command window.
Untuk membuka pekerjaan anda kembali, coba : clear all load work_1.mat whos Name

Size

Bytes

tes x 1x1
1x10

8
80

Class double array double array

Grand total is 11 elements using 88 bytes

Keterangan : Untuk Bab ini dan selanjutnya terdapat tiga tipe penulisan script, tulisan berwarna hijau menunjukan perintah yang ditulis di command window, tulisan berwarna biru merupakan output dari perintah yang ditulis dan tulisan didalam kotak menunjukkan script yang ditulis di text editor.

I.2.Bilangan dan Operator Matematika di Matlab
Terdapat tiga tipe bilangan di Matlab , yaitu :





Bilangan bulat ( integer )
Bilangan real
Bilangan kompleks

Contoh bilangan bulat x=10 x =
10

Kuliah Berseri IlmuKomputer.Com
Copyright © 2004 IlmuKomputer.Com

Contoh bilangan real x=10.01 x =
10.0100

Di dalam Matlab anda tidak perlu penanganan khusus untuk bilangan kompleks. Bilangan kompleks di beri tanda i atau j , contoh : y=sqrt(-2) % akat negatif 2

y =
0 + 1.4142i real(y) ans =
0
imag(y) ans =
1.4142
abs(y) ans =
1.4142
angle(y) ans =
1.5708

Matlab mempunyai variabel yang bukan merupakan bilangan yang di lambangkan dengan :





-inf inf Nan

Kuliah Berseri IlmuKomputer.Com
Copyright © 2004 IlmuKomputer.Com

Daftar operasi aritmatika dasar dalam Matlab

Daftar konstanta yang nilainya sering digunakan

Contoh 1 :
Misalnya anda mengambil kuliah sebanyak 12 SKS, yang terdiri dari seismologi 4 sks,
Analisis sinyal 3 sks, Tomografi 2 sks dan Gravitasi 3 sks. Lalu pada akhir semester anda mendapat nilai sebagai berikut seismologi A, Analisis sinyal B, Tomografi C dan gravitasi A. Dengan point nilai A=4, B=3, C=2 berapa nilai IP anda ?
Untuk menyelesaikan ini digunakan pendekatan seperti perhitungan di kalkulator: ip=(4*4+3*3+2*2+3*4)/(4+3+2+3) ip =
3.4167

Sebagai alternatif anda dapat menyelesaikan masalah di atas dengan terlebih dahulu menyimpan informasi yang kita punya pada variabel. Contoh :

Kuliah Berseri IlmuKomputer.Com
Copyright © 2004 IlmuKomputer.Com

seismologi=4 tomografi=2 analisis_sinyal=3 gravitasi=4 seismologi =
4
tomografi =
2
analisis_sinyal =
3
gravitasi =
4
total_sks=12 total_sks =
12

ip=(seismologi*4+tomografi*2+analisis_sinyal*3+gravitasi*3)/total_sks ip =
3.4167

I.3. Komentar dan Tanda Baca
Semua teks sesudah tanda % dianggap sebagai statemen komentar, contoh: semester=8 % jumlah semester S 1

semester =
8

Variabel semester diisi dengan nilai 8 dan satetemen sesudah tanda % di anggap sebuah komentar. Statemen ini berguna untuk mendokumentasikan apa yang sudah anda kerjakan. Tanda titik koma ( ; ) dalam Matlab berguna untuk mencegah menampilkan hasil, contoh : semester=8; Kuliah Berseri IlmuKomputer.Com
Copyright © 2004 IlmuKomputer.Com

I.4.Fungsi-Fungsi Matematika Umum
Matlab mempunyai berbagai fungsi matematika umum yang biasa di gunakan dalam matematika. Sebagian besar fungsi tersebut hampir sama dengan bila anda menuliskannya secara matematis.
Sebagai contoh : pi ans =
3.1416
y=sin(pi/6) y =
0.5000
y=asin(0.5) y =
0.5236

Fungsi Trigonometri sin, asin, sinh, asinh cos, acos, cosh, acosh tan, atan, tanh, atanh cot, acot, coth, acoth sec, asec, sech, asech csc, acsc, csh, acsh

Deskripsi sinus, anti sinus, hiperbolik sinus, hiperbolik anti sinus cosines, anti cosines, hiperbolik cosines, hiperbolik anti cosines tangent, anti tangent, tangent hiperbolik, anti tangent hiperbolik cotangent, anti cotangent, cotangent hiperbolik, anti cotangent hiperbolik. secan, antisecan, secan hiperbolik, anti secan hiperbolik cosecant, anti cosecant, cosecant hiperbolik, anti cosecant hiperbolik.

Fungsi Matematika Dasar
Abs
Angle
Sqrt
Real
Imag
Conj
Round
Fix
Floor
Ceil
Rem
Exp
Log
Log10

Deskripsi nilai absolute atau amplitudo bilangan kompleks sudut fasa akar kuadrat bagian real dari bilangan kompleks bagian imaginer dari bilangan kompleks konjugat bilangan kompleks pembulatan ke bilangan bulat terdekat. pembulatan ke arah nol pembulatan kea rah − ∞ pembulatan ke arah ∞ sisa exponensial berbasis bilangan e logaritma murni logaritma basis 10

Kuliah Berseri IlmuKomputer.Com
Copyright © 2004 IlmuKomputer.Com

I.5. Contoh Penyelesaian Masalah
Contoh 1: Persamaan fungsi
Tentukan nilai fungsi dibawah ini dengan nilai-nilai t=25 , x=43 ,y=15.25,z=8.2 !
a.
b.
c.
d.
Untuk penyelesaian di atas adalah sbb:
Pertama kita buat dulu variabel nya t=25;x=43;y=15.25;z=8.2; Lalu masukkan nilai tersebut ke masing-masing fungsinya
M=4*x^2+3*y+10
M =
7.4518e+003
N=exp(2*x)+x
N =
2.2352e+037
O=sqrt((1/(x+y))+(1/(t+z)))
O =
0.2175
P=4*(exp(-x/2))*sin(pi*x)
P =
1.6223e-023

Kuliah Berseri IlmuKomputer.Com
Copyright © 2004 IlmuKomputer.Com

Contoh 2 : Penentuan volume silinder berlubang
Sebuah silinder mempunyai diameter luar 6.3125 dan diameter dalam 5.762 , tentukan volumenya bila diketahui rumus untuk mencari volumenya :

4
V = π ( RE 3 − RI 3 )
3
Dimana RE adalah diameter luar dan RI adalah diameter dalam
Penyelesaian : re=6.3125;ri=5.762; v=4/3*pi*(re^3-ri^3); disp(['Volume = ',num2str(v)])

Volume = 252.3169

I.6.Menyimpan dan Memanggil Data

Untuk Menyimpan dan memanggil data dari file pilih File

Save Workspace As …

Untuk memanggil data digunakan pilihan Load WorkSpace As atau Open pada menu file.
Sedangkan untuk mengimport data , untuk Matlab versi 6 keatas pilih file
Data .. .

Import

Matlab juga menyediakan dua perintah ---- save dan load ------- yang jauh lebih fleksibel. Perintah save untuk menyimpan satu atau lebih variabel dalam file format yang sesuai dengan pilihan anda. contoh : clear all x=1:10;y=10:10:10:100; % membuat array baru

save
Saving to: Matlab.mat

menyimpan semua variabel Matlab dalam format biner di file Matlab.mat

Kuliah Berseri IlmuKomputer.Com
Copyright © 2004 IlmuKomputer.Com

save data

menyimpan semua variabel Matlab dalam format biner di file data.mat save data_x x

menyimpan variabel x dalam format biner di file data_x.mat save data_xy.dat x

-ascii

menyimpan variabel x dalam format biner di file data_xy.dat dalam format ascii. untuk membuka data digunakan perintah load, contoh; load data_x.mat

I.7. Input dan Output di Matlab

Untuk menampilkan teks atau angka dapat digunakan fungsi disp. Sebagai contoh : disp('Ini contoh tampilan dari text')
Ini contoh tampilan dari text

Syarat digunakannya disp, isi didalamnya harus merupakan strings, jadi jika kita ingin menampilkan sebuah angka terlebih dahulu dirubah kedalam bentuk strings dengan menggunakan function num2str( ).
Sebagai contoh : nim=10499006; disp(['Nim saya adalah ',num2str(nim)])
Nim saya adalah 10499006

Untuk format output yang lebih fleksibel digunakan function fprintf, dimana disini anda dapat membuat tampilan di layar atau di simpan sekehendak anda. Fungsi ini mempunyai argumen sbb: fprintf( ' nama file ' ,' format string ' , list)

dimana list adalah nama variabel yang dipisahkan dengan koma.

Kuliah Berseri IlmuKomputer.Com
Copyright © 2004 IlmuKomputer.Com

Untuk format string :
%P.Qe untuk eksponensial
%P.Qf untuk fixed point
/n
untuk membuat baris baru

contoh : x=1007.46 ; y=2.1278;k=17; fprintf('x= %8.2f y=%8.2f k=%2.0f',x,y,k)

x=

1007.46 y=

2.13 k=17

I.7. Script M-file

Untuk menghadapi masalah jika harus mengetikkan perintah yang jumlahnya cukup banyak dibutuhkan suatu file script. File seperti ini di Matlab disebut M-file. Pada m-file anda diperbolehkan untuk mengetikkan deretan perintah dalam suatu teks file.
New
M-File.
Untuk membuat M-file, buka teks editor, pilih File
Sebagai contoh berikut ini diberikan perintah-perintah untuk menyelesaikan masalah pencarian nilai blok dalam tomografi geofisika. Yang didefinisikan dengan rumus sebagai berikut : no _ blok = (k − 1).nx.ny + ( j − 1).nx + i i = ifix (( x − xo) / dx) + 1 j = ifix (( y − yo) / dy ) + 1 k = ifix (( z − zo) / dz ) + 1
Dimana : x,y,z koordinat yang akan dicari nilai bloknya dx, dy, dz adalah panjang blok dalam arah x , y dan z. xo, yo, zo adalah koordinat awal ifix adalah bilangan bulat.
Penyelesaiannya dalam matlab adalah sebagai berikut :
% blok_tomo.m script file untuk mencari nilai blok tomografi x=110;y=10;z=175; % koordinat titik yang akan dicari nilai bloknya dx=1;dy=1;dz=50; % ukuran blok nx=65;ny=35; % Banyak kotak kearah x dan y x0=90;y0=-15;z0=0; % Koordinat awal i=fix((x-x0)/dx)+1; Kuliah Berseri IlmuKomputer.Com
Copyright © 2004 IlmuKomputer.Com

j=fix((y-y0)/dy)+1; k=fix((z-z0)/dz)+1; no_blok=(k-1)*nx*ny + (j-1)*nx+i disp(['no blok = ',num2str(no_blok)])

Untuk mengeksekusi file ini terlebih dahulu anda simpan dengan memilih File Save as
Run. Atau dengan cara
..,lalu beri nama blok_tomo.m. Setelah itu pilih Debug mengetikkan nama file tersebut di command Window Matlab : blok_tomo no blok = 8471

Jika perintah matlab tidak diakhiri dengan titik koma,hasil dari perintah itu serta nama variabelnya akan ditampilkan kembali dalam command window.Supaya tamplan lebih bagus , maka untuk menampilkan nama variabel digunakan perintah disp.
Perintah echo on membuat perintah-perintah yang dibuat di M-file akan ditampilkan kambali di command window.
Perintah input memungkinkan anda meminta input dari pemakai saat M-file dijalankan.
Contoh : Coba anda ketikkan perintah berikut di command window umur=input(‘masukkan umur anda sekarang’)

I.8. Operator Logika dan Relasional

Operator
<

>=
==
~=

Deskripsi kurang dari kurang dari sama dengan lebih dari lebih dari sama dengan sama dengan tidak sama dengan

Operator logika
|
&
~

Deskripsi or and not Kuliah Berseri IlmuKomputer.Com
Copyright © 2004 IlmuKomputer.Com

Daftar Pustaka
a) Getting Started With MATLAB , Version 6 , The MathWorks.Inc , 2002
b) MATLAB Bahasa Komputansi Teknis , Penerbit ANDI Yogyakarta , 2000
c) Numerical Methods Using Matlab , ELLIS HORWOOD , 1995
d) Mastering MATLAB 5. A Comprehensive Tutorial and reference , Prentice Hall ,
1998
e) http://www.mathworks.com

Similar Documents

Free Essay

Forecasting Models

...MATLAB® Getting Started Guide R2011b How to Contact MathWorks Web Newsgroup www.mathworks.com/contact_TS.html Technical Support www.mathworks.com comp.soft-sys.matlab suggest@mathworks.com bugs@mathworks.com doc@mathworks.com service@mathworks.com info@mathworks.com Product enhancement suggestions Bug reports Documentation error reports Order status, license renewals, passcodes Sales, pricing, and general information 508-647-7000 (Phone) 508-647-7001 (Fax) The MathWorks, Inc. 3 Apple Hill Drive Natick, MA 01760-2098 For contact information about worldwide offices, see the MathWorks Web site. MATLAB® Getting Started Guide © COPYRIGHT 1984–2011 by The MathWorks, Inc. The software described in this document is furnished under a license agreement. The software may be used or copied only under the terms of the license agreement. No part of this manual may be photocopied or reproduced in any form without prior written consent from The MathWorks, Inc. FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation by, for, or through the federal government of the United States. By accepting delivery of the Program or Documentation, the government hereby agrees that this software or documentation qualifies as commercial computer software or commercial computer software documentation as such terms are used or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms and conditions of this Agreement and only those rights...

Words: 36443 - Pages: 146

Free Essay

Human Step Detection and Counting with a Microphone (June 2015)

...alternative use of sensors for detecting human movements such as footsteps and that is done for various reasons such as security or just for lightning a lamp automatically. We developed a Simulink model in Matlab to simulate a system that analyses the footsteps of three 25 years old men. Those men had different heights and weights. The data were recorded and analyzed using filtering and conditioning blocks of Matlab. The System collected 3 sets of steps. The first set had 5 steps with 5 detections. The second set had 8 steps with 3 detection and the third set had 4 steps with 1 detections. In total, there were 17 steps where 9 steps were detected. I. C. Procedure During the first part of the experiment, the footsteps were recorded on the main corridor of the first floor of the house 21, located in the University of Kristianstad. We also recorded the steps at our respective houses. The experiment was carried on a floor without carpet to allow a better collection of the data. This procedure was repeated several times, until satisfactory data without much noisy could be acquired. INTRODUCTION T HE objective of this work was to detect the steps of a person using a microphone array embedded in our computer together with the Simulink library of Matlab. We have some background of the idea after reading a few articles regarding this type of experiments. Fig. 1. Simulink models used to record the steps In the articles we read, the experiment...

Words: 1833 - Pages: 8

Free Essay

Matlab

...matlab Probleme teoretice ale programării în MATLAB 1. Tipul de dată numeric. 2. Tipul de dată logic. 3. Tipul de dată caracter, şir de caractere. 4. Tipul de dată data şi ora. 5. Tipul de dată structură. 6. Tipul de dată celulă. 7. Expresii numerice şi logice în MATLAB. 8. Variabile în MATLAB. Definiţie şi tipuri de variabile. 9. Crearea variabilelor şi reguli de declarare a lor. 10. Cuvinte cheie. 11. operatori şi reguli de precedenţă. 12. Constante speciale în MATLAB. 13. Matrici, vectori, scalari. Funcţia size. Crearea cu operatorul []. 14. Crearea matricelor cu funcţii speciale. 15. Concatenarea matricelor. 16. Crearea matricelor cu blocuri pe diagonală 17. Accesarea directă şi liniară a matricelor. 18. Accesarea multiplă (cu operatorul :). 19. Accesarea logic indexată. 20. Funcţii de matrici şi funcţii de manipulare a matricelor. 21. Comanda de atribuire. Comenzi de întrerupere a execuţiei buclelor. 22. Comenzi de execuţie condiţionată. 23. Comenzi de execuţie a ciclurilor. 24. M-programe (M-scripturi şi M-funcţii) 25. Erori. Exportul şi importul datelor. Listarea pe ecran. 26. Depanarea M-programelor. 27. Utilizarea eficientă a memoriei. 28. Analiza timpului de execuţie şi principalele tehnici de reducere a timpului de execuţie. 29. Modelarea cu blocuri şi conexiuni în Simulink 30. Cele mai utilizate blocuri din biblioteca de blocuri Simulink. 1. Să se scrie...

Words: 1953 - Pages: 8

Premium Essay

Matlab

...C1: MATLAB Codes t1=[37.79 39.51 38.54 39.14 39.02 39.4 39.01 37.18] t2=[22.4 22.07 22.15 21.72 21.75 22.55 22.18 21.92] T1=mean(t1) T2=mean(t2) V1=var(t1) V2=var(t2) S1=sqrt(V1) S2=sqrt(V2) MATLAB Answers T1=38.6988 T2=22.0925 V1=0.6718 V2=0.0859 S1=0.8196 S2=0.2931 C2: MATLAB Codes beta=0.98 alpha=1-0.98 z=icdf ('norm', alpha/2, 0, 1) hatmu=mean(t1); hatmu=mean(t2) s=std(t1); s=std(t2) n=length (t1); n=length (t2) margin=z*s/sqrt(8) MATLAB Answers alpha=0.02 z=2.3263 margin(t1)=0.6741; margin(t2)=0.2931 C3: MATLAB Codes syms l s b T1 T2 l=0.0496; s=1.00; b=10; T1=0.0386988; T2=0.0220925; g=((l^2)/(2*s*sind(b)))*((1/T2^2)-(1/T1^2)) MATLAB Answers g=9.7835 C4: MATLAB Codes for Partial Derivatives g=((l^2)/(2*s*sin(b)))*((1/T2^2)-(1/T1^2)) gl=diff(g,l) gs=diff(g,s) gb=diff(g,b) gT1=diff(g,T1) gT2=diff(g,T2) MATLAB Answers for Partial Derivatives gl=-(l*(1/T1^2 - 1/T2^2))/(s*sin(b)) gs=(l^2*(1/T1^2 - 1/T2^2))/(2*s^2*sin(b)) gb=(l^2*cos(b)*(1/T1^2 - 1/T2^2))/(2*s*sin(b)^2) gT1=l^2/(T1^3*s*sin(b)) gT2=-l^2/(T2^3*s*sin(b)) MATLAB Codes for Partial Derivative Values gl0=subs(gl,[l s b T1 T2],[l0 s0 b0 T10 T20]) gs0=subs(gs,[l s b T1 T2],[l0 s0 b0 T10 T20]) gb0=subs(gb,[l s b T1 T2],[l0 s0 b0 T10 T20]) gT10=subs(gT1,[l s b T1 T2],[l0 s0 b0 T10 T20]) gT20=subs(gT2,[l s b T1 T2],[l0 s0 b0 T10 T20]) MATLAB Answers for Partial Derivative Values gl0= -125.9202 gs0=...

Words: 455 - Pages: 2

Free Essay

Matlab

...An Introduction to Matlab for Econometrics John C. Frain TEP Working Paper No. 0110 February 2010 Trinity Economics Papers Department of Economics Trinity College Dublin An Introduction to MATLAB for Econometrics John C. Frain. February 2010 ∗ Abstract This paper is an introduction to MATLAB for econometrics. It describes the MATLAB Desktop, contains a sample MATLAB session showing elementary MATLAB operations, gives details of data input/output, decision and loop structures, elementary plots, describes the LeSage econometrics toolbox and maximum likelihood using the LeSage toolbox. Various worked examples of the use of MATLAB in econometrics are also given. After reading this document the reader should be able to make better use of the MATLAB on-line help and manuals. Contents 1 Introduction 1.1 1.2 Preliminaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The MATLAB Desktop . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 ∗ Comments 4 4 6 6 7 8 8 9 9 9 The Command Window . . . . . . . . . . . . . . . . . . . . . . . . The Command History Window . . . . . . . . . . . . . . . . . . . The Start Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Edit Debug window . . . . . . . . . . . . . . . . . . . . . . . . The Figure Windows . . . . . . . . . . . . . . . . . . . . . . . . . . The Workspace Browser . . . . . . . . . . . . . . . . . . . . . . . . The...

Words: 15376 - Pages: 62

Free Essay

Matlab

...PARTH  PATTNI     BIOENGINEERING-­‐MATLAB  ASSIGNEMENT   a) figure subplot(2,1,1) plot(ecg_emg) ylabel('Voltage,V/mV') xlabel('Time,t/ms') title('ECG which is contaminated with EMG signals from the diaphragm') axis([0 3000 -1 2]) subplot(2,1,2) plot(ecg50hz) xlabel('Time,t/ms') ylabel('Voltage,V/mV') title('ECG containing mains contamination') axis([0 3000 -1 2]) PARTH  PATTNI     BIOENGINEERING-­‐MATLAB  ASSIGNEMENT   b & c) figure subplot(2,1,1) length=5; for x=1:3000-length+1; zecg_emg(x)=(ecg_emg(x)+ecg_emg(x+1)+ecg_emg(x+2)+ecg_emg(x+3)+ ecg_emg(x+4))/5; end plot(ecg_emg) ylabel('Voltage,V/mV') xlabel('Time,t/ms') title('ECG which is contaminated with EMG signals from the diaphragm') axis([0 3000 -1 2]) subplot(2,1,2) length=5; for x=1:3000-length+1; zecg50hz(x)=(ecg50hz(x)+ecg50hz(x+1)+ecg50hz(x+2)+ecg50hz(x+3)+ecg 50hz(x+4))/5; end plot(ecg50hz) xlabel('Time,t/ms') ylabel('Voltage,V/mV') title('ECG containing mains contamination') PARTH  PATTNI     BIOENGINEERING-­‐MATLAB  ASSIGNEMENT   axis([0 3000 -1 2]) d) figure subplot(2,1,1) length=3; for x=1:3000-length+1; zecg_emg(x)=(ecg_emg(x)+ecg_emg(x+1)+ecg_emg(x+2))/3; end plot(zecg_emg) ylabel('Voltage,V/mV') xlabel('Time,t/ms') title('ECG which is contaminated with EMG signals from the diaphragm') PARTH  PATTNI     BIOENGINEERING-­‐MATLAB  ASSIGNEMENT   axis([0 3000 -1 2]) subplot(2...

Words: 645 - Pages: 3

Free Essay

Matlab

...A、B 机器加工,加工时间分别为每台 2 小时和 1 小时;生产乙机床 需用 A、B、C 三种机器加工, 加工时间为每台各一小时。 若每天可用于加工的机器时 数分别为 A 机器 10 小时、 B 机器 8 小时和 C 机器 7 小时,问该厂应生产甲、乙机床各 几台,才能使总利润最大? 上述问题的数学模型: 设该厂生产 x1 台甲机床和 x 2 乙机床时总利润最大, x1 , x2 则 应满足 (目标函数) max z = 4 x1 + 3 x2 (1) ⎧2 x1 + x2 ≤ 10 ⎪x + x ≤ 8 ⎪ 1 2 s.t.(约束条件) ⎨ ⎪ x2 ≤ 7 ⎪ x1 , x2 ≥ 0 ⎩ (2) (1)式被称为问题的目标函数, (2)中的几个不等式 这里变量 x1 , x 2 称之为决策变量, 是问题的约束条件,记为 s.t.(即 subject to)。由于上面的目标函数及约束条件均为线性 函数,故被称为线性规划问题。 总之, 线性规划问题是在一组线性约束条件的限制下, 求一线性目标函数最大或最 小的问题。 在解决实际问题时, 把问题归结成一个线性规划数学模型是很重要的一步, 但往往 也是困难的一步,模型建立得是否恰当,直接影响到求解。而选适当的决策变量,是我 们建立有效模型的关键之一。 1.2 线性规划的 Matlab 标准形式 线性规划的目标函数可以是求最大值, 也可以是求最小值, 约束条件的不等号可以 是小于号也可以是大于号。为了避免这种形式多样性带来的不便,Matlab 中规定线性 规划的标准形式为 min cT x x ⎧ Ax ≤ b ⎪ s.t. ⎨ Aeq ⋅ x = beq ⎪lb ≤ x ≤ ub ⎩ 其中 c 和 x 为 n 维列向量, A 、 Aeq 为适当维数的矩阵, b 、 beq 为适当维数的列向 量。 -1- 例如线性规划 Ax ≥ b max cT x s.t. x 的 Matlab 标准型为 min − cT x s.t. x − Ax ≤ −b 1.3 线性规划问题的解的概念 一般线性规划问题的(数学)标准型为 n z = ∑cj xj max (3) j =1 s.t. 可行解 ⎧n ⎪∑ aij x j = bi i = 1,2, L, m ⎨ j =1 ⎪ x ≥ 0 j = 1,2,L, n ⎩ j (4) 满足约束条件 (4) 的解 x = ( x1 , x2 , L , xn ) , 称为线性规划问题的可行解, 而使目标函数(3)达到最大值的可行解叫最优解。 可行域 所有可行解构成的集合称为问题的可行域,记为 R 。 1.4 线性规划的图解法 10 2 x1 + x2 = 1 0 9 8 7 x2 = 7 (2 ,6 ) 6 5 4 3 2 x1 + x2 = 8 1 z= 1 2 0 0 2 4 6 8 10 图 1 线性规划的图解示意图 图解法简单直观, 有助于了解线性规划问题求解的基本原理。 我们先应用图解法来 求解例 1。对于每一固定的值 z ,使目标函数值等于 z 的点构成的直线称为目标函数等 位线,当 z 变动时,我们得到一族平行直线。对于例...

Words: 57838 - Pages: 232

Free Essay

Matlab

...Lab 2: Linear Time-Invariant Systems In this experiment, you will study the output response of linear time-invariant (LTI) systems using MATLAB, and learn how to use MATLAB to implement the convolution sum. You will also investigate the properties of LTI systems. The objective of this experiment is: (1) to study how to compute the output of LTI systems, and (2) to study the properties of discrete-time LTI systems. 1. Introduction to Linear Time-Invariant (LTI) Systems In discrete time, linearity provides the ability to completely characterize a system in terms of its response [pic] to a signal of the form [pic] for all [pic]. If a linear system is also time-invariant, then the responses [pic] will become [pic]. The combination of linearity and time-invariance therefore allows a system to be completely described by its impulse response [pic]. The output of the system [pic] is related to the input [pic] through the convolution sum as follows: [pic] Similarly, the output [pic] of a continuous-time LTI system is related to the input [pic] and the impulse response [pic] through the following convolution integral: [pic] The convolution of discrete-time sequences [pic] and [pic] represented mathematically by the expression given in [pic] can be viewed pictorially as the operation of flipping the time axis of the sequence [pic] and shifting it by [pic] samples, then multiplying [pic] by[pic] and summing the resulting product sequence...

Words: 1592 - Pages: 7

Free Essay

Matlab

...Matlab Assignment 7 Make the Matalb assignment discussed in the last class (least square regression estimates). Make sure that you program a function with proper comments and at least one test for sound input. Test your function with some input vectors, for example: y=[1,2,4,23,4,6,3,2] and x=[5,4,3,2,6,5,4,3] You can take any other input vectors. m.file command: function [alpha_estimate, beta_estimate] = my_regression(y,x) n = length(x) a = sum(x); b = sum(y); c = sum(x)/n; d = sum(y)/n; e = sum(x.*y); f = sum(x.*x); alpha_estimate = d-(e-n*c*d)/(f-n*c^2)*c; beta_estimate = (e-n*c*d)/(f-n*c^2); disp('alpha =') disp(alpha_estimate) disp('beta =') disp(beta_estimate) % Purpose of the function: This function is used to calculate the % coefficients of the regression formula. % Input: value of y and x % Output: alpha_estimate and beta_estimate % How to run the function: % I use n to represent the length of vector x and y % a to represent the sum of vector x % b to represent the sum of vector y % c to represent the avergae of vector x % d to represent the average of vector y % e to represent the sum of vector x and y % f to represent the sum of square of vector x %then calculating: alpha_estimate = d-(e-n*c*d)/(f-n*c^2)*c; % beta_estimate = (e-n*c*d)/(f-n*c^2); % Author: Hengya Jin % Date of last change: 11/27/2013 end Check: >> y=[1,2,4,23,4...

Words: 298 - Pages: 2

Premium Essay

Matlab Ode

...MATLAB 數值微積分與微分方程式求解 數值積分 ∫ b a f ( x) dx 等於由界限範圍 x = a 到 x = b 之間 曲線 f(x) 底下的面積 (a) 矩形以及 (b) 梯形 數值積分的圖解說明 數值積分 已知數據點的積分, 已知數據點的積分,不知函數 f(x):trapz : I = trapz(x, y) (梯形積分法 梯形積分法) 梯形積分法 x : 數據點之 x 值所構成的向量 y : 數據點之 f(x) 值所構成的向量 Ex: >>x=[0 10 20 30 40]; >>y=[0.5 0.7 0.9 0.6 0.4]; >>area=trapz(x,y) %梯形法 梯形法 area = 26.5000 數值積分 之形式: 已知函數 f(x) 之形式:quad , quadl I = quad(@fun, a, b) I = quadl(@fun, a, b) (適應性辛普森法) (羅伯特二次式) fun:定義函數的 function m-file 檔名 a :積分下限 b :積分上限 數值積分 Ex: ∫ 1 0 e − x cos( x) dx 1. edit fun.m function y=fun(x) y=exp(-x).*cos(x); 2. 求積分 回到Matlab Command Window) 求積分(回到 area=quadl(@fun,0,1) 亦可使用 area=quadl(‘exp(-x).*cos(x)’,0,1) NOTE: 函數內之數學運算必須使用向量個別元素之運算 (.* ./ .^) (註:比較此結果與利用trapz指令計算之結果) 數值微分 已知數據點的微分 在 x2 之微分 數值微分 可利用 diff 函數 Ex: >>x=0:0.1:1; >>y=[0.5 0.6 0.7 0.9 1.2 1.4 1.7 2.0 2.4 2.9 3.5]; >>dx=diff(x); >>dy=diff(y); >>dydx=diff(y)./diff(x) 數值微分 Ex: f ( x) = sin( x), f ′( x) = ? x ∈ [ 0, π ] >> >> >> >> >> >> >> x = linspace(0,pi,20); y = sin(x); d = diff(y)./diff(x); % backward or forward difference dc = (y(3:end)-y(1:end-2))./(x(3:end)-x(1:end-2)); % central difference dy = cos(x); % 實際微分值 plot(x, dy, x(2:end), d,'o', x(1:end-1), d,'x', x(2:end-1), dc,'^') xlabel('x'); ylabel('Derivative') 1 0.8 0.6 0.4 Derivative 0.2 0 -0.2 -0.4 -0.6 -0.8 -1 0 0.5 1 1.5 x 2 2.5 3 3.5 工程問題中常微分方程式的解 常微分方程式 常微分方程式之形式: dy = f (t, y) dt 一般解之形式: yi +1 = yi + φ h ...

Words: 983 - Pages: 4

Free Essay

Matlab

...Signals and Systems Midterm 10:20a.m. ~ 12:20p.m., May 1, Fri., 2009 Closed book, but open 1 sheet (both sides, 2 pages) of personal notes of A4 size Total score: 120 Total 4 pages in one B4 sheet 1. [12] Suppose x and y denote input and output, respectively, of each of the three systems: System A: y (t ) = x(t + 2) sin(ω t + 2), ω ≠ 0 System B: y[n] = ( − 1 ) ( x[n] + 1) 2 System C: y[n] = ∑ x 2 [k + 1] − x[k ] k =1 n n Answer the following questions for each system and justify your answer. (a) Is the system linear? (b) Is the system time invariant? (c) Is the system causal? (d) Is the system stable? 2. We want to develop an edge detector that is robust against additive noise. Consider a discrete-time (DT) linear time-invariant (LTI) system H 2 with h2 [ n] = h[ n] ∗ h[ n + 1] as its impulse response shown below, where h[ n] = δ [ n] − δ [ n − 1] . (a) [4] Assume there is no noise, i.e., d [n] = 0 and x[n] = p[n] . Sketch the output y[n] of the system assuming the input p[n] to the system is the following signal: (b) [4] Assume the noise is d [ n] = −δ [ n + 1] and the input p[n] remains the same. Sketch the output y[n] of the system. (c) [4] In order to use system H 2 as a part of an edge detector, we would like to add an LTI system H s whose unit impulse response hs [n] is shown below. System H s smoothes out effect of noise on x[n] . The overall system can be represented as below: Sketch the output ys [n] of the system with d [n] and p[n] specified...

Words: 1025 - Pages: 5

Free Essay

Matlab & Ss

...Lab 1: Introduction to MATLAB Warm-up MATLAB is a high-level programming language that has been used extensively to solve complex engineering problems. The language itself bears some similarities with ANSI C and FORTRAN. MATLAB works with three types of windows on your computer screen. These are the Command window, the Figure window and the Editor window. The Figure window only pops up whenever you plot something. The Editor window is used for writing and editing MATLAB programs (called M-files) and can be invoked in Windows from the pull-down menu after selecting File | New | M-file. In UNIX, the Editor window pops up when you type in the command window: edit filename (‘filename’ is the name of the file you want to create). The command window is the main window in which you communicate with the MATLAB interpreter. The MATLAB interpreter displays a command >> indicating that it is ready to accept commands from you. • View the MATLAB introduction by typing >> intro at the MATLAB prompt. This short introduction will demonstrate some basic MATLAB commands. • Explore MATLAB’s help capability by trying the following: >> help >> help plot >> help ops >> help arith • Type demo and explore some of the demos of MATLAB commands. • You can use the command window as a calculator, or you can use it to call other MATLAB programs (M-files). Say you want to evaluate the expression [pic], where a=1.2, b=2.3, c=4.5 and d=4....

Words: 2151 - Pages: 9

Free Essay

Pelajaran Matlab

...SUPLEMEN Pemodelan Sistem / Pengolahan Sinyal / Metode Kuantitatif TUTORIAL SINGKAT MATLAB oleh: Judi Prajetno Sugiono Sekolah Tinggi Teknik Surabaya (2005, 2008, 2011) judi@stts.edu ©2005 p. 1 of 40 MATLAB Short Tutorial Reserve word (don’t used it as variable's name) · · · · · ans pi nan inf eps Special sign · · · · · % [] ; ' : line comment begin - end of matrix row separation, or not echoed command if place in the end of a statement begin - end of string indexing sign Variable is assume as matrix % empty matrix A=[] A = [] % matrix 1x1 or a constant A=[0] A = 0 % same with A=0 A = 0 % complex number: use i or j to express imaginary part z=3+4j z = 3.0000 + 4.0000i Entry a matrix % use as column separation and or as row separation A=[1 2 3; 4 5 6; 7 8 9] A = 1 4 7 2 5 8 3 6 9 Last saved by jpsugiono 9/23/2011 judi@stts.edu ©2005 p. 2 of 40 How to point element of matrix % A(row,column) A(1,3) ans = 3 % sign use as get all row or column A(2,:) ans = 4 5 6 % sign use as get from m to n cell in row or colomn A(1:2, 2:3) ans = 2 5 3 6 row and column vector % row vector a=[0 1 2 3 4 5] a = 0 1 2 3 4 5 % column vector b=[0; 1; 3; 4; 5] b = 0 1 3 4 5 % Shortcut to build a vector % init:step:final a=0:0.2:1 a = 0 0.2000 0.4000 0.6000 String % begin and end with < ' >, and act like a matrix of character ...

Words: 819 - Pages: 4

Free Essay

Ocr Matlab

...EEN 538: DIGITAL IMAGE PROCESSING Optical Character Recognition (OCR) using binary image processing with MATLAB Abstract- Nowadays, Optical Recognition is becoming a very important tool in several fields: medicine, physics, cosmology, traffic (plate numbers), etc. We can also use this to recognize character for example to digitalize a book. We will talk about this last topic in this report: Optical Character Recognition (OCR). I. INTRODUCTION Once we have the b&w image we can start the segmentation process. To do that we can use the function “bwconncomp”. This function returns us a struct from where we can obtain the characters because it gives us all the connected components. Thus, we can use it to get all the character even if they have 2 or 3 objects. This function returns us the pixels of the connected components (characters) but we have to figure out from those, the coordinates of the character in the original matrix (row and columns). To do this, we will obtain the centroid of every connected component and from it and using the first and last pixel detected of the connect component, we can figure out the exact coordinates of the image. The idea is as follows: Firstly, we can to convert the number that the function returns us to a column and a row. We can do this using the total rows of the original image. Once we have the first and last pixel detected of the connect component in (row, column) we can figure out directly the x-coordinates of the character in the image...

Words: 1132 - Pages: 5

Premium Essay

Matlab Sol

...mClassics Company paid $275,000 on May 1 to purchase $300,000, 6%, bonds that will mature in 5 years from the date of purchase. Interest on the bonds is paid May 1 and November 1 of each year. Classics Company plans to hold the bonds until maturity and amortizes the premium or discount on each interest payment date using the straight-line method. At year end, the bonds had a market value of $285,000. Prepare all necessary journal entries related to the investment in bonds. Answer: May 1 Long-Term Investment in Bonds 275,000 Cash 275,000 Nov. 1 Cash 9,000 Interest Revenue ($300,000 × 6% × 6/12) 9,000 Nov. 1 Long-Term Investment in Bonds 2,500 Interest Revenue ($300,000 - $275,000) × (6/60) 2,500 Dec 31 Interest Receivable 3,000 Interest Revenue ($300,000 × 6% × 2/12) 3,000 Dec. 31 Long-Term Investment in Bonds 833 Interest Revenue ($300,000 - $275,000) × (2/60) 833 On April 2, Smith Co. purchased 25% of Wesson Inc.’s stock for $600,000. On August 1, Wesson paid a cash dividend of $340,000 and on August 31 reported net income for the year of $2,000,000. On October 1, Smith sold all the stock in Wesson Inc. for $1,200,000. Record the Wesson-related transactions in the journal of Smith Co. Answer: April 2 Long-Term Investment in Wesson $600,000 Cash $600,000 August 1 Cash ($340,000 X .25) $85,000 Long-Term Investment in Wesson...

Words: 534 - Pages: 3