Documente Academic
Documente Profesional
Documente Cultură
Lecture-1
Fundamentals
MATLAB stands for Matrix Laboratory, a tool for numeric
and Scientific computation.
Various toolboxes-> Control Systems, Signal Processing,
Image Processing & System Identification.
Active Folder
generally WORK
MATLAB Window
Basic Operations
When invoked, command window will display
prompt >>. So now ready for entering data and
executing commands.
To quit exit or quit. Help can be sought using
help or lookfor command.
? Find out the difference between Scalar & Vector
in MATLAB.
? What happens if a MATLAB statement ends with
a Semicolon.
Predefined Values
Function
Description
pi
(3.14)
i,j
Inf
Nan
clock
Represents the date and time in a six element row vector containing
the year, month, day, hour, minute & second
date
eps
The short name for epsilon, it represents the floating point precision
for the Computer being used, it is the smallest difference between 2
nos. that can be represented on the computer
ans
Basic Commands
Command
Description
Comments
demo
length
Length of a matrix
Clear
clc
clg
diary
close
Description
abs(x)
Absolute value of x
acos(x)
Cos-1x, in radians
asin(x)
Sin-1x, in radians
atan(x)
Tan-1x, in radians
atan2(x,y)
cos(x)
exp(x)
ex
log(x)
log10(x)
Description
diag(a)
eye(n)
eye(n,m)
ones(n)
ones(n,m)
zeros(n)
zeros(n,m)
Assignment-1(Command Line)
1.
2.
3.
Division Operator
Left Division Operator
a\b== b/a==inv(a)*b [MATLAB]
Right Division Operator
a/b== a/b==a*inv(b) [MATLAB]
Decision depends on Programmer. Care must
be taken that a and b are matrices.
Period(.)
Preceding the linear algebraic operations
of +,-,*,/ by a period (.) indicates an array
or element by element operation.
So, .*, ./, .\, .^ are element by
element multiplication, division and
exponent.
Complex Number
A no. z=2+j2 may be entered in MATLAB
as z=2+2*i or z=2+2*j
In general, while entering nos. like y=3+4j,
no spaces should be given in between
otherwise it will be considered as 2
separate numbers.
Ex- w=[1+j 3-2*j; 3+2*j 4+3*j]
Assignment-2
1. For a two dimensional matrix, demonstrate the
operations of Matrix addition, Subtraction,
Multiplication, Division. Also find out square,
cube, square root and cube root of each
element of both the matrices.
2. Convert the following expression in MATLAB
equivalent
za=22exp[(/4)j].
3. Calculate the magnitude and Phase (in
degrees) of Input Impedance
Z=((5+6j)(4-j8)/(9-2j))+4/300
Generating Vectors
For generating vectors we use 2 commands:1. Linspace- generates linearly evenly spaced
vectors.
2. Logspace- generates a Logarithmically
evenly spaced vectors.
Syntax- linspace(i_value,f_value,np)
logspace(i_value,f_value,np)
Where
i_value= initial value
f_value=final value
np=total no. of elements in vector.
M Files
Command Line Prompt allows execution
of one instruction at a time.
MATLAB files with .m extension are
called M Files. These are text editor to
write programs.
There are two types of M Files:a. Script Files
b. Function Files
Script Files
It is especially useful for analysis and
design problems that require long
sequences of MATLAB commands.
Statements in a script file operate globally
on the workspace data.
Function Files
These are M Files equivalent to the User
Defined Functions used in the C/C++
Language style.
Scope of a variable declared inside a
function is Local. However, arguments
may be into or out of a Function M file.
Syntax-function variable(parameters)=
function_name (arguments)
Assignment-3
Implement using M files and Function files
the following operation: Input- a=10, b=20
Output- Add, Sub., Mul., Division( both types) and
ab.
clc;
close all;
clear all;
echo on;
a=10;
b=20;
c=a+b;
d=a-b;
e=a*b;
f=a/b;
g=a\b;
h=a^b;
disp(a);
disp(b);
disp(c);
disp(d);
disp(e);
disp(f);
disp(g);
disp(h);
Assignment-4
Find out the role of functions namely- ceil, exp,
fix, floor, log10, rem, round, sqrt, tan.
Clearly Explain the difference between Vectors
and Scalars in MATLAB.
Suppose you are given a set of Five resistances
namely
R1=1, R2=2 , R3=3 , R4=4 , R5=5 .
Write a Program to calculate the Equivalent
Resistances when they are connected in Series
and in Parallel.
Assign-4(Ctd.)
For the Following figure, find out the
Equivalent Resistance across Point A and
B.
4
2
5
4
2
A