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

matlab (1)

The document provides an introduction to MATLAB, covering its features, user interface, and basic operations with variables, vectors, and matrices. It explains the different types of arithmetic operations, mathematical functions, and how to create various plots including 2D and 3D figures, pie charts, and bar graphs. Additionally, it highlights the advantages of MATLAB in technical computing and its applications in teaching and research.

Uploaded by

bhupendramarmat4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

matlab (1)

The document provides an introduction to MATLAB, covering its features, user interface, and basic operations with variables, vectors, and matrices. It explains the different types of arithmetic operations, mathematical functions, and how to create various plots including 2D and 3D figures, pie charts, and bar graphs. Additionally, it highlights the advantages of MATLAB in technical computing and its applications in teaching and research.

Uploaded by

bhupendramarmat4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

SOFTWARE WORKSHOP

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.

MATLAB is a high-performance language for technical computing. It integrates


computation, visualization, and programming environment. Furthermore,
MATLAB is a modern programming language environment: it has sophisticated
data structures, contains built-in editing and debugging tools, and supports
object-oriented programming. These factors make MATLAB an excellent tool for
teaching and research.

MATLAB has many advantages compared to conventional computer languages


(e.g., C, FORTRAN) for solving technical problems. MATLAB is an interactive
system whose basic data element is an array that does not require
dimensioning. The software package has been commercially available since
1984 and is now considered as a standard tool at most universities and
industries worldwide.

It has powerful built-in routines that enable a very wide variety of


computations. It also has easy to use graphics commands that make the
visualization of results immediately available. Specific applications are collected
in packages referred to as toolbox. There are toolboxes for signal processing,
symbolic computation, control theory, simulation, optimization, and several
other fields of applied science and engineering.

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 Command Window

The Command History

The Workspace

1
SOFTWARE WORKSHOP

The Current Directory

The Help Browser

The Start button

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.

User interface in MATLAB

It is both a programming language as well as a programming


environment. It allows the computation of statements in the command
window itself.

 Command Window: In this window one must type and


immediately execute the statements, as it requires quick
prototyping. These statements cannot be saved. Thus, this is can
be used for small, easily executable programs.

 Editor (Script): In this window one can execute larger programs


with multiple statements, and complex functions These can be
saved and are done with the file extension ‘.m ‘

2
SOFTWARE WORKSHOP

 Workspace: In this window the values of the variables that are


created in the course of the program (in the editor) are displayed.

 Command History window : This window displays a log of


statements that you ran in the current and previous MATLAB
sessions. The Command History lists the time and date of each
session in the short date format for your operating system,
followed by the statements from that session.

MATLAB Library comes with a set of many inbuilt functions. These


functions mostly perform mathematical operations like sine, cosine and
tangent. They perform more complex functions too like finding the
inverse and determinant of a matrix, cross product and dot product
Although MATLAB is encoded in C, C++ and Java, it is a lot easier to
implement than these three languages.

Defining and using variable:


To create a new variable, enter the variable name in the Command
Window, followed by an equal sign (=) and the value you want to assign
to the variable. For example:

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 :

Column vectors are created by enclosing the set of elements in square


brackets, using semicolon to delimit the elements.

4
SOFTWARE WORKSHOP

INPUT AND OUTPUT:

You can reference one or more of the elements of a vector in several


ways. The ith component of a vector v is referred as v(i). For example –
Taking above column vector:

MATLAB allows you to select a range of elements from a vector.


Example from above row vector :

5
SOFTWARE WORKSHOP

MATRIX AND ITS OPERATIONS :


Code:

6
SOFTWARE WORKSHOP

EIGEN VALUES :

The symbolic eigenvalues of a square matrix A or the symbolic


eigenvalues and eigenvectors of A are computed, respectively, using the
commands E = eig(A) and [V,E] = eig(A).
CODE AND RESULT :

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 −

Sr. Operators Description


No.
1. + Addition or unary plus. A+B adds the values stored in
variables A and B. A and B must have the same size,
unless one is a scalar. A scalar can be added to a matrix of
any size.
2. - Subtraction or unary minus. A-B subtracts the value of B
from A. A and B must have the same size, unless one is a
scalar. A scalar can be subtracted from a matrix of any
size.
3. * Matrix multiplication. C = A*B is the linear algebraic
product of the matrices A and B. For non-scalar A and B,
the number of columns of A must be equal to the
number of rows of B. A scalar can multiply a matrix of
any size.
4. .* Array multiplication. A.*B is the element-by-element
product of the arrays A and B. A and B must have the
same size, unless one of them is a scalar.
5. / Slash or matrix right division. B/A is roughly the same as
B*inv(A). More precisely, B/A = (A'\B')'.

8
SOFTWARE WORKSHOP

6. ./ Array right division. A./B is the matrix with elements


A(i,j)/B(i,j). A and B must have the same size, unless one
of them is a scalar.
7. \ Backslash or matrix left division. If A is a square matrix,
A\B is roughly the same as inv(A)*B, except it is
computed in a different way. If A is an n-by-n matrix and
B is a column vector with n components, or a matrix with
several such columns, then X = A\B is the solution to the
equation AX = B. A warning message is displayed if A is
badly scaled or nearly singular.
8. .\ Array left division. A.\B is the matrix with elements
B(i,j)/A(i,j). A and B must have the same size, unless one
of them is a scalar.
9. ^ Matrix power. X^p is X to the power p, if p is a scalar. If p
is an integer, the power is computed by repeated
squaring. If the integer is negative, X is inverted first.
10. .^ Array power. A.^B is the matrix with elements A(i,j) to the
B(i,j) power. A and B must have the same size, unless one
of them is a scalar.
11. ‘ Matrix transpose. A' is the linear algebraic transpose of A.
For complex matrices, this is the complex conjugate
transpose.
12. .’ Array transpose. A.' is the array transpose of A. For
complex matrices, this does not involve conjugation.

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

Polylogarithms and Zeta Function:


dilog - Dilogarithm function
hurwitzZeta - Hurwitz zeta function
polylog - Polylogarithm
psi - Digamma function
zeta - Riemann zeta function

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.

MATLAB also provides Hyperbolic Functions , Complex Numbers , Gamma Zeta


Functions,

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

We can draw 2 plots simultaneously also such as:


CODE :

PLOT:

17
SOFTWARE WORKSHOP

Plot of Non Linear Function:

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

Stacked Bar Graph


CODE :

PLOT :

24

You might also like