List of Experiments
List of Experiments
1. 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 ordinary differential 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
2. BASICS:
2.1 MATLAB WINDOWS: There are three basic windows which are as
follows:
1. 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 is 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.
2. 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.
3. 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 appears on the command
window. The figure appears on the figure window. An editor
window is shown as in figure:
2.2 LANGUAGES:
MATLAB is a high-level language that includes matrix-based data
structures, its own internal data types, an extensive catalogue of
functions and scripts, and 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, and program written in C and
FORTRAN, and serial port devices.
2.3 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.
2.3.1 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.
2.3.2 Dimension: Dimension state is not required in the MATLAB. It is
automatic.
2.3.3 Case Sensitivity: It differentiates between lower and upper cases.
It is case sensitive.
2.3.4 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 the end of a command except for
the graphics.
GIVEN NUMERICAL:
A= 3 2 1
0 3 4
-1 1 -1
B= 1 3 0
2 64
-1 0 2
Where A and B are two 3 X 3 matrix
COMMANDS:
>> A= [3 2 1; 0 3 4; -1 1 -1]
>> B= [1 3 0; 2 6 4; -1 0 2]
Sum: A+ B
Subtraction: A–B
Multiplication: A*B
Division: A/B or A\B
Inverse of A: inv(A)
RESULTS:
6 21 10
2 18 20
2 3 2
1 1 1
1 1 1
1 1 1
>> b= 2*ones(3) % multiplication of 2 with ones(3)
ans:
2 2 2
2 2 2
2 2 2
CONCLUSION:
We have studied various commands to solve the basic matrix operations.
EXPERIMENT NO. 03
THEORY:
For an n x n matrix A, the real number λ is called an Eigen value of A if there
exists a nonzero vector x in Rn such that Ax =λ x. The vector x is called an
eigenvector belonging to λ . The equation Ax =λ x is equivalent to (A-λI) x = 0, so
all of the following are equivalent:
1.λ is an Eigen value of A.
2. (A-λI) x = 0 has a nontrivial solution.
3. A-λI is singular.
4. det(A-λI) = 0.
The eigenvectors for λ are the nonzero solutions x to (A-λI)x=0. These vectors
together with the 0 vector is called the eigen space corresponding to eigen value λ.
The expression det(A-λI) is a polynomial in λ of degree n, called the characteristic
polynomial. By property 4, the eigen values are the roots of the characteristic
equation det(A-λI) = 0.
Determining eigen values and eigenvectors with MATLAB:
Method 1: In MATLAB we can find the characteristic polynomial of a matrix A by
entering poly(A). If A is an n x n matrix, poly(A) is a row vector with n+1 elements
that are the coefficients of the characteristic polynomial. The command roots(C)
computes the roots of the polynomial whose coefficients are the elements of the
vector C. Thus, roots (poly(A)) returns the eigen values of A in a column vector.
Similarly, the reduced echelon forms for A-1I and A-(-1)I allow us to determine
1 1
>> A = [ 1 2 3; 4 5 6; 7 8 9]
>> eig(A)
>> [V D]=eig(A)
RESULT :
eig(A) =
16.1168
-1.1168
-0.0000
V=
D=
16.1168 0 0
0 -1.1168 0
0 0 -0.0000
THEORY:
DIFFERENTIAL EQUATIONS:
GIVEN NUMERICAL:
COMMANDS:
(i)
>> y=dsolve(‘Dy=-a*y’) %write ODE in inverted comma
(ii)
(iii)
Note: In all the above cases, the independent variable is ‘t’ by default.
(iv)
>> y = dsolve (‘Dy=(x*y –y^2)/ x^2’, ‘x’)
% define independent variable as ‘x’
(v) >> y = dsolve (‘Dy=tan(y/x) + y/x)’, ‘x’)
RESULTS:
(i)
>> y=dsolve(‘Dy=-a*y’)
y=
C1/exp(a*t)
(ii)
>>y=dsolve(‘Dy=-a*y’, ‘y(0)=1’)
y=
exp(-a*t)
(iii)
>>y=dsolve(‘D2y=-a^2*y’, ‘y(0)=1, Dy(pi/a)=0’)
y=
cos(a*t)
(iv)
>> y = dsolve (‘Dy=(x*y –y^2)/ x^2’, ‘x’)
y=
-x/(C12 - log(x))
(v)
>> y = dsolve (‘Dy=tan(y/x) + (y/x)’, ‘x’)
y= asin(x*C1)*x
EXPERIMENT NO. 05
GIVEN NUMERICAL
COMMANDS:
>> pretty(i)
-2 exp(-2t) C2-7 exp(-7 t)(-C2 +9/500)+9/500 sin(t)+ 500 cos(t)