An Introduction To Matlab !!!
An Introduction To Matlab !!!
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Outline
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Denition MATLAB R is a 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 development, Data acquisition, Modeling, simulation, prototyping, Data analysis, exploration, visualization, Scientic and engineering graphics, Application development including graphical user interface building -The MathWorks, Inc.
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
MATLAB
MATRIX LABORATORY Everything in MATLAB is a matrix The basic data element in MATLAB is an array that does not require dimensioning. An interactive software package/language designed for scientic and engineering computations - Making it Simple!!!!! An interpreted language - Commands executed line by line Precise numerical calculations and graphics illustrations are possible
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
MATLAB............ ?
MATLAB commands are expressed in a notation close to that used in Mathematics and Engineering
Eg: sin,log,abs ......
Single MATLAB command to nd the inverse of a matrix Because of natural notation, MATLAB code is clear and self documented MATLAB Software is written in Optimized C and assembly language- to obtain high performance
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
MATLAB............ ?
MATLAB commands are MATLAB functions generally stored as an M le (File stored with .m as extension)
Eg: sin.m , plot.m etc...
The built in M les are open. Modications are possible. One can create user dened M les /functions for solving certain problems
sin.m is a built-in function to calculate sin of an angle But no built in function is available to nd sine square of an angle User can create a function named sin2 (le sin2.m) to do the same
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
MATLAB............ ?
There is nothing one can do in Fortran or C that can not be done in MATLAB (and in a much easier fashion) MATLAB has a rich set of Toolboxes/application-specic solutions to do specialized work Toolboxes are comprehensive collections of MATLAB functions (M-les) that extend the MATLAB environment to learn and apply specialized technology
Simulink Electrical - Control Systems, Signal processing, Power systems Mathematics - PDE , Fuzzy logic , Optimization, Wavelet etc..
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
MATLAB............ ?
MATLAB has a good demo program for beginners All the help, manuals etc. are freely available at http://www.mathworks.com MATLAB is costly ??? Scilab by INRIA is an Alternative. It is Open Source and free
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
MATLAB System
Five main parts Development Environment - Set of tools and facilities that helps to use MATLAB functions and les - GUIs The MATLAB Mathematical Function Library - a vast collection of computational algorithms sum, sine, cosine, matrix inverse, matrix eigenvalues, Bessel functions, and fast Fourier transforms The MATLAB Language - high-level matrix/array language with control ow statements, functions, data structures, input/output, and object-oriented programming features.
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
MATLAB System
Graphics - functions for displaying vectors and matrices as graphs, two and three-dimensional data visualization, image processing, animation, presentation graphics and building complete GUIs The MATLAB Application Program Interface (API) - library that allows to write C and Fortran programs that interact with MATLAB facilities for calling routines from MATLAB (dynamic linking), calling MATLAB as a computational engine
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Matrix Operations
Basic Conventions
Separate the elements of a row with blanks or commas Use a semicolon ; to indicate the end of each row. Surround the entire list of elements with square brackets [ ]
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Matrix Operations...Contd
A= [16 3 2 13; 5 10 11 8; 9 6 7 12; 4 15 14 1] 16 3 2 13 5 10 11 8 A= 9 6 7 12 4 15 14 1 To suppress output, end the line with a semicolon a=3 a=3 a=3; Variable names Case Sensitive B= [1,6,3,2;5,1,0,8;9,6,7,2;4,15,1,4]; If variable name is not specied, the default name is ans
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
sum(A) - gives the sum of column elements To nd the sum of row elements transpose the matrix and take the sum A gives the transpose of A sum(A) diag(A) - gives the diagonal elements sum(diag(A))- gives the sum of diagonal elements The element in row i and column j of A is denoted by A(i,j) A(1,1) gives 16
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
eig(A) gives the eigen values of A inv(A) gives the inverse of A det(A) gives the determinant of A poly(A) gives the coefcients of the characteristic polynomial A(:,2) gives the elements of the 2nd column A(2,:)=[3 6 4 3]; replaces second row of A
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
clear A1 - Removes the variable A1 from Workspace clear all - Deletes everything from Workspace load le-name - Retrieves the variables saved in the le named le-name Eg: load my-variables.dat Can do the same for entire environment. Commands are save myenv; clear all; load myenv;
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
A variable is a 1 X 1 array A linear array is a vector Most variables will be arrays or matrices of doubles (64-bit default)) or 16-bit char Other types are also supported: complex, symbolic, 16-bit and 8 bit integers, etc. Variable Names
First character must be a LETTER after that, any combination of letters, numbers and _ CASE SENSITIVE!
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Built-in variables
i and j can be used to indicate complex numbers pi has the value 3.1415926... Inf and -Inf are positive and negative innity NaN represents Not a Number
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
a=s; denes a character variable a with value s Welcome 2012 display the string with the string stored as ans To remove "ans =", disp() function can be used disp(Welcome 2012) MATLAB function sprintf() allows to mix strings with variables year=2012; disp(sprintf(Welcome %g, year)) The format is C-syntax
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Scalar Operations
Arithmetic operations (+, , , /) 7/45 (1+i)*(2-i) Exponentiation ( ) 42 Complicated expressions, use parentheses ((2 + 3) 3)0.1 Multiplication is NOT implicit 3(1+0.7) gives an error 3*(1+0.7) is correct
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Built in Functions
MATLAB has an enormous library of built-in functions Call using parentheses - passing parameter to function
sqrt(2) log(2), log10(0.23) cos(1.2), atan(-.8) exp(2+4*i) round(1.4), oor(3.3), ceil(4.23) angle(i); abs(1+i);
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Help on Functions
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Functions- An Example
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Element-wise operators Operators * / have element-wise operation To do element-wise operations, dot . operator is used. Operand dimensions should match
a = [112]; b = [2; 3; 1]; a. b, a./b, a. (b) gives errors a. b, a./b, a. (b) valid
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Plotting Curves
Generating data for plots
x=linspace(0,4*pi,10); y=sin(x);
to plot y versus x
plot(x,y);
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Try help plot practice the various options A second plot command normally overwrites the rst To draw 2 curves in the same graph the hold on command is used
hold on;
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
to add a title
title(Vehicle)
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
All the above can be done in the gure GUI itself GUI can be used to save plots in a variety of le formats: .eps. .pdf, .jpg etc. *.eps is the preferred way to put graphics into TEX and LATEX documents It is also editable and savable in usual drawing programs, especially linux based LATEX commands can be inserted in plots
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab
MATLAB - Denition The MATLAB System MATLAB Development Environment MATLAB Programming
Thank you
Dr. C. SREEKUMAR Associate Professor Dept. of Electrical & Electronics Engg. Govt. College of Engg. Kannur An Introduction to Matlab