Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

INTRODUCTION LAB

OBJECTIVES:To learn about different commands and some uses of MATLAB.

COMMANDS:VECTOR ADDRESSING:
To define a vector in matlab first chose a variable and then give it a value.i.e (both
have same results.)
V=[1 2 3 4 5 6 7 8 9 10]

&

V=1starting point:1increment:10ending point

EXAMPLES:
To make a new vector from two vectors first define these two and then
A=[1 2 3]

&

Now

C=[A+B]

The result is

C=[1 2 3 4 5 6]

B=[4 5 6]

To use any value of vector as a new variable write


C(1)=1 , A(2)=2 & B(3)=6
FOR MATRICES:To create a matrix in matlab first chose a variable and then give it a value.

EXAMPLES:
1):

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

If X(1,:)

it used to extract first row of matrix.

If X(|:,1)

it used to extract first column of matrix.

2): To create a matrix such that its all entries should be zero or one then write

For all zero entries and any order

For all zero entries and any order

Zeros(n) & Zeros(n,m)

Ones(n) & Ones(n,m)

Where n & m both are integers. :

Where n & m both are integers.

3): If we have a matrix A then to find the size of that matrix we use command
[
Size(A)
]
4): For transpose of a matrix A we use command

[ B=A ]

5): To create an identity matrix we use command

[eye(n,m)]

6): For diagonal of a matrix we use command

[diag(A)]

7): For upper triangular we use command

[triu(A)]

8): For lower triangular we use command

[tril(A)]

9): For Inverse of matrix A we use command

[inv (A)]

(matrix should be square)


10): To find the determinant of a matrix we use command [Det(A)]
11): To take the power of the entries of the matrix we use command [A.^2]
12): For multiplying entry by entry in matrices we use command [x=A.*B]

Plotting:If we want to plot two vectors i.e. consider two arbitrary


values to the variable.

Examples:
1):

t=1:0.1:10

&

y=cos(t)

then

plot(tfor x-axis ploting,yfor y-axis ploting)

[It is for continues function]

stem(tfor x-axis ploting,yfor y-axis ploting)

[It is for discrete function]

2): For plotting more than one graph on the same graph-window we use
[

plot(t1 y1 t2 y2)

3): For plotting more than one graph on the same graph we use
[

subplot(2rows ,2colomns ,1patches)

4): For changing the scale of axis we use command [ axis(xmini xmax , ymini ymax) ]
5): For labeling on a graph we use command
[xlabel(time) , ylable(amplitude)

&

title(vector)]

6): To change the color of graph we use command

plot(t,y,r)

7): For making a grid on the graph we use command

grid

Complex:If we have a complex number i.e ( z=a+ib ) then


Examples:
1): To find its imaginary part we use command

[ imaginary (z)]

2): To find its real part we use command

[ real(z)]

3): To find angle we use command

[ angel(z)]

4): To take conjugate of it we use command

[ conj(z)]

LAB TASK:1): Plot a sine wave for

f=10Hz

First to plot this wave we have to find the time period from frequency of 10Hz.
So

T=1/f

T=1/10

T=0.1

Coding for given task:


t=1:0.1:10
y=sin(t)
plot(t,y)
xlabel(Time)
ylabel(Amplitude)
title(Sine Wave)
2): Plot a sine wave with amplitude=1, f=10KHz & sampling
frequency=20KHz
Now again the time period is
T=1/f

T=1/20000

T=0.0002

t=[0:0.0002:0.2];
A=1;
f=10000;
y=A*sin(2*pi*f*t);
plot(t,y)

Conclusion:In this lab we learn about some basic commands of matlab.i.e. ploting
of vectors, sinosiod signals(continues time & discrete time signals), matrices and
complex numbers. We attempt their different methods of initiating and some
examples. At the end of this lab, two tasks were given which were performed
successfully.
Now after performing this lab I am able to use matlab with its basic commands.

Assignment
Title :

You might also like