matlab (1)
matlab (1)
EXPERIMENT – 1
Objective – Introduction to MATLAB : To define and use variables,
vectors, matrices and its functions in MATLAB.
The name MATLAB stands for MATrix LABoratory. MATLAB was written
originally to provide easy access to matrix software developed by the LINPACK
(linear system package) and EISPACK (Eigen system package) projects.
When you start MATLAB, a special window called the MATLAB desktop appears.
The desktop is a window that contains other windows. The major tools within
or accessible from the desktop are:
The Workspace
1
SOFTWARE WORKSHOP
When MATLAB is started for the first time, the screen looks like the one that
shown in the Figure 1.1. This illustration also shows the default configuration of
the MATLAB desktop. You can customize the arrangement of tools and
documents to suit your needs.
2
SOFTWARE WORKSHOP
INPUT :
OUTPUT :
3
SOFTWARE WORKSHOP
Multiple assignment
To recall or use the variable we can simply enter the variable in equation
or directly on command prompt and they will be used directly.
VECTORS:
A vector is a one-dimensional array of numbers. MATLAB allows
creating two types of vectors −
Row vectors
Column vectors
Row vectors are created by enclosing the set of elements in square
brackets, using space or comma to delimit the elements.
INPUT :
OUTPUT :
4
SOFTWARE WORKSHOP
5
SOFTWARE WORKSHOP
6
SOFTWARE WORKSHOP
EIGEN VALUES :
7
SOFTWARE WORKSHOP
EXPERIMENT – 2
Objective – To study various arithmetic operators and mathematical
functions in MATLAB.
MATLAB allows two different types of arithmetic operations −
Matrix arithmetic operations
Array arithmetic operations
Matrix arithmetic operations are same as defined in linear algebra. Array
operations are executed element by element, both on one dimensional and
multi-dimensional array.
The matrix operators and arrays operators are differentiated by the period (.)
symbol. However, as the addition and subtraction operation is same for
matrices and arrays, the operator is same for both cases.
The following table gives brief description of the operators −
8
SOFTWARE WORKSHOP
9
SOFTWARE WORKSHOP
CODE :
10
SOFTWARE WORKSHOP
Mathematical Functions :
MATLAB provides a wide variety of mathematical functions in your
computations — from basic functions, such as sine and cosine functions, to
special functions, such as the Riemann zeta function and Bessel functions.
Logarithms Functions:
log - Natural logarithm of entries of symbolic matrix
log10 - Log base 10 of symbolic input
log2 - Base-2 logarithm of symbolic input
Trigonometric Functions:
sin Symbolic sine function
sinc Normalized sinc function
cos Symbolic cosine function
tan Symbolic tangent function
cot Symbolic cotangent function
sec Symbolic secant function
csc Symbolic cosecant function
Similarly inverse trigonometric functions such as asin , acos , atan , acot , asec
and acsc.
Their Integrals and differential functions and also special functions such as
Direcdelta , Heaviside , Rectangular pulse , Triangular pulse and so on.
11
SOFTWARE WORKSHOP
EXAMPLE CODE :
12
SOFTWARE WORKSHOP
EXPERIMENT – 3
Objective – Write a MATLAB program to plot 3-dimension and 2-
dimension figure.
Create a two-dimensional line plot using the plot function. For example, plot
the value of the sine function from 0 to 2π.
CODE:
PLOT :
13
SOFTWARE WORKSHOP
Cosine Function
CODE :
PLOT :
14
SOFTWARE WORKSHOP
Tangent Function
CODE :
PLOT :
15
SOFTWARE WORKSHOP
Also we can plot graph or 2 – dimensional figure by values with help of array.
Example:
CODE :
PLOT :
16
SOFTWARE WORKSHOP
PLOT:
17
SOFTWARE WORKSHOP
CODE :
PLOT :
18
SOFTWARE WORKSHOP
SUB – PLOT :
Subplot(m,n,p) divides the current figure into an m-by-n grid and creates axes
in the position specified by p.
Code :
PLOT :
19
SOFTWARE WORKSHOP
3 – Dimensional plots :
Some examples of plotting 3 – D plots are:
Code :
PLOT :
20
SOFTWARE WORKSHOP
SPHERE:-
CODE :
PLOT:
21
SOFTWARE WORKSHOP
EXPERIMENT – 4
Objective – Write a MATLAB program to plot pie chart and bar graph.
Pie Chart : Pie chart creates a pie chart of the values in the vector data.
Each slice has a label indicating its size as a percentage of the whole
pie.
CODE :
PLOT :
22
SOFTWARE WORKSHOP
Bar Graph : Bar creates a bar graph with one bar for each element in y.
CODE :
PLOT :
23
SOFTWARE WORKSHOP
PLOT :
24