Matlab Basic Dr. Imtiaz Hussain

Slides:



Advertisements
Similar presentations
MATLAB – A Computational Methods By Rohit Khokher Department of Computer Science, Sharda University, Greater Noida, India MATLAB – A Computational Methods.
Advertisements

Introduction to Matlab
Digital Image Processing Lecture3: Introduction to MATLAB.
What is MATLAB ? MATrix LABratory –Originally, it was a front-end to FORTRAN matrix routines developed in the U. of New Mexico and Stanford –Today.
January 24, 2005 Lecture 3 - By P. Lin 1 CPET 190 Lecture 3 Problem Solving with MATLAB
259 Lecture 15 Introduction to MATLAB. 2 What is MATLAB?  MATLAB, which stands for “MATrix LABoratory” is a high- performance language for technical.
MATLAB Lecture One Monday 4 July Matlab Melvyn Sim Department of Decision Sciences NUS Business School
BRIAN D. HAHN AND DANIEL T. VALENTINE THIRD EDITION Essential MATLAB® for Engineers and Scientists.
Introduction to MATLAB adapted from Dr. Rolf Lakaemper.
Introduction to MATLAB Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
You can make this in matlab!. Matlab Introduction and Matrices.
MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU.
Introduction to M ATLAB EE 100 – EE Dept. - JUST.
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
A L I MAM M OHAMMAD B IN S AUD I SLAMIC U NIVERSITY C OLLEGE OF S CIENCES D EPARTMENT OF M ATHEMATICS MATLAB 251 : MATH SOFTWARE Introduction to MATLAB.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
Eng Ship Structures 1 Introduction to Matlab.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
Basics of MATLAB By DR. Wafaa Shabana
Matlab The language of Technical computing Mr. D. Suresh Assistant Professor, Dept. of CSE, PSNA CET, Dindigul.
MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Matlab 14.html Cost: $100 Available in labs on Windows and Unix machines.
OUTLINE Overview Numbers, variables and similar in Matlab
Chapter 6 Review: User Defined Functions Introduction to MATLAB 7 Engineering 161.
INTRODUCTION TO MATLAB MATLAB is a software package for computation in engineering, science, and applied mathemat-ics. It offers a powerful programming.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
CIS 595 MATLAB First Impressions. MATLAB This introduction will give Some basic ideas Main advantages and drawbacks compared to other languages.
Matlab Basic. MATLAB Product Family 2 3 Entering & Quitting MATLAB To enter MATLAB double click on the MATLAB icon. To Leave MATLAB Simply type quit.
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
CIS 601 Fall 2003 Introduction to MATLAB Longin Jan Latecki Based on the lectures of Rolf Lakaemper and David Young.
Introduction to Engineering MATLAB – 4 Arrays Agenda Creating arrays of numbers  Vectors: 1-D Arrays  Arrays: 2-D Arrays Array Addressing Strings & String.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Tutorial 2 : Matlab - Getting Started.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
CIS 595 MATLAB First Impressions. MATLAB This introduction will give Some basic ideas Main advantages and drawbacks compared to other languages.
Matlab Tutorial (material available at 1 Dr. Jim Martin Associate Professor School of Computing.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
Matlab Programming for Engineers
ECE 1304 Introduction to Electrical and Computer Engineering
Matlab.
Introduction to MATLAB
Computer Application in Engineering Design
Signals in Matlab Matlab as a name stands for Matrix Laboratory.
Introduction to Matlab
Lecture: MATLAB Chapter 1 Introduction
MatLab Programming By Kishan Kathiriya.
MATLAB Basics Nafees Ahmed Asstt. Professor, EE Deptt DIT, DehraDun.
Introduction to Programming for Mechanical Engineers (ME 319)
2) Platform independent 3) Predefined functions
Outline Matlab tutorial How to start and exit Matlab Matlab basics.
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Matlab Workshop 9/22/2018.
Introduction to MATLAB
Digital Image Processing using MATLAB
MATH 493 Introduction to MATLAB
Use of Mathematics using Technology (Maltlab)
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
Digital Image Processing
Fourth Year – Software Engineering
Communication and Coding Theory Lab(CS491)
Matlab Intro.
INTRODUCTION TO MATLAB
Simulation And Modeling
Laboratory in Oceanography: Data and Methods
Introduction to Matlab:
Introduction To MATLAB
Presentation transcript:

Matlab Basic Dr. Imtiaz Hussain Assistant Professor email: imtiaz.hussain@faculty.muet.edu.pk URL :http://imtiazhussainkalwar.weebly.com/

Contents What is MATLAB? Basic commands Variable definition Introduction to Matlab Matlab system MATLAB Product Family Toolboxes SIMULINK Basic commands Entering and quitting Matlab MATLAB Desktop Other basic commands Variable definition Defining Scalars in MATLAB Defining Vectors in MATLAB Defining Matrices in MATLAB Defining character arrays

Introduction to MATLAB

Introduction to MATLAB Integrated software environment Math and Computation Algorithm Development Modeling Simulation Visualization Analysis Scientific and engineering graphics Application Development GUI development Easy-to-use environment

The MATLAB System MATLAB System Handle graphics MATLAB language MATLAB working Environment Handle graphics MATLAB mathematical function library MATLAB application program interface (API)

MATLAB Language This is a high level matrix/array language with following features. Control flow statements Functions Data structures Input/output Object oriented programming features

MATLAB working Environment This is the set of tools and facilities that you work with as MATLAB user or programmer. It Includes the tools and facilities of Managing the variables Importing and exporting data Developing, managing and debugging M-files

Handle Graphics This is the MATLAB graphic system. It includes high level commands for: 2-D data visualization 3-D data visualization Image processing Animations Presentation graphics GUI tools

MATLAB mathematical function Library This is vast collection of computational algorithms like: Sum Sine cosine Complex arithmetic Matrices and inverses Matrix Eigen values Bessel functions FFT And many others

Application Program Interface (API) This is the library that allows you to write C and Fortran programs that interact with MATLAB. It includes facilities for: Calling routines from MATLAB Calling MATLAB as a computational engine Reading and writing MAT files.

MATLAB Product Family MATLAB MATLAB Extensions MATLAB Compiler SIMULINK Extensions Real Time Workshop Blocksets DSP Control System Communications e.t.c MATLAB SIMULINK MATLAB Extensions MATLAB Compiler MATLAB C Math Library Toolboxes Communication Financial Fuzzy Logic Image Processing Neural Networks Optimization Signal Processing

Basic Commands

Entering & Quitting MATLAB To enter MATLAB double click on the MATLAB icon. To Leave MATLAB Simply type quit and press enter. >> quit

MATLAB Desktop

Some Basic Commands >>ver >>clc >>home To check the list of installed toolboxes type >>ver To clear the screen type >>clc To move the cursor to upper left corner of the command window type >>home

Some Basic Commands (contd…) To list the current variables type >>who To list the current variables in long form type >>whos To clear the workspace type >>clear To remove particular variable from the workspace type >> clear ‘name of the variable’

Some Basic Commands (contd…) To get list of Help topics type >>help To get help for any topic type >>help ‘topic’ To get help for any command type >>help ‘command/syntax’

Some Basic Commands (contd…) To search command type >>lookfor ‘keyword’ To list the files in a directory type >>dir ‘directory name’ To list the Matlab files only type >>what ‘directory name’

Working With MATLAB Variables

Types of MATLAB Variables Scalar 1x1 array Vector nx1 (column vector) or 1xn (row vector) Matrix mxn Character Arrays (Strings)

Defining Scalars >> a = 2 a = 2 Variables are assigned numerical values by typing the expression directly, for example, typing >> a = 2 yields: a = 2

Variable Definitions We can also assign numerical values to the variables by typing the expression >> b = 1+2 yields: b = 3

Variable Definitions After typing the expressions the answers are echoed back. To suppress the echo put semicolon at the end of the expression. >> c = 5;

Arithmetic Operators on Scalars MATLAB utilizes the following arithmetic operators:  +  Addition  -  Subtraction  *  Multiplication  /  Division  ^  Power Operator  

Variable Definition (Contd…….) A variable can be assigned using a formula. For example, since a was defined previously, the following expression is valid >> d = 2*a yields: d = 4

Variables in Workspace Type who to check the stored variables in workspace. >> who Your variables are: a b c d

Variables in Workspace Type whos to check the stored variables in long form. >> whos Name Size Bytes Class a 1x1 8 double array b 1x1 8 double array c 1x1 8 double array d 1x1 8 double array Grand total is 4 elements using 32 bytes

Complex numbers A complex number 3+2i in Matlab is entered in the following form >> 3+2*i Or >> 3+2*j

Complex numbers >> 3e-2 Yields: ans= 0.0300 An exponential number 3x10-2 in Matlab is entered in the following form >> 3e-2 Yields: ans= 0.0300

Exercise#1 Investigate the effect of following commands (i) k=3 (ii) f= 2*c/3 (iii) g=c*d^2 (iv) h=c-d+k (v) who (vi) whos (vii) clear (viii) who (ix) whos (x) 3x10-5+5j

Defining Vectors Row Vectors 1xn Column Vectors nx1

Defining Row Vectors To create a row vector A simply type in: 1x9 vector A = 2 4 7 1 5 6 1 2 3 4 5 6 7 8 9 A(2) A(5)

Defining Row Vectors v = [2 0 1 4 7 1 5 6 4] A = A(1:4) A(6:9) 2 4 7 1 1x9 vector A = 2 4 7 1 5 6 1 2 3 4 5 6 7 8 9 A(1:4) A(6:9)

Defining Column Vectors To create a column vector B simply type in: B = [3; 5; 0; 0; 1; 4; 9; -1; 1] 1 -1 9 4 5 3 2 6 7 8 B(3) B = 9x1 vector B(5)

Defining Column Vectors B = [3; 5; 0; 0; 1; 4; 9; -1; 1] 1 -1 9 4 5 3 2 6 7 8 B(2:5) B = 9x1 vector B(7:9)

Arithmetic Operators (Arrays)  + Addition  - Subtraction  .* Array multiplication  ./ Array division  .^ Array power operator  ' transpose

Exercise#2 Investigate the effect of the following commands: V=[2 4 7 5] and w=[1 3 8 9] (i) v(2) (ii) sum = v + w (iii) diff = v – w (iv) vw = [v w] (v) vw(2: 6) (vi) v’ (vii) v./w (viii) v.*w (ix) whos

Exercise#3 (i) z’ (ii) z*v (iii) [v; w] (iv) v*z Investigate the effect of the following commands. z=[1; 1; 0; 0] (i) z’ (ii) z*v (iii) [v; w] (iv) v*z (v) [z; v’] (vi) z + v’

Defining Matrices A Matrix is a mxn array

Defining Matrices The most obvious ways are to type M = [1 2; 3 4] or To enter the matrix The most obvious ways are to type M = [1 2; 3 4] or M = [ [1 3]’ [3 4]’ ]

Defining Matrices N=[1 3 9 1; 2 1 7 4; 7 4 1 8; 1 9 3 0] N(1,3) or N(9) 1 3 9 7 4 8 2 5 6 10 11 12 14 15 16 13 N = N(4,3) or N(12)

Defining Matrices N=[1 3 9 1; 2 1 7 4; 7 4 1 8; 1 9 3 0] N(1:4) 1 3 9 7 4 8 2 5 6 10 11 12 14 15 16 13 N = N(10:12)

Defining Matrices 1 3 9 7 4 8 N = N(1:2,1:2) N(3:4,3:4) 2 5 6 10 11 12 2 5 6 10 11 12 14 15 16 13 N = N(3:4,3:4)

Defining Matrices N(:,1:2) 1 3 9 7 4 8 2 5 6 10 11 12 14 15 16 13 N =

Defining Matrices 1 3 9 7 4 8 2 5 6 10 11 12 14 15 16 13 N = N(3:4,:)

Exercise#4 (i) N’ (ii) M*N (iii) M/N Investigate the effect of the following commands: M=[1 2; 3 4] N=[-1 3; 5 2] (i) N’ (ii) M*N (iii) M/N (iv) M + N (v) M*z(1:2) (vi) v(3:4)*M (vii) M(1,1) (viii) M(1:2,1:2) (ix) M(:,1) (x) M(2,:)

Exercise#5 (i) K = inv(M) (ii) I = eye(2) (iii) rank(M) Investigate the effect of the following commands: M=[1 2; 3 4] (i) K = inv(M) (ii) I = eye(2) (iii) rank(M) (iv) Zeros(3) (v) Zeros(3,2) (vi) ones(4) (vii) ones(4,5) (viii) tril(M) (ix) triu(M) (x) diag(M) (xi) size(M) (xii) det(M) (xiii) eig(M) (xiv) magic(3)

Exercise#6 Define a matrix A of dimension 2 x 4 whose (i,j) entry is A(i,j)=i+j Extract two 2 x 2 matrices A1 and A2 out of the matrix A. A1 contains the first two columns of A, A2 contains the last two columns of A Compute the matrix B to be the sum of A1 and A2 Compute the eigen values and eigen vectors of B Compute the determinant of B Compute the inverse of B Compute the rank of B

Defining Character Arrays (Strings) Character arrays are created using single quote delimiter >> str = ‘MATLAB‘ Yields str = MATLAB 1x6 vector str = M A L B T 1 2 3 4 5 6

Defining Character Arrays (Strings) >> str = ‘MATLAB‘ str = M A L B T 1 2 3 4 5 6 str(5:6) str(3)

Conversion B/W Numeric & String Arrays To convert from numeric to string array num2str To convert from string array to numeric array str2num

Numeric to string conversion >> strnum=num2str(num); >> whos Name Size Bytes Class strnum 1x3 6 char array num 1x1 8 double array Grand total is 4 elements using 14 bytes

String to Numeric conversion >> num=str2num(str); >> whos Name Size Bytes Class num 1x1 8 double array str 1x4 8 char array Grand total is 5 elements using 16 bytes

Thank you for your concentration Questions