0% found this document useful (0 votes)
9 views

MATLAB-1

Uploaded by

bharatbhushan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

MATLAB-1

Uploaded by

bharatbhushan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 27

• PRACTICAL FILE

• OF
• IT MATLAB

SUBMITTED TO:

SUBMITTED BY:
Ms Antim ma’am Name
= Ankit Kumar
(Roll
Number) =
DEPARTMENT OF COMPUTER SCIENCE
AND ENGINEERING ARAVALI COLLEGE OF
ENGINEERING AND MANAGEMENT
FARIDABAD-121002

INDEX

EXPERIMENT NO:1
A I M : Study of introduction of MATLAB.

• INTRODUCTION:
The name MATLAB stands for Matrix Laboratory. The basic building block of
MATLAB is the matrix. It is not confined to the solution of Matrix related
problems. With its inbuilt functions, it is an excellent tool for linear algebraic
computations, data analysis, signal processing, optimization, numerical solutions
of ordinarydifferential equations (ODE), quadrature, 2D & 3D, graphics and many
other types of scientific computation. Therefore, we can say:
MATLAB is a software package in high performance language for technical
computing. It integrates computation, visualization and programming in an easy to
use environment where problems and solutions are expressed in familiar
mathematical notation. Typical uses include:
• Math and computation
• Algorithm and development
• Data acquisition modeling
• Simulation and prototyping
• Data analysis, exploration, and visualization
• Scientific and engineering graphics
• Application development, including graphical user interface building.
• BASICS:

MATLAB WINDOWS: There are three basic window which are as


follows:
• Matlab Desktop: This is the window which appears by default when
MATLAB is launched. It consists of :
• Command Window: This is the main window , where
command are written. It is characterized by MATLAB
command prompt (>>). The results also appear on this
window(except figures, which appear on figure window)
which command is written. Commands cannot be edited in
this window.
• Current Directory: This appears on the bottom left side of
MATLAB desktop. It is where all files are listed. With a
mouse right click, you can run M-files, rename, delete them
etc after selecting a file from here.

• Workspace: This sub-window shows all the variables


generated so far and also shows their type and size.
• Command History: All commands typed on the MATLAB
prompt are recorded here. Also commands can be selected
from here and create as M-file. Thus it remains records of
MATLAB functions run.
• Figure Window:The output of all the commands written on
the command window or executed by writing in M-file,
whose output is a graph , appears on the window. The user
can create as many figure windows as the system memory
allows. A figure window is showing sine curve is shown in
figure.
• Editor Window:This is where we can write, create, edit
and save programs in a file. The file is known as M-file. To
select editor window, go to file and then select M-file. The
programmes written on the file are first saved and then run
to get the results. To save and run the programme, go to
debug and select ‘save and run’. The result appear on the
command window. The figure appear on the figure window.
A editor window is shown as in figure:
LANGUAGES:
MATLAB is a high-level language that includes matrix-based data structures, its
own internal data types, an extensive catalog of functions and scripts, the ability
to import and export to many types of data files, object-oriented programming
capabilities, and interfaces to external technologies such as COM, Java, program
written in C and Fortran, and serial port devices.

INPUT-OUTPUT:
MATLAB takes input from the screen and rushes output to the screen i.e. it supports
interactive computation. It can read input files and write output files.

• Data Type: There is no need to declare a data to be real or


complex. When a real number is entered as a variable,
MATLAB automatically sets the variable to be real.
Fundamental data type is the array.
• Dimension: Dimension state is not required in the MATLAB. It is
automatic.
• Case Sensitivity: It differentiates between lower and upper cases. It
is case sensitive.
• Output Display: The output of every command appears on the
screen unless MATLAB is directed otherwise. A semi-colon(;)
suppress the output when used at theend of a command except
for the graphics.
GETTING STARTED:
Starting Matlab: On windows platform, start MATLAB by
double clicking the MATLAB shortcut icon on your
Windows desktop.
Writing Command: When you start MATLAB, the
MATLAB desktop appears containing tools for managing
files, variables, and applications associated with MATLAB.
You can start writing your command at the prompt appears
on command Window. You can also write command in M-
file.
Printing Graphics: The simplest way to get print out of the
graph is to typeprint command window after the graph
appears in the figure window. Alternatively activate the
figure window and then select print from the file menu.
Quiting Matlab: To end your MATLAB session, select file
>Exit MATLAB in the desktop or type quit in the command
window. You can run a script file named finish.m each time
MATLAB quits that, for example, executes function to save
the workplace, or display a quit confirmation dialog box.

• ACCESSORIES:

• Toolbox: MATLAB features a family of add-on-


application- specific solutions called toolboxes. Very
important to most users of MATLAB , toolboxes allow
you to learn and apply specialized technology. Toolboxes
are comprehensive collections of MATLAB environment
to solve particular classes of problems. Areas in which
toolboxes are available include signal processing, control
systems, neural networks, fuzzy logic, wavelets,
simulation, and many others. There are 78 toolboxes
available. Thus we can say MATLAB basically works as a
platform and for solving a particular problem,
concerned toolbox is required. Few of the toolboxes are as
follows:

• Communication toolbox

• Control system toolbox

• Curve fitting toolbox

• Data acquisition toolbox

• Filter design toolbox

• Instrument control toolbox

• Optimization toolbox

• Symbolic maths toolbox, etc.

• Simulink: Simulink is a software package that enables you to


model, simulate, and analyze systems whose outputs change over
time. Such system are often referred to as dynamic systems.
Simulink can be used to explore the behavior of a wide range of
real- world dynamic systems, including electrical circuits, shock
absorbers, braking systems, and many other electrical, mechanical,
and thermodynamic system. This section explains how Simulink
works. Simulating a dynamic system is a two step process with
Simulink. First, a user creates a block diagram, using a block
diagram Simulink model editor that graphically depicts time
dependent mathematical relationship among the system’s inputs,
states, and outputs. The user then commands simulink to simulate
the system represented by the model from a specified start time to a
specified stop time.
EXPERIMENT NO:2

AIM : How To Make A Matrix Using Different Method In MATLAB.

THEORY : A matrix is a rectangle arrangement of no. into rows , column. The


dimension of the matrix tells its size that is no. of rows , column of matrix in that order.
MATLAB allows you to process or of the values in a,mat- rix using a single arithmetic
operations or functions.

IMPLEMENTATION :

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


b=[4 5 6 3; 4 5 6 7 ;3 4 5 7]
a
=
m

b
=
b
'

c
=
i
n
v
(
m
)
d
=
d
e
t
(
m
)
e
=
e
i
g
(
a
)

OUTPUT :

>

>

7 8 9 5
5 6 7 6
10 11 12 7
2 3 4 1

b=
4 5 6 3
4 5 6 7
3 4 5 7
>> marteix

m =

7 8 9 5
5 6 7 6
10 11 12 7
2 3 4 1

b =

4 5 6 3
4 5 6 7
3 4 5 7

b =

4 4 3
5 5 4
6 6 5
3 7 7

>> marteix

m =

7 8 9 5
5 6 7 6
10 11 12 7
2 3 4 1

b =

4 5 6 3
4 5 6 7
3 4 5 7

b =

4 4 3
5 5 4
6 6 5
3 7 7

c=

1.0e+15 *

1.6908 -0.1537 -0.9991 -0.5380


-3.3815 0.3074 1.9982 1.0759
1.6908 -0.1537 -0.9991 -0.5380
0.0000 0.0000 -0.0000 -0.0000
>
>

m
a
t
r
i
x

7 8 9 5
5 6 7 6
10 11 12 7
2 3 4 1

b =

4 5 6 3
4 5 6 7
3 4 5 7

a =

7 8 9 5
5 6 7 6
10 11 12 7
2 3 4 1

b =

4 4 3
5 5 4
6 6 5
3 7 7
c=

1.0e+15 *

1.6908 -0.1537 -0.9991 -0.5380


-3.3815 0.3074 1.9982 1.0759
1.6908 -0.1537 -0.9991 -0.5380
0.0000 0.0000 -0.0000 -0.0000

d=

1.3012e-14

e=

27.4732
-0.0000
-0.4732
-1.0000

EXPERIMENT NO:3

AIM:To Implementation Of Various Operations On Matrix Using MATLAB.

THEORY: The matrix in a MATLAB is a type of variable that is a used for


mathematical computation purpose . MATLAB known as a matrix laboratory , efficiently
process matrix calculation. There are several mathematical & trigonometric computation
supported by a MATLAB software some arithmetic operation on the matrix in a MAT-
LAB are addition , subtraction, multiplication and division.

IMPLEMENTATION:-

a= [2, 4; 5, 7]
b= [4, 5; 7, 9]
c
=
a
+
b

c
=
b
-
a

c
=
a
'

c
=
a
*
b

OUTPUT:

a=

2 4
5 7

b=

4 5
7 9

c=

6 9
12 16

c=

2 1
2 2

c=

2 5
4 7
c=

36 46
69 88

EXPERIMENT NO:4

AIM : To Implement The If-Else Statement On MATLAB.

THEORY :If the statement execute code are statement block only when the condition is
true.It is a conditional programming keywords used to give condition’s to the program of
MATLAB. It has three part :-
• If statement
• Else statement
• Else-If statement.

IMPLEMENTATION :

a
=
2
0

b
=
3
0
if a>b
disp('a is 2');

elseif a==20
disp('a=20');

else end

disp('b is ');

e
=
e
i
g
(
b
)

t
=
e
i
g
(
a
)

i
f

e
>
b
disp('a matrix
is greater
=1,5,6'); else
disp('b is
greater');
end

OUTPUT :

>

>

o
n

20

b=

e=

30

t=

20

b is greater
>>

EXPERIMENT NO:5
AIM : To Implement the While Loop In MATLAB.

THEORY : An expression is true when the result is non- empty and contains and
contain’s all non zero element (logical or realnumeric).Otherwise the expression is false.

IMPLEMENTATION :

i=0
while i<10
i=i+1
end
A=inp
ut("En
ter the
value"
) i=
A
x
=

1
w
h
i
l
e

i
>
1
x
=
x
*
i

i
=
i
-
1

end

disp(A)

OUTPUT :

>

>

i
=

i =

i =

i =

i =

i =

i =

i =

i =

i =
9

i=

10

E
n
t
e
r

t
h
e

v
a
l
u
e
3

i=

x=

x=

3
i=

x=

i=

>>

EXPERIMENT NO:6

AIM : How To Make A Graph In MATLAB (Labeling , Title , Subplot).

THEORY :A graph is a non linear data structure consisting of vertices and edges .To plot a
graph of the function we need to take some steps.
• Define x by specifying the range of the value of the variable x.

• As a plot (x,y).

IMPLEMENTATION :

x =1:10
y

p
l
o
t
(
x
,
y
)
title(“h
ouse
price
graph”)
xlabel(
‘Price’)
ylabel(
‘House
’)

OUTPUT :

>> exp6

x=
2 3 4 5 6 7 8 9 10
1

y=

1 2 3 4 5 6 7 8 9 10

>>
EXPERIMENT NO:7

AIM : How To Make Function In MATLAB.

THEORY :Afunction is defined as a relationship between a set of inputs having one


output each.in simple word afunction is a relationship between inputs where each input is
related to exactly one output.every function has a dom- ain & co-domain or you can say
arrange.

IMPLEMENTATION :
function d= sum(a,b,c)
d=a+b+c
end
OUTPUT :

>> sum(1,2,3)

d=

ans =

>>

EXPERIMENT NO:8

AIM: How To Make And Write In Excel Sheet Using MATLAB.

THEORY:A excel sheet is a sheet also called work sheet. A sheet is a single page that
contain it’s on collection of sheet of sheet. To held to organize a data.There can be sheet in
your excel document & you can see the sheet instead.

IMPLEMENTATION:-
Value= {98,64,74;3,2,12;45,11,34;34,11,56}
xlswrite ('vishal.xlsx', value)

OUTPUT:

>> Value =

4×3 cell array

{[98]} {[64]} {[74]}


{[ 3]} {[ 2]} {[12]}
{[45]} {[11]} {[34]}
{[34]} {[11]} {[56]}

>>

EXPERIMENT NO:9

AIM: Certificate of MATLAB from Mathworks.

You might also like