93 views

Uploaded by farhanfendi

- MatlabSimulinkIntro
- Introduction Tom at Lab
- e4man.pdf
- curso de matlab.pdf
- pertemuan 2
- Matlab Introduction
- Introduction to Matlab
- Laboratory Manual
- Introduction to Matlab
- A1_MATLAB.doc
- simulink
- Lab1
- Help Mathlab 7
- matlab_zakl_sig_e
- MATLAB1
- sudokuSolver
- companion
- NAbook Aug 2008
- Matlab and Simulink
- MEC417_ELE 317 Control Systems Laboratory# 1

You are on page 1of 5

Semester I, 2016/2017 Due date: March 7, 2017

Learning Familiarize with the Matlab environment and running some basic Matlab

Objectives: commnds in Matlab

Equipment Matlab

Required:

The functional unit of data in any Matlab program is array. An Array is a collection of data

values organized into rows and columns and known by a single name.

Arrays can be classified as either vectors or matrices. The term VECTOR is usually used to

describe an array with only one dimension. While the term MATRIX is usually used to describe

an array with two or more dimensions.

Size of array is specified by the number of rows and the number of columns in the array, with the

number of rows mentioned first. The total number of elements in the array will be the product of

the number of rows and the number of columns.

Try using these values:

[3.4]

[1.0 2.0 3.0]

[1.0; 2.0; 3.0]

[1, 2, 3; 4, 5, 6]

[1, 2, 3, 4, 5, 6]

[]

Not all the elements of an array need to be defined when it is created. If a specific array

element is defined and onwe or more of the elements before it are not, then the earlier

elements are automatically created and initialized to zero. For example, if c is not previously

defined, the statement

C(2,3)=5

Will produce matrix 0 0 0

005

d(4)=4

will produce d=[1 2 0 4].

Initializing with shortcut expressions

Matlab provides a special shortcut notation for these circumstances using the COLON

operator. The colon operator specifies a whole series of values by specifying the first vales in

the series, the stepping increment and then the last value in the series. The general form of a

colon operator is

First: increment: last

For example

x=1:2:10

will generate x= 1 3 5 7 9

Try using angles=(0.01:0.01:1.00)*pi;

Transpose Operator():

This operator swaps the rows and columns of any array that it is applied to.

For example try using:

F=[1:4]

And F=[1:4]

Initializing with Built-in functions:

Try using these:

A=zeros(2)

B=zeros(2,3)

C=[1 2; 3 4]

D=zeros(size(C))

E=ones(3)

Ones(3,1)

Eye(3)

Eye(3,2)

Length(C) //Generate the longest dimension of the array.

Zeros can be used to create an all zero array of any desired size. If function has a single

square array; it will generate a square array using the single argument as both the number of

rows and columns. size function returns two values containing the number of rows and

columns in an array.

Initializing variables with keyboard input:

Input function displays a prompt string in the command window and then waits for the user

to type in a response. For example , consider the following statement:

My_val=input(enter an input value);

Multidimensioanl Array

Matlab allows us to create arrays as many dimensions as necessary for any given problem.

These arrays have one subscript for each dimension and an individual element in the array

will be the product of the maximum value of each subscript. For example the following two

statements create a 2X2X3 array C:

C(:,:,1)=[1 2 3; 4 5 6];

C(:,:,2)=[7 8 9; 10 11 12];

Whos C

End Function:

It is very useful for creating array subscripts. When used in an array subscript; end returns

the highest value taken on by that subscript. For example. Suppose that array arr3 is defined

as follows:

Arr3=[ 1 2 3 4 5 6 7 8];

Then Arr1(5:end) would be the array [5 6 7 8] and array(end) would generate 8.

The value returned by end is always the highest value of a given subscript. Is end appears in

different subscripts, it can return different values within the same expression. For example,

suppose that the 3X4 array Arr4 is defined as follows:

Arr4=[1 2 3 4; 5 6 7 8; 9 10 11 12];

Then the expression

Arr4(2:end, 2:end)

would return the array.(Try this one).

TASKS

Question # 01:

This M-file calculates and plot the function sin(x) for 0<=x<=6

X=0:0.1:6;

Y=sin(X);

plot(X,Y);

plot(X,Y)

Question # 02:

The following Matlab statement plot the function y(x)=2e-0.2x for the range 0<=x<=10

X=0:0.1:10;

Y=2*exp(0.2*X);

Plot(X,Y);

Question # 03:

suppose that u=1 and v=3. Evaluate the following expressions using Matlab.

(a) 4u/3v

(b) 2v-2/(u+v)2

(c) v3/v3-u3

(d) 4/3 pi.v2

Question # 04:

(a) Generate a 6X6 Matrix.

(b) Generate a 6X1 Matrix

(c) Generate a 3X4 Matrix

Question # 05

Answer the following questions for the array shown below.

1.1 0.0 2.1 -3.5 6.0

0.0 1.1 -6.6 2.8 3.4

1.1 0.1 0.3 -0.4 1.3

-1.4 5.1 0.0 1.1 0.0

(a) what is the size of the array?

(b) What is the value of the array(4,1)?

(c) What is the size and value of array( : , 1 : 2 )?

(d) What is the size and Value of the (array[1 3],end)?

Question # 06

Are the following Matlab variable names legal or illegal? Why?

(a) dog1

(b) 1dog

(c) Do_you_know_the_way__to_kuala lampur

(d) _help

Example : Here are three ways to create an array xp which has 11 equally spaced samples from 0

to : (a) use xp=[ 0: pi/l0: pi ] directly; (b) first create an array equally spaced between 0 and 1

then multiply it by ; (c) use linspace function:

xp=[0:pi/10:pi]

xp[0:0.1:1]*pi

xp = linspace(0,,11)

If not stated otherwise, all vectors in MATLAB are indexed starting from 1, e.g., x( 1) is the

first element of vector x. Thus, in order to represent a signal with negative or zero time index,

an additional index vector should be defined. The following code will define a discrete-time

signal x[n]=2n, for n = 3,..,3:

x=2*n;<ret>

plot(n,x)<ret> % This command is to show the vector x[n] graphically

In MATLAB both stem and plot can be used to plot a signal. The difference between

these two functions can be seen by typing the following example:

x1 =n1>=-2&n1 <2;

x2=sin(n2);

subplot(2, 1,1), stem (n1,x1)

subplot(2,1,2), plot (n2,x2)

Question # 07

Evaluate the following expressions (remember to include numerical answers in the result section

and executable MATLAB code as attachment of your report):

(b) convert y in part (a) from radians to degrees

(c) c4 = 6+ j sin(0.5) + c (using c =1 )

(d) c5 = real part of c4

Question # 08

Exchange the stem and plot functions in the example, and watch the results.

Explain the advantages and disadvantages of each function.

The following example describes the process of creating a sampled sinusoidal signal:

Example 5: Evaluate sin(pi*x) from 0 to 1 using a sampling period of 0.1: create an array for the

argument of sine,

length(x) % returns the length of the array x

xp = x*pi,. % multiply each element of the array bypi

length(xp)

xp(3) % refers to the third element in the xp array only

xp(2:6) % references the second through sixth element of the xp array

y= sin(xp);<ret>

length(y)< ret>

xlabel(' theta' );

ylabel(function value);

title(Sampled Sine Function for Example VIII);

close

Question # 09

Create and plot the following signals using sampling rate l0 Hz (i.e. 10 samples per second).

Include the plots in your report:

a. y1 = cos(5t);

b. y2 = 2exp(2t)*cos(5t);

c. add a noise scaled by 0.2 on y1.

(use function randn, and type help randn if you dont know how to use it).

- MatlabSimulinkIntroUploaded bybdeepesh
- Introduction Tom at LabUploaded byamitaiisc
- e4man.pdfUploaded byrokhgireh_hojjat
- curso de matlab.pdfUploaded byDaniel Tosi
- pertemuan 2Uploaded byMichael_Wollo
- Matlab IntroductionUploaded byJayanth Bhargav
- Introduction to MatlabUploaded byHassaan Shah
- Laboratory ManualUploaded byPaul
- Introduction to MatlabUploaded bydadado98
- A1_MATLAB.docUploaded byAziful Aieman
- simulinkUploaded bydpksobs
- Lab1Uploaded byAli Ahmad
- Help Mathlab 7Uploaded byMohammad Pichan
- matlab_zakl_sig_eUploaded bySangya Singh
- MATLAB1Uploaded bysonamrishikapoor
- sudokuSolverUploaded byAlan Richards
- companionUploaded byAlberipa
- NAbook Aug 2008Uploaded byRohit Dhir
- Matlab and SimulinkUploaded byOnur Kımıllı
- MEC417_ELE 317 Control Systems Laboratory# 1Uploaded byAmir Dillawar
- S Sztendel PaperUploaded bySagarias Albus
- MSUM CH1 Concepts.pptxUploaded byMario H Perez
- MatrizUploaded byLuigi MJ
- Grade2Module6AnswerKey (1)Uploaded bygrace sanchez
- FARMERS TURNED INTO BRICK WORKERS: A STUDY ON THEIR SOCIAL STATUS CHANGEUploaded byIntegrated Intelligent Research
- Lab No 10 to mail.docxUploaded byanimeshkumarverma
- Business Applications of Matrices ProjectUploaded byMaria Pugh
- Matlab Notes 2013Uploaded byJorge Hirs
- How to rewrite multivariate random functions as univariate to do cokriging. A flexible algorithmUploaded byJose Maister
- matlabUploaded byvsalaiselvam

- Intermediate Micro With Calc. ProblemsUploaded byDunbar Anders
- Stampingjournal20131112 DlUploaded byWaqar Mansoor
- Tank Services ELECTRONICUploaded byNeruda
- Ti Nspire Cx CasUploaded byols3d
- Facial Expressions Are Contagious Lundqvist 1995Uploaded byPaula Santos Garrido
- Clayards_diss_07-20-08Uploaded byRevisão Textual
- pbs nova secrets of the psychicUploaded byapi-323453767
- Applying to Hofstra for Undergraduate Admission as a Transfer StudentUploaded byHofstraUniversity
- Physical Properties HDPE PE3408Uploaded byDanny Milton Silva Vasquez
- EPRI-DOE Handbook of Energy Storage for TransmissionUploaded bySAEIDKIAN
- Shamanism and Alien Abductions - A Comparative StudyUploaded byMaurício Eloy
- Nonlinear Continuum Mechanics for Finite Element AnalysisUploaded byDebangaRajNeog
- WaukeshaUploaded byOmar Alexander Cañon Ortegon
- U.S. Immigration: Economic Effects and Policy ImplicationsUploaded byGerman Marshall Fund of the United States
- Transfer Cassette Tape to Computer - Easy Steps - 2.pdfUploaded byKathir
- hardness-preheat.pdfUploaded bydanghp
- UpdateonASNTACCP.pdfUploaded byAnonymous m43RBxOVZ2
- CEO COO CKO Senior Vice President in Washington DC Resume Robert BairdUploaded byRobertBaird1
- SM4125-07Uploaded byNguyen Huu Hanh Lam
- VLSI Design Lab NewUploaded bymtariqanwar
- BX53M BXFMUploaded byRepresentaciones y Distribuciones FAL
- Stilling BasinUploaded byale hopeju2009
- Rotary screw air compressorsUploaded byJako Mishy
- Concept Basd Text MiningUploaded byraj
- Electrical MCQSUploaded byMuhammad Azhar Iqbal
- EJERCICIOSIUploaded byRossana María López Viramontes
- aaUploaded byAtul Garg
- Load Balancing Techniques Major Challenges in Cloud Computing a Systematic ReviewUploaded byAmr Elmestekawi
- Batch Smart Test Setup v1.0Uploaded byAshwin Reddy
- Electronic Skin My PresentationUploaded byJayalekshmi Sivan