introduction to matlab 1 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Introduction to Matlab-1 PowerPoint Presentation
Download Presentation
Introduction to Matlab-1

Loading in 2 Seconds...

play fullscreen
1 / 40

Introduction to Matlab-1 - PowerPoint PPT Presentation


  • 97 Views
  • Uploaded on

Introduction to Matlab-1. Laboratoire Mathématiques, Informatique et Applications. Lecture 1 – Matlab Basics. What is Matlab?. A software environment for interactive numerical computations Examples: Matrix computations and linear algebra Solving nonlinear equations

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Introduction to Matlab-1' - qamra


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
introduction to matlab 1

Introduction to Matlab-1

Laboratoire Mathématiques, Informatique et Applications

Lecture 1 – Matlab Basics

what is matlab
What is Matlab?
  • A software environment for interactive numerical computations
  • Examples:
    • Matrix computations and linear algebra
    • Solving nonlinear equations
    • Numerical solution of differential equations
    • Mathematical optimization
    • Statistics and data analysis
    • Signal processing
    • Modelling of dynamical systems
    • Solving partial differential equations
    • Simulation of engineering systems
matlab used in many courses
Matlab used in many courses
  • Numerical analysis
  • Signal and Systems I
  • Signals and Systems II
  • Modeling of Dynamical Systems
  • Automatic Control, Basic Course
  • Automatic Control, Advanced Course
  • Nonlinear Control
  • Hybrid and Embedded Control Systems
  • Chemical Process Control
  • Control Project Course
  • Signal Theory
  • Digital Signal Processing
  • Adaptive Signal Processing
  • Signal Processing Project
  • Communication theory
  • Advanced Communication Theory
  • <and many, many more>
today s lecture
Today’s Lecture
  • Matlab Basics
    • Background to Matlab
    • Interactive calculations
    • Vectors and matrices
    • Graphical illustrations
  • Next lecture: Matlab programming
matlab background
Matlab Background
  • Matlab = Matrix Laboratory
  • Originally a user interface for numerical linear algebra routines
  • Commercialized 1984 by The Mathworks
  • Since then heavily extended (defacto-standard)
  • AlternativesComplements
  • Matrix-X Maple (symbolic)Octave (free; GNU) Mathematica (symbolic)Lyme (free; Palm)
construction
Construction
  • Core functionality: compiled C-routines
  • Most functionality is given as m-files, grouped into toolboxes
    • m-files contain source code, can be copied and altered
    • m-files are platform independent (PC, Unix/Linux, MAC)
  • Simulation of dynamical systems is performed in Simulink

Contr. Syst.

Sig. Proc

Simulink

m-files

C-kernel

matlab desktop
Matlab Desktop

Launch Pad

Command Window

History

matlab desktop cont d
Matlab Desktop – cont’d

Workspace

Command Window

Current DIrectory

matlab demo
MATLAB Demo
  • Demonstrations are invaluable since they give an indication of the MATLAB capabilities.
  • A comprehensive set are available by typing the command >>demo in MATLAB prompt.
interactive calculations
Interactive Calculations
  • Matlab is interactive, no need to declare variables
  • >> 2+3*4/2
  • >> a=5e-3; b=1; a+b
  • Most elementary functions and constants are already defined
  • >> cos(pi)
  • >> abs(1+i)
  • >> sin(pi)
  • Last call gives answer 1.2246e-016 !?
variable and memory management
Variable and Memory Management
  • Matlab uses double precision (approx. 16 significant digits)
  • >> format long
  • >> format compact
  • All variables are shown with
  • >> who
  • >> whos
  • Variables can be stored on file
  • >> save filename
  • >> clear
  • >> load filename
the help system
The Help System
  • Search for appropriate function
  • >> lookfor keyword
  • Rapid help with syntax and function definition
  • >> help function
  • An advanced hyperlinked help system is launched by
  • >> helpdesk
  • Complete manuals as PDF files
variables
Variables
  • Don’t have to declare type
  • Don’t even have to initialise
  • Just assign in command window
  • >>
  • >> a=12; % variable a is assigned 12

Matlab prompt

comment operator

suppress command output

assign operator

Try the same line without the semicolon and comments

variables continued
Variables (continued …)
  • View variable contents by simply typing the variable name at the command prompt
  • >> a
  • a =
  • 12
  • >>
  • >> a*2
  • a =
  • 24
  • >>
workspace
Workspace
  • The workspace is Matlab’s memory
  • Can manipulate variables stored in the workspace
  • >> b=10;
  • >> c=a+b
  • c =
  • 22
  • >>
workspace continued
Workspace (continued …)
  • Display contents of workspace
  • >> whos
  • Name Size Bytes Class
  • a 1x1 8 double array
  • b 1x1 8 double array
  • c 1x1 8 double array
  • Grand total is 3 elements using 24 bytes
  • >>
  • Delete variable(s) from workspace
  • >> clear a b; % delete a and b from workspace
  • >> whos
  • >> clear all; % delete all variables from workspace
  • >> whos
the operator
The : operator
  • VERY important operator in Matlab
  • Means ‘to’
  • >> 1:10
  • ans =
  • 1 2 3 4 5 6 7 8 9 10
  • >> 1:2:10
  • ans =
  • 1 3 5 7 9

Try the following >> x=0:pi/12:2*pi;>> y=sin(x)

the operator and matrices
The : operator and matrices
  • >>A(3,2:3)
  • ans =
  • 1 7
  • >>A(:,2)
  • ans =
  • 2
  • 1
  • 1

A =

3 2 1

5 1 0

2 1 7

What’ll happen if you type A(:,:) ?

vectors and matrices
Vectors and Matrices
  • Vectors (arrays) are defined as
  • >> v = [1, 2, 4, 5]
  • >> w = [1; 2; 4; 5]
  • Matrices (2D arrays) defined similarly
  • >> A = [1,2,3;4,-5,6;5,-6,7]
matrix operators
Matrix Operators
  • All common operators are overloaded
  • >> v + 2
  • Common operators are available
  • >> B = A’
  • >> A*B
  • >> A+B
  • Note:
  • Matlab is case-sensitive
  • A and a are two different variables
indexing matrices
Indexing Matrices
  • Indexing using parentheses
  • >> A(2,3)
  • Index submatrices using vectorsof row and column indices
  • >> A([2 3],[1 2])
  • Ordering of indices is important!
  • >> B=A([3 2],[2 1])
  • >> B=[A(3,2),A(3,1);A(2,2),A(2,1)]

Column no. 1, 2

Rows no. 2, 3

indexing matrices1
Indexing Matrices
  • Index complete row or column using the colon operator
  • >> A(1,:)
  • Can also add limit index range
  • >> A(1:2,:)
  • >> A([1 2],:)
  • General notation for colon operator
  • >> v=1:5
  • >> w=1:2:5
matrix functions
Matrix Functions
  • Many elementary matrices predefined
  • >> help elmat;
  • >> I=eye(3)
  • Elementary functions are often overloaded
  • >> help elmat
  • >> sin(A)
  • Specialized matrix functions and operators
  • >> As=sqrtm(A)
  • >> As^2
  • >> A.*A
  • Note: in general, ”.<operator>” is elementwise operation
manipulating matrices
Manipulating Matrices

A =

3 2 1

5 1 0

2 1 7

  • >> A ' % transpose
  • >> B*A % matrix multiplication
  • >> B.*A % element by element multiplication
  • >> B/A % matrix division
  • >> B./A % element by element division
  • >> [B A] % Join matrices (horizontally)
  • >> [B; A] % Join matrices (vertically)

B =

1 3 1

4 9 5

2 7 2

Enter matrix B into the Matlab workspace

Create matrices A and B and try out the the matrix operators in this slide

numerical linear algebra
Numerical Linear Algebra
  • Basic numerical linear algebra
  • >> z=[1;2;3]; x=inv(A)*z
  • >> x=A\z
  • Many standard functions predefined
  • >> det(A)
  • >> rank(A)
  • >> eig(A)
  • The number of input/output arguments can often be varied
  • >> [V,D]=eig(A)
matrix vs element math
Matrix vs Element Math

Element Math

Matrix Math

circuit example
Circuit Example

10 Ohms

+

10V

-

3uF

0.01 H

I=V/R=10 /

rlc series m file
RLC Series .m File

%Example4.m - RLC

w=linspace(1,40000,1000);

i=10./(10+(1./(j.*w.*3.*10^-6))+(j.*w.*0.01));

plot(w,abs(v));

j is intrinsically unless its redefined

graphics
Graphics
  • Visualization of vector data is available
  • >> x=-pi:0.1:pi; y=sin(x);
  • >> plot(x,y)
  • >> plot(x,y,’s-’)
  • >> xlabel(’x’);
  • >> ylabel(’y=sin(x)’);
slide33

% print the cosine and sine

u = 0:pi/20:2*pi;

w = sin(u);

v = cos(u);

figure(1);

plot(u,w,'ro-') ;

hold on;

plot(u,v,'gs:');

xlabel('\theta');ylabel('y');

legend('Sin(\theta)','Cos(\theta)');

title('Sample Plots');

slide34

Can change plot properties in Figure menu, or via ”handle”

>> h=plot(x,y); set(h, ’LineWidth’, 4);

Many other plot functions available

>> v=1:4; pie(v)

graphics1
Graphics
  • Three-dimensional graphics
  • >> A = zeros(32);
  • >> A(14:16,14:16) = ones(3);
  • >> F=abs(fft2(A));
  • >> mesh(F)

>> rotate3d on

slide36

Three-dimensional graphics

  • >> A = zeros(32);
  • >> A(14:16,14:16) = ones(3);
  • >> F=abs(fft2(A));
  • >> mesh(F)

>> rotate3d on

graphics2
Graphics
  • Three-dimensional graphics
  • >> A = zeros(32);
  • >> A(14:16,14:16) = ones(3);
  • >> F=abs(fft2(A));
  • >> mesh(F)
  • >> rotate3d on
  • Several other plot functions available
  • >> surfl(F)
  • Can change lightning and material properties
  • >> cameramenu
  • >> material metal
graphics3
Graphics
  • Bitmap images can also be visualized
  • >> load mandrill
  • >> image(X); colormap(map)
  • >> axis image off
matlab reference
MATLAB - Reference:
  • A Partial List of On-Line Matlab Tutorials and Matlab Books
    • http://www.duke.edu/~hpgavin/matlab.html
  • Getting started with Matlab
    • http://www.engr.iupui.edu/ee/courses/matlab/tutorial_start.htm
  • A quick reference to some of the key features of Matlab
    • http://science.ntu.ac.uk/msor/ccb/matlab.html#MATLAB
  • Matlab tutorial, with lots of links to other tutorials
    • http://www.glue.umd.edu/~nsw/ench250/matlab.htm
  • Control Tutorial for Matlab
    • http://www.engin.umich.edu/group/ctm/home.text.html
  • A Practical Introduction to Matlab
    • http://www.math.mtu.edu/~msgocken/intro/intro.html
  • Matlab Tutorial Information from UNH
    • http://spicerack.sr.unh.edu/~mathadm/tutorial/software/matlab/
next lecture
Next Lecture
  • Programming in MATLAB