7 views

Uploaded by api-19807868

save

- Changes matpower
- Problem Set 0
- ABI MATLAB for Electrical and Computer Engineering Students and Professionals with Simulink.pdf
- Array Indexing - MATLAB & Simulink.pdf
- Lecture 2 Notes
- Exercises on Labview
- Getting Started With MATLAB_Part1
- Optional 01
- 01-Introduction_to_MATLAB.pptx
- FINAL DOC
- Wind Turbine Blockset in Matlab Simulink
- present matlab pdf.pdf
- Build CAN Communication Simulink Models - MATLAB & Simulink
- Body of Project
- Spatial Econometrics - Book LeSage
- Matrices Module
- c1bs01-mathematics-i-set1
- rtwin_ug
- Direction Finding Using 3d Array Geometry
- RPH11
- Calculator Instructions.pdf
- Report Simulation Latest
- Problem set In High Energy
- cv kai wu oct 19th
- gsm based temperature monitering and control
- Mat 31121SummerISyllabus2016
- SimulinkIEEE04
- Parallel Computing Toolbox™UserGuide
- UT Dallas Syllabus for math2418.501.09f taught by Istvan Ozsvath (ozsvath)
- Simulink Design Optimization - Getting Started Guide
- LED2
- Nostromo_NT
- Light emitting diode
- love me little love me long
- LED1
- War_and_Peace_NT
- fiber_optic
- The_Thirty-Nine_Steps_NT
- Signals.and.systems.made.simple.Karu.2001.scan
- Paradise_Lost_NT
- Beyond_Good_and_Evil_NT
- The_Portrait_of_a_Lady_NT
- Optical_Fibre_Communications-senoir
- The_Red_Badge_of_Courage_NT
- optical devices
- scada procure
- Biomedical signal processing
- Microwave Engineering 3e - David M Pozar - Solutions Manual
- SMS GSM HANDBOOK
- John.Wiley.&.Sons.WiMAX-Technology.for.Broadband.Wireless.Access.2007
- biomedical
- theory_microwave_technology
- Top_Images_2008
- Electronic Imaging Devices
- IPRoutingtrace
- BioMedical Engg
- Digital Electronics
- encf_7
- Innovation on Medical Electronics

You are on page 1of 9

**Lab-1 Dated: 24-10-2007
**

1. What is MATLAB:

The name Matlab is short for the MATrix LABoratory. It is commercial software

package whose main function is to perform calculations on matrices, row vectors, and

column vectors. It is widely used in both industry and academic institutions. It

possesses many of the features of the High Level, numerically oriented programming

language, but in addition has a large collection of built-in functions for performing

matrix and vector operations in a way that is very simple for the user.

In addition to functions for performing the usual computations from linear algebra

(e.g., inverse, transpose, determinants etc.) Matlab has collection of toolboxes of

more specialized functions for computations in specific areas of science and

engineering including Control system Toolbox.

2. Entering and Quitting MATLAB.

Start windows and double click on the MATLAB icon (if it is installed!). A command

window will appear. You can write your programs directly on the window or you

may open a new file from file menu, which appears on top of the command window.

3. Creating and Manipulating Matrices and Vectors.

Matlab works on matrices and vectors that may be real or complex. Variables do not

have to be declared (as in C-language). Computations are performed using double-

precision arithmetic, and the results can be displayed in a variety of different formats.

Let us enter a row matrix into the Matlab workspace. Type in:

» v=[2 4 7 5]

and pressing enter key will result in echo back to you:

v =

2 4 7 5

this creates a variable v whose current value is a row vector with four elements as

shown. To suppress the echo one uses semicolon following the command line. Thus

» W=[1 3 8 9];

creates another row vector W, but does not echo. To check that W has appeared in the

Matlab workspace, type

» who

which will display all the variables in the Matlab workspace as:

Your variables are:

W v

and to check the value of W simply type:

» W

and press enter key,

W =

1 3 8 9

Note that Matlab is case sensitive.

EXERCISE-1: investigate the effect of the following commands:

(i) v(2)

(ii) W(4)

(iii) sum=v+W.

(iv) diff=v-W

(v) vW=[v W]

(vi) vW(2:6)

(vi) v’

column vectors can be typed directly in one of two ways, for example, to enter the

column vector

1

1

Z =

0

0

you can type

» Z=[1;1;0;0]or

» Z=[1

1

0

0]

both will result in:

Z =

1

1

0

0

EXERCISE-2: investigate the effects of following commands:

(i) Z’

(ii) Z*v

(iii) Z’*v’

(iv) [v;W]

(v) [Z;v’]

it creates a new matrix of single column combining the column vector Z and

transpose of row matrix v.

(vi) Z+v’

it simply adds the column vector Z with transpose of row vector v.

These are various ways of entering matrices. For example, to enter the matrix

1 2

M =

3 4

the most obvious ways are to type

» M=[1 2;3 4] or

» M=[1 2 3 4]

but there are more perverse ways such as:

» M=[[1 3]'[2 4]']

EXERCISE-3: investigate the effect of the following commands:

(i) N=inv(M)

this creates a new matrix N whivh is a inverse of matrix M.

(ii) M*N

it simply multiply M with N.

(iii) det(M)

it finds the determinant of matrix M.

(iv) I=eye(2)

this display the identity matrix of order 2-by-2.

(v) M+I

this add the Identity matrix with matrix M.

(vi) M*Z

it will multiply matrix M to first and second row of matrix Z.

(vii) v(3:4)*M

(viii) M(I,I)

It will display first element (1x1) of the matrix.

(ix) M (1:2,1:2)

will display elements in(2x2) matrix.

(x) M(:,1)

will only display first column’s elements.

(xi) M(2,:)

it will only display the second row of the M matrix.

**4.Built-in functions and Matlab HELP.
**

You have already encountered some built-in functions. In addition to standard arithmetic

operations such as “+” and “*”, you have met inv (M) that generates the inverse of matrix

M, det(M) that generates determinant of M and eye(2) that generates the 2-by-2 Identity

matrix. Matlab has a very large number of built-in functions. To see the list of those

variables on your machine type

» help

**To get information a specific function (“det” for example) type
**

» help det

DET Determinant.

DET(X) is the determinant of the square matrix X.

Use COND instead of DET to test for matrix singularity.

See also COND.

The help command is very useful. Most of the Matlab built-in functions have very

descriptive names and are easily remembered or guessed.

EXERCISE-4: use the help command to find out about the following built-in functions

and make your own sample examples

(i) ones

Solution:

ONES Ones array.

ONES(N) is an N-by-N matrix of ones.

ONES(M,N) or ONES([M,N]) is an M-by-N matrix of ones.

ONES(M,N,P,...) or ONES([M N P ...]) is an M-by-N-by-P-by-

...

array of ones.

ONES(SIZE(A)) is the same size as A and all ones.

Example program:

» ones(3)

ans =

1 1 1

1 1 1

1 1 1

(ii) zeros

Solution:

ZEROS Zeros array.

ZEROS(N) is an N-by-N matrix of zeros.

ZEROS(M,N) or ZEROS([M,N]) is an M-by-N matrix of zeros.

ZEROS(M,N,P,...) or ZEROS([M N P ...]) is an M-by-N-by-P-

by-...

array of zeros.

ZEROS(SIZE(A)) is the same size as A and all zeros.

Example program:

» zeros(3)

ans =

0 0 0

0 0 0

0 0 0

(iii) linspace

Solution:

» help linspace

**LINSPACE Linearly spaced vector.
**

LINSPACE(x1, x2) generates a row vector of 100 linearly

equally spaced points between x1 and x2.

LINSPACE(x1, x2, N) generates N points between x1 and x2.

See also LOGSPACE, :.

Example program:

» linspace(0,1)

ans =

Columns 1 through 7

0 0.0101 0.0202 0.0303 0.0404 0.0505

0.0606

(iv) logspace

Solution:

LOGSPACE Logarithmically spaced vector.

LOGSPACE(d1, d2) generates a row vector of 50

logarithmically

equally spaced points between decades 10^d1 and 10^d2. If

d2

is pi, then the points are between 10^d1 and pi.

LOGSPACE(d1, d2, N) generates N points.

See also LINSPACE, :.

Example program:

ans =

Columns 1 through 7

1.0000 1.0481 1.0985 1.1514 1.2068 1.2649

1.3257

5.graphs

The results of many control computations in Matlab are huge matrices containing, for

example, frequency responses, that one would like to display in graphical form.

We will plot graph of

ys=sin(t)

for t going from 0 to 5 seconds. First we need to generate a vector t containing the values

of time that we want to use. Type:

» t=linspace(0,5,51)

which makes t into a row vector of 51 values from0 to 5 inclusive. Another way of doing

same thing would be to type

» t=(0:0.1:5)

both ways will result in:

t =

Columns 1 through 7

0 0.1000 0.2000 0.3000 0.4000 0.5000

0.6000

» plot(t,ys)

1

0 .8

0 .6

0 .4

0 .2

0

-0 . 2

-0 . 4

-0 . 6

-0 . 8

-1

0 0.5 1 1 .5 2 2 .5 3 3 .5 4 4.5 5

**the graph can be prettied using thee following self explanatory sequence of commands:
**

» xlabel('time[in seconds]');

» ylabel('graph of sin(t)');

» title('2KES23');

2K E S 23

1

0.8

0.6

0.4

0.2

graph of sin(t)

0

-0 . 2

-0 . 4

-0 . 6

-0 . 8

-1

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

t im e [ in s e c o n d s ]

more than one set of points can be plotted on the same axes, and more than one graph can

be displayed on the screen at once.

EXERCISE-5

(i) Generate a vector containing the values of cos (t) for the same time

range before.

Solution:

» yc=cos(t)

yc =

Columns 1 through 7

1.0000 0.9950 0.9801 0.9553 0.9211

0.8776 0.8253

» plot(t,yc)

1

0.8

0.6

0.4

0.2

0

-0 . 2

-0 . 4

-0 . 6

-0 . 8

-1

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

**(ii) From “help” entry for “plot” find out how to get both ys an yc plotted
**

against t on the same axes.

Solution:

» t=(0:0.1:5);

» ys=sin(t);

» plot(t,ys)

» hold on

» plot(t,yc)

» hold off

1

0 .8

0 .6

0 .4

0 .2

0

-0 . 2

-0 . 4

-0 . 6

-0 . 8

-1

0 0 .5 1 1 .5 2 2 .5 3 3 .5 4 4 .5 5

**(iii) From the “help” entry for “subplot” find out how to plot ys and yc
**

plotted on two separate graphs, one above the other.

Solution:

» subplot(2,1,1),plot(t,ys)

» subplot(2,1,2),plot(t,yc)

1

0.5

0

-0.5

-1

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

1

0.5

0

-0.5

-1

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

- Changes matpowerUploaded bygugun_j
- Problem Set 0Uploaded byAparna Appu
- ABI MATLAB for Electrical and Computer Engineering Students and Professionals with Simulink.pdfUploaded bysrinureddy2014
- Array Indexing - MATLAB & Simulink.pdfUploaded byMakhdoom Ibad Hashmi
- Lecture 2 NotesUploaded byjoepepperone
- Exercises on LabviewUploaded bymayankfirst
- Getting Started With MATLAB_Part1Uploaded byRav Chumber
- Optional 01Uploaded byVivek Mishra
- 01-Introduction_to_MATLAB.pptxUploaded byajuen_99
- FINAL DOCUploaded byShubham Garg
- Wind Turbine Blockset in Matlab SimulinkUploaded byArifujjaman Sumon
- present matlab pdf.pdfUploaded byZahratul Laily Edaris
- Build CAN Communication Simulink Models - MATLAB & SimulinkUploaded byWan MK
- Body of ProjectUploaded byunikmyquestar
- Spatial Econometrics - Book LeSageUploaded byotukweR
- Matrices ModuleUploaded bySean Gomez
- c1bs01-mathematics-i-set1Uploaded bySrinivasa Rao G
- rtwin_ugUploaded byhoangductuan
- Direction Finding Using 3d Array GeometryUploaded byMohammed Nawaz Shaik
- RPH11Uploaded byCik Hidayah
- Calculator Instructions.pdfUploaded byhamooodiii
- Report Simulation LatestUploaded byAin Safirah
- Problem set In High EnergyUploaded bysachin
- cv kai wu oct 19thUploaded byapi-182175268
- gsm based temperature monitering and controlUploaded byHirankur Khillare
- Mat 31121SummerISyllabus2016Uploaded byNayil Arana
- SimulinkIEEE04Uploaded byInsaf Mohamed
- Parallel Computing Toolbox™UserGuideUploaded byakbertherock
- UT Dallas Syllabus for math2418.501.09f taught by Istvan Ozsvath (ozsvath)Uploaded byUT Dallas Provost's Technology Group
- Simulink Design Optimization - Getting Started GuideUploaded bys_b_stojanovic

- LED2Uploaded byapi-19807868
- Nostromo_NTUploaded byapi-19807868
- Light emitting diodeUploaded byapi-19807868
- love me little love me longUploaded byapi-19807868
- LED1Uploaded byapi-19807868
- War_and_Peace_NTUploaded byapi-19807868
- fiber_opticUploaded byapi-19807868
- The_Thirty-Nine_Steps_NTUploaded byapi-19807868
- Signals.and.systems.made.simple.Karu.2001.scanUploaded byapi-19807868
- Paradise_Lost_NTUploaded byapi-19807868
- Beyond_Good_and_Evil_NTUploaded byapi-19807868
- The_Portrait_of_a_Lady_NTUploaded byapi-19807868
- Optical_Fibre_Communications-senoirUploaded byapi-19807868
- The_Red_Badge_of_Courage_NTUploaded byapi-19807868
- optical devicesUploaded byapi-19807868
- scada procureUploaded byapi-19807868
- Biomedical signal processingUploaded byapi-19807868
- Microwave Engineering 3e - David M Pozar - Solutions ManualUploaded byapi-19807868
- SMS GSM HANDBOOKUploaded byapi-19807868
- John.Wiley.&.Sons.WiMAX-Technology.for.Broadband.Wireless.Access.2007Uploaded byapi-19807868
- biomedicalUploaded byapi-19807868
- theory_microwave_technologyUploaded byapi-19807868
- Top_Images_2008Uploaded byapi-19807868
- Electronic Imaging DevicesUploaded byapi-19807868
- IPRoutingtraceUploaded byapi-19807868
- BioMedical EnggUploaded byapi-19807868
- Digital ElectronicsUploaded byapi-19807868
- encf_7Uploaded byapi-19807868
- Innovation on Medical ElectronicsUploaded byapi-19807868