You are on page 1of 24

# MATLAB

PRACTICAL FILE

SUBMITTED
BY:NISHANTKUMAR

## ROLL NO: 14513303612

MAE-B

INDEX
S.NO NAME OF
EXPERIMENT
1.
2.
3.
4.
5.

6.

7.
8.
9.

Introduction to
matlab.
Basic matrix
operations.
Plot and solve
various
functions
Basic 2-D and
3D plots.
To find closed
loop transfer
function of
system
To generate sine
wave,cosine
wave and
exponential
curve.
Plot the transfer
function
Open loop
transfer
function
To find root
locus for given
system.

PAGE DATE OF
DATE OF
REMARKS
NO.
EXPERIMENT SUBMISSION
12/08/14
19/08/14
19/08/14

26/08/14

26/018/14

2/09/14

2/09/14

9/09/14

9/09/14

16/09/14

16/09/14

23/09/14

23/09/14

30/09/14

30/09/14

07/10/14

07/10/14

14/10/14

Experiment -1
Introduction to matlab
Matlab :

## Is a high performance, high level language.

Stands for matrix laboratory
Can be used as a fancy calculator
Allows you to easily work with entire matrices rather than one number at a time
Is useful for anything that requires matrix and vector manipulation such as :
i) Mathematical, scientific, engineering ,statistical and financial problems
ii) Anything that requires plotting/visualizing and analyzing data
Comes with a basic set of tools for visualizing data for performing calculations on
matrices and vectors
i) for specific technologies , MATLAB provides toolboxes, which add to the basic
MATLAB functionality. We have the image processing toolbox.
Some other toolboxes include:
(1) statistics toolbox
(2) neural network toolbox
(3) fuzzy logic toolbox
(4) signal processing toolbox
(5) wavelet toolbox
(6) financial toolbox
(7) bioinformatics toolbox
(8) Database toolbox

## MATLAB Graphical user interface

Matlabs graphical interface is written in java and should be look similar on any OS. It is
divided into 4 main parts :

## command window this is where you type commands.output or reeor messages

usually appear her too.
Workspace window as you define new variables,they should be listed here.
Command history window this is where past command are remembered .if you
want to re-run previous command or to edit it you can drag it from this window to
the command window or double click to re-run it.
Current directory window shows the files in the current directory.
The M-files

The edit command in the above section shows you a very basic M files for the
acosd

## fuction. The following is meant to summarize M flies:

(a) M-Files are text with MATLAB code
(b) M files have a .m extension

SCALAR VARIABLES:
Scalars
In matlab a scalar is a variable with one row and one column. Scalars are the simple
variables that we use and manipulate in simple algebraic equations.
Creating scalars
To create a scalar you simply introduce it on the left hand side of an equal sign.
>>x=1;
>>y=2;
>>z=x+y;
Scalar operations
Matlab supports the standard scalar operations using an obvious notation. The following
statements demonstrate scalar addition, subtraction, multiplication and division.
>> u=5;
>>v=3;
>>w=u+v
>>x=u-v
>>y=u*v
>>z=u/v
Vectors:
In matlab a vector is a matrix with either one row or one column.the distinction berween
row vector and column vector is essential . many programming errors are causedby
using a row vector where a column vector is required ,and vice versa.
MATLAB vector are used in many situations, e.g,creating x-y plots, that do not fall under
the rubric of linear algebra. In these con texts a vector is just a convenient data
structure.

MATLAB still enforces the rules of linear algebra so paying attention to the details of
vector creation and manipulation is always important.
Creating vectors
To create a vector you simply introduce it on the left hand side of an equal sign. Of
course this means that the expression on the right side of the equal sign must evaluate
to a vector . There are numerous ways to actually create a vector, each one having

## Using the built- in fumnctions ones, zero,linespace and log space

Assigning a mathematical expressions involving vectors
Appending elements to a scalar
Using colon notation
Vector operations
Mathematical operations involving vectors follow the rules of linear
algebra. Addition and subtraction of vectors is performed with the +and
operators .
Operations with scalars
Vector transpose
Vector multiplication
Element-wise vector operations
Passing vectors to built-in functions.

EXPERIMENT-2
AIM: BASIC MATRIX OPERATION

## (1) CREATING A MATRIX.

A= [1 2 0;2 5 -1;4 10 -1]
A=
1 2
0
2 5
-1
4 10 -1

B=A
B=
1 2 4
2 5 10
0 -1 -1

C= A*B
C=
5 12 24
12 30 59
24 59 117

Eig(A)
Ans=
3.7321
0.2679
1.0000

EXPERIMENT -3

## Aim: Plot of basic functions in matlab.

1. Y(x)= sin(xcosx /x2 + 3x +1)
For the values of x from one to three step of 0.02.
x= 1:0.02:3;
g= x.*cos(x);
g= x.^2+ 3*x +1;
y= sin(f./g);

Y= x3 -3x2 + 2X
r= [1 -3 2 0];
c= roots(r);
Ans=[0,2,1]

3.

## f(x)= x2cosx/(x3+1)(x +2)

X= linspace(0,10,200);
g= x.^3+1;
h=x+2;
z= x.^2;
y= cos(x.*pi);
F=y*z./g*h;

X2 COSX/(X3+1)(X+2)

EXPERIMENT -4
AIM:BASIC 2-D AND 3-D PLOTS.

## 1. Plot f(x) = e-x/lO sin(x) for x between 0 and 20.

PROGRAM:
fplot('exp(-.l*x) . *sin(x) ', [0 , 20])
xlabel('x'),ylabel('f(x) ; e-{x/10} sin(x) ')
title('A function plotted with fplot')

## 2. Plot f(x) = et/lO sin(t) for x between 0 and 20.

> X = 0 : . l. : 2. 0 ;
y = exp(O.l*x) .*sin(x);
plot (x, y)
x1abel (I Time (t) in Sedorids1)
ylabel (I The Response Amplitude in mtn I)
title ( 1 A Simple 2 -D Plot 1 )

## 3. plot r() = 1 + 2sin2() for 0 < < 2

PROGRAM:
r = inline('1+2*(sin(2*t)).-2');
ezpolar(r)

## 4. plot x(t) = tcos(3t), y(t) = tsin(3t), and z(t) = t over the

default domain.
PROGRAM:
x = 't.*cos(3*pi*t) ';
y = 't.*sin(3*pi*t)';
z = 't ';
ezplot3(x,y,z)

EXPERIMENT-6
1.Program to generate sine wave

## f= input('enter the frequency in hertz of the sine wave');

t=0:.0001:5;
y=sin(2*pi*f*t);
plot(t,y);
ylabel ('Amplitude');
xlabel ('Time Index');
TITLE ('Sine wave');

## f= input('enter the frequency in hertz of the sine wave');

t=0:.0001:5;
y=cos(2*pi*f*t);
plot(t,y);
ylabel ('Amplitude');
xlabel ('Time Index');
TITLE ('cosine wave');

## 3. Program to generate the exponential sequence

n=input('Enter the duration of the signal N = ');
a=input ('Enter the scaling factor a = ');
t=0:.1:n-1;
y=exp(a*t);
plot(t,y);
ylabel ('Amplitude');
xlabel ('Time Index');
TITLE ('Exponential Signal');