Introduction To MATLAB Prof. Muhammad Saeed Mathematical Modeling and Simulation.

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

Introduction to Matlab
S i m u l i n k Prof. Muhammad Saeed Mathematical Modeling and Simulation UsingMATLAB 1.
Introduction To MATLAB Prof. Muhammad Saeed Mathematical Modeling and Simulation.
Problem Solving & Program Design in C Sixth Edition By Jeri R. Hanly & Elliot B. Koffman 1-1.
0 - 0.
ADDING INTEGERS 1. POS. + POS. = POS. 2. NEG. + NEG. = NEG. 3. POS. + NEG. OR NEG. + POS. SUBTRACT TAKE SIGN OF BIGGER ABSOLUTE VALUE.
MULTIPLICATION EQUATIONS 1. SOLVE FOR X 3. WHAT EVER YOU DO TO ONE SIDE YOU HAVE TO DO TO THE OTHER 2. DIVIDE BY THE NUMBER IN FRONT OF THE VARIABLE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Addition Facts
Functions M-file with the function keyword. First line: –[myout1, myout2,..] = myfunction(a, b,…) Function called by name of m-file, not function name,
Matlab Intro Simple introduction to some basic Matlab syntax. Declaration of a variable [ ] Matrices or vectors Some special (useful) syntax. Control statements.
Addition 1’s to 20.
Test B, 100 Subtraction Facts
Week 1.
Multidimensional Array
StatLab Workshop Yale University Maximiliano Appendino, Economics October 18 th, 2013.
ICE1341 Programming Languages Spring 2005 Lecture #16 Lecture #16 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Introduction to Matlab
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 10.
A MATLAB function is a special type of M-file that runs in its own independent workspace. It receives input data through an input argument list, and returns.
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
Lecture 4.
MATLAB Functions – Part II Greg Reese, Ph.D Research Computing Support Group Academic Technology Services Miami University September 2013.
MATLAB - Basics Centro de Informática Universidade Federal de Pernambuco Aprendizagem de Máquina – IN1102 Arley Ristar –
+ Review of Linear Algebra Introduction to Matlab / Machine Learning Fall 2010 Recitation by Leman Akoglu 9/16/10.
Introduction to Matlab By: Dr. Maher O. EL-Ghossain.
Lecture 7 Sept 19, 11 Goals: two-dimensional arrays (continued) matrix operations circuit analysis using Matlab image processing – simple examples Chapter.
Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples.
User-defined Functions Selim Aksoy Bilkent University Department of Computer Engineering
Matrix Mathematics in MATLAB and Excel
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Arithmetic Operations on Matrices. 1. Definition of Matrix 2. Column, Row and Square Matrix 3. Addition and Subtraction of Matrices 4. Multiplying Row.
M ATLAB Tutorial Course 1. Contents Continued  Desktop tools  matrices  Logical &Mathematical operations  Handle Graphics  Ordinary Differential.
1 M ATLAB Short Course. History of Calculator 2 3 Introduction to Matlab Matlab is short for Matrix Laboratory Matlab is also a programming language.
1 Week 3: Vectors and Matrices (Part III) READING: 2.2 – 2.4 EECS Introduction to Computing for the Physical Sciences.
Introduction to MATLAB CBE 502 Mathematical Methods of Engineering Analysis.
Hydroinformatics: Session4 Dr Ivan Stoianov Room 328B Dr Andrew Ireson (Room 304) Mr Juan Rodriguez-Sanchez (411A) Mr Baback.
Matlab Programming for Engineers Dr. Nidal Farhat Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
Function M-File Numerical Computing with. MATLAB for Scientists and Engineers.
26 - 3/20/2000AME 150L1 M ATLAB ® /20/2000AME 150L2 M ATLAB ® vs. Fortran Fortran Positives –First Compiler –Legacy Codes –Efficient Numerically.
Flow Control and Functions ● Script files ● If's and For's ● Basics of writing functions ● Checking input arguments ● Variable input arguments ● Output.
Advanced Topics- Functions Introduction to MATLAB 7 Engineering 161.
COMP 116: Introduction to Scientific Programming Lecture 11: Functions.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room , Chris Hill, Room ,
Chapter 6 Review: User Defined Functions Introduction to MATLAB 7 Engineering 161.
Introduction to Matlab. What is Matlab? A software environment for interactive numerical computations Examples:  Matrix computations and linear algebra.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
A string is an array of characters Strings have many uses in MATLAB Display text output Specify formatting for plots Input arguments for some functions.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
3.6 Solving Systems Using Matrices You can use a matrix to represent and solve a system of equations without writing the variables. A matrix is a rectangular.
Introduction to Matlab
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
1 Lecture 3 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Introduction to Matlab Patrice Koehl Department of Biological Sciences National University of Singapore
SCRIPTS AND FUNCTIONS DAVID COOPER SUMMER Extensions MATLAB has two main extension types.m for functions and scripts and.mat for variable save files.
Introduction to Programming on MATLAB Ecological Modeling Course Sep 11th, 2006.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
응용 전산 및 실습 MATLAB – Chapter 3 행렬연산
Introduction to Matlab
Introduction to Programming for Mechanical Engineers (ME 319)
Scripts & Functions Scripts and functions are contained in .m-files
Vectors and Matrices Chapter 2 Attaway MATLAB 4E.
Review of Linear Algebra Introduction to Matlab
Loop Statements & Vectorizing Code
Vectors and Matrices Chapter 2 Attaway MATLAB 4E.
Matlab Basics Tutorial
Loop Statements & Vectorizing Code
Presentation transcript:

Introduction To MATLAB Prof. Muhammad Saeed Mathematical Modeling and Simulation

Basic Features MATLAB Windows 1.Command ( << ) 2.Command History 3.Workspace 4.Current Directory 5.Editor 6.Profiler 7.Help Simple Math in Command Window 1.Operators: +, -, *, /, \, ^ 2.Variables: ans, pi, inf, NaN, i, j, realmin, realmax, ……, user-defined 2 Mathematical Modeling and Simulation

3.Precision: significant digits and formats a)format short, format short eand format short g b)format long, format long e, format long g c)format hex d)format bank e)format + 4.Complex numbers a)imag(), real(), abs() and angle() Display and Help 1.who, whos, clear, clear a*, clear –regexp, clc, disp, ver, version, diary, commands 2.Comments in MATLAB (%) 3.Ellipses ( … ) and ; at the end of commands 4.Built-in Functions and Help using fx, start and Help 3 Mathematical Modeling and Simulation

Arrays and Matrices 1.Initialization: i.Row Matrix: a=[1,2,3,4], [ ], [1:1:4] or [1:4] a=1:2:20, b=1:10,(1:1:10), (1:7) ii.Column Matrix: a=[1;2;3;4] iii.3x3 Matrix: d3=[1,2,3;4,5,6;7,8,9], [1 2 3;4 5 6;7,8,9], [1:3;4:6;7:9], [1:exp(1.4567):100], angle=[0:pi/10:pi] iv.sine=sin(angle) v. d=[a b], d=[a b;b a] or d=[a b b], c(:)=1.5 vi. x=(0:0.1:2)*pi, linspace(0,2*pi,21), logspace(0, 3, 5) vii. ones(n, m), ones(n), zeros(n), zeros(n, m), eye(n), eye(n, m), rand(n), rand(n, m), randn(n), randn(n, m), randi(10,5), randperm(n), diag([ ]), diag(a), diag(a, n), diag(a,-n) 4 Mathematical Modeling and Simulation

2.Operations: i.a(2), a(2:6), a(3:end), a(12:-1:5), a(3:1:9), a([ ]) ii.Transpose : a., [1:5], (0:0.1:1) iii.Conjugate Transpose : a iv.Maths: 3*(a-1), a*2, 3\a, a/3, a+4, a+b, a*b, a.*b, a./b, a^2, a.^2, 2./a v.Extraction: a=b([2 3],[1 3 4]), a=b(:,1:3) 3.Special Functions: sort(a), sort(a,ascend), sort(a,descend), sort(a,1), sort(a,2), sortrows(a), sortrows(a,1), sortrows(a,[1 3]), sortrows(a,-2), find(a>7), find(a, k), find(a, k, first), find(a, k,last), max(a), min(a), flipud(a), fliplr(a), rot90(a), rot90(a,2), triu(a). tril(a), ……………….. continued 5 Mathematical Modeling and Simulation ….. Arrays and Matrices

66 Mathematical Modeling and Simulation repmat(a,1,4),repmat(a, 2, 2), repmat(pi,size(a)), repmat(pi, 2, 3), reshape(a, 4, 3), reshape(1:10, 2, 5) numel(a), length(a), size(a), size(a,1), size(a,2), ndims(a), prod(a), prod(a,1), prod(a,2), dot(a,b), cross(a,b), sub2ind(size(a),3,5), ind2sub(size(a),15), sum(a), diag(diag(a)), blkdiag(a,b,c), ….. Arrays and Matrices

4.Data Types: declaration, conversion and display int8, uint8……. Int64, uint64, char, double, single, inf, NaN, ones(n,m,uint32), cast(a,int16), class(a), realmax(type), realmin(type), intmin, intmax, num2str, int2str, mat2str, str2double, str2num, strmatch(…, str), regexp, regexpi sprintf(…..), fprintf(….. ) 5.Operators: +, -, *, /, \, ^, =,, =, ==, ~=,,.,.*,./,.^,.\ &, |, ~, &&, || 7 Mathematical Modeling and Simulation ….. Arrays and Matrices

88 Mathematical Modeling and Simulation Basic Matrix Functions 1.rank(a) 2.inv(A) 3.A\y, solves set of linear equations, A is a matrix and y is a vector 4.det(A) 5.eig(A), [v d]=eig(A) calculates eigen values and eigen vectors 6.trace(A) 10.sp=sparse(A), 11. full(sp) 12. or(a,b) 13. xor(a,b)

99 Mathematical Modeling and Simulation M-File Scripts 1.Specific Functions used in M-Files: echo, disp, input, keyboard, pause, pause(n), waitforbuttonpress 2.All functions and control statements of MATLAB can be used in script files. 3.Extension is m ( file.m ) 4.M-File directly runs on the command line ( >>) as simple statements do. It is evaluated in MATLAB workspace.

10 Mathematical Modeling and Simulation 1.Function name must be identical to M-File name. 2.Function start with function keyword and ends with end keyword 3.1 st line in M-File must be the function declaration 4.The error and warning functions in the M-File are like sprintf 5.Script file called in a function is evaluated in function workspace 6.Subfunctions are called from the 1 st functions body 7.Help for subfunction can be displayed by >>helpwin func/subfunc 8.Functions can have zero input or zero output arguments. 9.Functions can be called with fewer input and output arguments than are specified in the function definition but not with more arguments than specified. M-File Functions

11 Mathematical Modeling and Simulation ……….. M-File Functions 10.Function arguments can be determined by two variables: nargin and nargout. 11.The first set of contiguous comment lines after the function declaration are the help text for the function 12.The return statement is not necessary. 13.Script file called in a function is evaluated in function WS 14.Unlimited number of input and output arguments by specifying varargin as the last argument and varargout for output arguments. 15.pcode command compiles the function 16.Functions can be nested. 17. One-Lineinline functions can be defined as in C (by #define) 18.Anonymous functions are defined by handles. 19. Handles of MATLAB functions can also be created

12 Mathematical Modeling and Simulation Set Functions 1.isequal(a, b), compares as a whole 2.unique(a), removes duplications 3.ismember(a,b), ismember(a,xyz), element by element 4.union(a,b), must be rows or columns 5.intersect(a,b) 6.diff(a) Base Conversion Functions 1.dec2bin(x), bin2dec(x) 2.dec2hex(x), hex2dec(x) 3.dec2base(x, base), base2dec(x, base) Precision Functions digits(n), vpa(pi), vpa(x, d), vpa(pi)

13 Mathematical Modeling and Simulation Data Analysis 1.mean(a), for a 2D matrix each rows s mean will be calculated. 2.mean(a,1), row values are averaged 3.mean(a,2), column values are averaged 4.median(a) 4.std(a), standard deviation 5.var(a), Variance 5.cov(a), covariance 6.corrcoef(a), correlation coefficient 7.diff(a), rows are subtracted 8.min(a) 9.max(a) 10.cumsum(a) 11.cumprod(a)

End 14 Mathematical Modeling and Simulation