Introduction To MATLAB
Introduction To MATLAB
Introduction to MATLAB
Outline
Introduction Basic Operations using MATLAB
8/27/2011
MATLAB : Introduction
27-08-2011
MATLAB Introduction
MatLab : Matrix Laboratory Numerical Computations with matrices Why Matlab?
User Friendly (GUI) Easy to work with Powerful tools for complex mathematics Every number can be represented as matrix
8/27/2011
MATLAB : Introduction
MATLAB System
Desktop Tools and Development Environment
This part of MATLAB is the set of tools and facilities that help you use and become more productive with MATLAB functions and les. Many of these tools are graphical user interfaces. It includes:
8/27/2011
the MATLAB desktop and Command Window, an editor and debugger, a code analyzer, browsers for viewing help, the workspace, and les, and other tools.
MATLAB : Introduction 4
27-08-2011
MATLAB System
8/27/2011
MATLAB : Introduction
MATLAB System
The Language
The MATLAB language is a high-level matrix/array language with control ow statements, functions, data structures, input/output, and object-oriented programming features. It allows both programming in the small to rapidly create quick programs you do not intend to reuse. You can also do programming in the large to create complex application programs intended for reuse.
8/27/2011 MATLAB : Introduction 6
27-08-2011
MATLAB System
Graphics
MATLAB has extensive facilities for displaying vectors and matrices as graphs, as well as annotating and printing these graphs. It includes high-level functions for two-dimensional and three-dimensional data visualization, image processing, animation, and presentation graphics. It also includes low-level functions that allow you to fully customize the appearance of graphics as well as to build complete graphical user interfaces on your MATLAB applications.
8/27/2011 MATLAB : Introduction 7
MATLAB System
External Interfaces
The external interfaces library allows you to write C and Fortran programs that interact with MATLAB.
It includes facilities for calling routines from MATLAB (dynamic linking), for calling MATLAB as a computational engine, and for reading and writing MAT-les.
External DAQ System can be interfaced for digital/analog Input Output
8/27/2011 MATLAB : Introduction 8
27-08-2011
Menus
MATLAB Window
8/27/2011
MATLAB : Introduction
Essential Requirements
for successful Programming You need to learn the exact rules for writing MATLAB statements. You need to develop a logical plan of attack for solving particular problems Garbage in, garbage out.
If you give MATLAB a garbage instruction, you will get a garbage result. With experience, you will see that with MATLAB you can design, develop and implement computational and graphical tools to do relatively complex science and engineering problems.
8/27/2011
MATLAB : Introduction
10
27-08-2011
Arithmetic Operations
Since we have experience doing arithmetic, we want to examine if MATLAB does this correctly. When applying computer tools this is a required step to gain condence in the tool and in our ability to use the tool. Carry out simple arithmetic operations at command line as below >> 3+5 >> 5*10/2 >> 3^2+5^3+10/5 The line with the >> prompt is called the command line. Use of Backspace , Left-arrow , Right-arrow and Del keys. Use of Up-arrow and Down-arrow
MATLAB : Introduction 11
8/27/2011
Arithmetic Operations
Assign values to variable to do arithmetic operations
>> a=5 >> b=10 >> c=(a+b)/a etc
MATLAB has all of the usual mathematical functions that are on a scientic-electronic calculator, like sin, cos, log
Carry out simple trigonometric operations and verify
MATLAB has numerous general functions such as date, calendar, clc, clear, who, whos etc
8/27/2011
MATLAB : Introduction
12
27-08-2011
log10 (e3 )
Trigonometric 2 2
sin 6 cos 6
log10(exp(3))
3.0000
1.0000
Complex Number
1 3i 1 3i
e
8/27/2011
8/27/2011
MATLAB : Introduction
14
27-08-2011
8/27/2011
MATLAB : Introduction
15
8/27/2011
MATLAB : Introduction
16
27-08-2011
General Commands
Online help
help topic lookfor string demo who whos size clear WP) clc list topics on which help is available lists help topics containing string runs the demo program lists variable currently in workspace lists variable currently in workspace with their clears workspace (deletes all variables from clears command window returns a current date and time vector creates a directory lists contents of current directory
MATLAB : Introduction 17
Workspace Information
General Information
clock mkdir ls
8/27/2011
8/27/2011
MATLAB : Introduction
18
27-08-2011
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, [ ]
8/27/2011
MATLAB : Introduction
19
Defining a Array
Elements of variable
8/27/2011
MATLAB : Introduction
20
10
27-08-2011
Defining Array
>> x = 1 :
Variable Name
10
End Number
1 as default increment
>> x = 1
Increment of +0.5
0.5 :
Positive increment
>> x =
Increment of -1
8/27/2011
10 :
-1
Negative increment
MATLAB : Introduction
21
Defining Array
rand function: Uniformly distributed pseudorandom numbers >> x = rand( row_nos, col_nos) >> x = rand(1,7)
8/27/2011
MATLAB : Introduction
22
11
27-08-2011
Defining a Matrix
8/27/2011
MATLAB : Introduction
23
Defining MATRIX
Inbuilt Functions
eye Function : Identity matrix >> x = eye(row_nos, col_nos) >> x = eye(5, 5) zero Function : Zeros array (M-by-N matrix of zeros) >> x = zero(row_nos, col_nos) >> x = zero(5, 5) ones Function : Ones array (M-by-N matrix of ones) >> x = ones(row_nos, col_nos) >> x = ones(5, 5)
8/27/2011
MATLAB : Introduction
24
12
27-08-2011
eye
linspace repmat logspace freqspace meshgrid
Indentity Matrix
Linearly spaced vector Replicate and tile array Logarithmically spaced vector Frequency spacing for frequency response X & Y arrays for 3D plots
8/27/2011
MATLAB : Introduction
25
size
length ndims numel disp isempty isequal isequalwithequalnans
Size of array
Length of vector Number of dimensions Number of elements Display matrix or text True for empty array True if arrays are numerically equal True if arrays are numerically equal.
8/27/2011
MATLAB : Introduction
26
13
27-08-2011
diag
blkdiag tril flipplr rot90 end
8/27/2011
MATLAB : Introduction
27
ndgrid
permute ipermute Shiftdim circshift Squeeze isscalar isvector
8/27/2011
14
27-08-2011
Elementary matrices and matrix manipulation inf nan isnan isinf isfinit e i&j Infinity Not a number True for not a number True for infinite elements True for finite elements Imaginary unit
29
Smallest positive floating point Largest positive integer value Smallest integer value 3.1415926535897....
MATLAB : Introduction
Exponential Functions
exp, log, log10, log2, realpow, reallog, sqrt, nthroot etc
Complex Functions
abs, angle, complex, conj, imag, real, etc
8/27/2011
MATLAB : Introduction
30
15
27-08-2011
Specialized math functions. Specialized math functions Math Functions airy besselj, bessely, besselh beta etc gamma etc legendre etc cross dot
8/27/2011
Number theoretic functions factor isprime, primes gcd (),lcm rat factorial
MATLAB : Introduction
31
Matrix Manipulations
Transpose of Matrix >> A = rand(3,3) >> A = rand(3,3) >> B = A >> B = det(A) Dash Operator Dash Operator Determinant of Matrix
Multiplication of Matrix >> C = A * B Eigen Values and Eigen Vectors Dash * Operator
16
27-08-2011
Matrix Manipulations
The colon operator >> A=magic(3,3) >> A (2:3, 1:2) Deleting rows & columns >> a ( :, 2) = [] >> a ( 1, 2) = [] Sum of elements of matrix >> A=fix(10*rand(3,3)) >> sum (A) Colon : Operator Deletes 2nd column of a Deletes single element of a Colon : Operator
8/27/2011
MATLAB : Introduction
33
Thank You
Tutorials (20 Problems for 60 min ) Plz solve problems from tutorials
8/27/2011
MATLAB : Introduction
34
17