Introduction to MATLAB

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 The language of Technical Computing.
Introduction to Matlab
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
Lecture 6 MATLAB functions Basics of Built-in Functions, Help Feature, Elementary Functions (e.g., Polynomials, Trigonometric Functions), Data Analysis,
Introduction to MATLAB Simon O’Keefe Non-Standard Computation Group
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
Introduction to MATLAB ES 156 Signals and Systems 2008 Harvard SEAS.
Introduction to MATLAB ES 156 Signals and Systems 2007 Harvard SEAS Prepared by Jiajun Gu.
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.
Matlab intro The Environment
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
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.
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
Martin Ellison University of Warwick and CEPR Bank of England, December 2005 Introduction to MATLAB.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
Nonparametric Econometrics1 Intro to Matlab for Data Analysis and Statistical Modeling.
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU.
Introduction to MATLAB
Introduction to MATLAB. Windows in MATLAB Command Window – where you enter data, run MATLAB code, and display results Command History - displays a log.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
Recap Graphic Window Edit Window Start Button Matrices in MATLAB Scalar Operations Order of Operations Array Operations Matrix Addition Matrix Multiplication.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Introduction to MATLAB Computational Probability and Statistics CIS 2033 Section 003 Djordje Gligorijevic, Temple University, Fall 2015.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
Introduction to MATLAB CBE 502 Mathematical Methods of Engineering Analysis.
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB is a powerful program for numerical computations, plotting and programming.
Introduction to MATLAB ENGR 1181 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Introduction to Engineering MATLAB – 1 Introduction to MATLAB Agenda Introduction Arithmetic Operations MATLAB Windows Command Window Defining Variables.
MATLAB An Introduction to MATLAB (Matrix Laboratory) 1.
EECE 360/460 Matlab Tutorial Jan Outline What is Matlab? What is Matlab? Matlab Interface Matlab Interface Basic Syntax Basic Syntax Plotting Graphs.
INTRODUCTION TO MATLAB LAB# 01
CDA6530: Performance Models of Computers and Networks Chapter 4: Using Matlab for Performance Analysis and Simulation TexPoint fonts used in EMF. Read.
Introduction to Matlab
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
(The Transpose Operator) 1 >> C=[ ; ; ] C = >> D=C' D =
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
ECE 351 M ATLAB I NTRODUCTION ( BY T EACHING A SSISTANTS )
1 Lecture 3 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
MATLAB Lecture 1 염익준. Introduction MATLAB (MATrix LABoratory) a special purpose computer program optimized to perform engineering and scientific calculations.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
An Introduction to Programming in Matlab Emily Blumenthal
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
Outline What is MATLAB MATLAB desktop Variables, Vectors and Matrices Matrix operations Array operations Built-in functions: Scalar, Vector, Matrix Data.
Introduction to Programming
Introduction To MATLAB
Introduction to MATLAB
Numeric, Cell and Structural Arrays One of the strenghts of MATLAB is the capabilty to handle collection of numbers called ARRAYS. MATLAB refers to scalars,
ECE 1304 Introduction to Electrical and Computer Engineering
Built-in MATLAB Functions Chapter 3
Introduction to Mat lab
Introduction to Programming
Computer Simulation Lab
TexPoint fonts used in EMF.
MATLAB DENC 2533 ECADD LAB 9.
Matlab Workshop 9/22/2018.
Introduction To MATLAB
StatLab Matlab Workshop
Use of Mathematics using Technology (Maltlab)
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
Introduction to Programming
Introduction to Programming
Communication and Coding Theory Lab(CS491)
Introduction to Programming
How to Use MATLAB A Brief Introduction.
Computer Simulation Lab
Presentation transcript:

Introduction to MATLAB Computational Probability and Statistics CIS 2033 Section 003 Djordje Gligorijevic, Temple University, Spring 2015

Djordje Gligorijevic, Temple University, Spring 2015 About MATLAB MATLAB (MATrix LABoratory) is a high level language made for: Numerical Computation (Technical computing) Visualization Application Development Everything is a matrix – easy to do Linear Algebra and other mathematical fields that use Linear Algebra (Statistics, Fourier Analysis, Optimization, Filtering,…) Useful tool for mathematical analysis and simulation Djordje Gligorijevic, Temple University, Spring 2015

MATLAB Software Access All Temple University in-campus computers have student-version MATLAB installed Temple University also provides a student license for every student, just go to MATLAB Site Licensed Software page: https://computerservices.temple.edu/matlab-site-licensed-software Djordje Gligorijevic, Temple University, Spring 2015

Layouts of versions MATLAB 1.0 to MATLAB 8.2 Matlab Layouts Layouts of versions MATLAB 1.0 to MATLAB 8.2 Editor Workspace Current folder view Command Window Command History Djordje Gligorijevic, Temple University, Spring 2015

Matlab Layouts – new movement Layouts of versions MATLAB 8.3 - Editor/Variables View Current Window Workspace Command Window Djordje Gligorijevic, Temple University, Spring 2015

Djordje Gligorijevic, Temple University, Spring 2015 MATLAB competition Due to its cost, MATLAB has a hard time finding a dominance in the industry. Other languages provide a “bigger bang for the buck” thanks to the active communities that maintain widely used libraries. An examples of such languages that have became a “hot topic” recently are: Python (NumPy, SciPy, Matplotlib, SciKit Learn,…) R However, MATLAB is still completely dominating when it comes to performance. Djordje Gligorijevic, Temple University, Spring 2015

There are a few predefined variables in MATLAB: MATLAB Variables There are a few predefined variables in MATLAB: ans   Variable which has been assigned a value of most recent expression, which hasn’t had assigned a value of its output to a specific variable pi Number pi = 3.1415926535897932384626433832795 eps Smallest difference between two numbers MATALB can see  inf Stands for an infinite value NaN Undefined value (Not-a-Number), Ex. 0/0 i Imaginary one Djordje Gligorijevic, Temple University, Spring 2015

Djordje Gligorijevic, Temple University, Spring 2015 Matlab Structures Numeric Types: Matlab provides wide range of numerical and floating point types such are double, int (8,16,32 and 64 bits), uint ( 8,16,32,64 bits). Some functions on numeric types: Djordje Gligorijevic, Temple University, Spring 2015

Elementary math functions sqrt(x) Square root   sin(x) Sinus x (in radians) exp(x) Exponential function - ex cos(x) Cosinus s abs(x) Absolute value tan(x) Tangens x log(x) Natural logarithm - ln(x), loge(x) cot(x) Cotangens x log10(x) Logarithm with basis 10 round(x) Round to an integer factorial(x) Factoriel x – x! ceil(x) Round to higher value fix(x) Round to lower value rem(y,x) Remainder of x/y division sign(x) Signum function Djordje Gligorijevic, Temple University, Spring 2015

Matlab Structures, Contd. Matrices and Vectors To enter a matrix: 2 5 3 6 4 1 >> A = [2, 5, 3; 6, 4, 1] >> B = [1:1.5:6; 2 3 4 5] >> for i=1:4 for j=1:3 C(i,j)=i*j; end >> D =[]; D=[D;5]; D=[D;6;7] >> E = zeros(4, 5) Djordje Gligorijevic, Temple University, Spring 2015

Matlab Structures, Contd. Matrices and Vectors As every variable in MATLAB can be a matrix, we can do basic operations on them: Addition: >> C = A + B Subtraction: >> D = A – B Multiplication: >> E = A * B (Matrix multiplication) >> E = A .* B (Element wise multiplication, A and B same size) Division: Left Division and Right Division >> F = A . / B (Element wise division) >> F = A / B = A*inv(B) (A * inverse of B) >> F = A . \ B (Element wise division) >> F = A \ B=inv(A)*B (inverse of A * B) Djordje Gligorijevic, Temple University, Spring 2015

Elementary matrix functions max Maximum of elements   + Matrix addition min Minimum of elements - Matrix substraction sum Sum of elements * Matrix multiplication prod Product of elements / Matrix division median Median (Middle value) \ Left matrix division mean Mean (Agerage) ^ Power std Standard deviation ' Transpose any Is there any zero inv Inverse of the matrix Never use it!!!! all Are all elements zero sort Sort columns (or rows) Djordje Gligorijevic, Temple University, Spring 2015

Generating basic matrices Matrix with ZEROS: >> A = zeros(m, n) Matrix with ONES: >> B = ones(m, n) IDENTITY Matrix: >> I = eye(m, n) RANDOM Matrix: >> I = rand(m, n) MAGIC SQUARE Matrix: >> I = magic(n) m  Rows n  Columns zeros, ones, eye, rand, magic  Matlab functions Djordje Gligorijevic, Temple University, Spring 2015

Random Number Generators Rand(m,n): matrix with each entry ~ U(0,1) Randn(m,n): standard normal distribution Mvnrnd(Mu, Sigma): Multivariate normal random numbers Djordje Gligorijevic, Temple University, Spring 2015

Array indexing, obtaining information Size(A): return [m n] Length(A): length of a vector Length(A) = max(size(A)) B = A(2:4,3:5) B is the subset of A from row 2 to row 4, column 3 to column 5 C = A(2) C is a scalar with value of second index in matrix A Matlab matrix indicies go iteratively top-down, column by column D = A(:, [1,15,20]) Select all rows but a few columns A(:, 2)=[] Delete second column Djordje Gligorijevic, Temple University, Spring 2015

Characters and Strings A sequence of characters enclosed in single quotes  assign a string to a variable A = ‘Alice’ use two single quotes within the definition if  the text includes  a single quote Concatenaton   With square brackets  as concatenate numeric arrays A = [‘Alice’, ’followed’, ’the’, ’rabbit.’] Convert numeric values to strings num2str int2str   Djordje Gligorijevic, Temple University, Spring 2015

Djordje Gligorijevic, Temple University, Spring 2015 Save/Load Data Save fname Save all workspace data into fname.mat Save fname x y z Save(fname): when fname is a variable Save large files save('fname.mat','fname','-v7.3'); Load fname Load fname x y No error in data You can run simulation intermittently Save/load data between runs Djordje Gligorijevic, Temple University, Spring 2015

Programming in MATLAB - Scripts A file with a .m extension containing Multiple sequential lines of MATLAB commands Function calls To run a script Save a file in the current folder and type its name at the command line Run scripts from the Editor by pressing the Run button Comments To describe the code Add comments whenever you write code For comments add % symbol first Djordje Gligorijevic, Temple University, Spring 2015

Programming in MATLAB - Functions Equivalent to subroutines or methods in other programming languages To call a function, enclose its input arguments in parentheses If there are multiple input arguments, separate them with commas Return output from a function by assigning it to a variable When there are multiple output arguments, enclose them in square brackets To call a function that does not require any inputs and does not return any outputs, type only the function name Djordje Gligorijevic, Temple University, Spring 2015

Programming in MATLAB – Control Flow MATLAB allows control flow operations: Conditional statements, loops, branching Djordje Gligorijevic, Temple University, Spring 2015

Plotting in MATLAB – Basic 2-D Figure Plot Plot(X, Y): Plots vector Y versus vector X Hold: next plot action on the same figure Title(‘title text here’) Xlabel(‘…’), ylabel(‘…’) Axis([XMIN XMAX YMIN YMAX]) Or use xlim or ylim Legend(‘…’) Grid Example demo Djordje Gligorijevic, Temple University, Spring 2015

Plotting in MATLAB – Basic 3-D Figure Plot x=[0:10]; y=[0:10]; z=x’*y; mesh(x,y,z); figure; surf(x,y,z); Djordje Gligorijevic, Temple University, Spring 2015

Djordje Gligorijevic, Temple University, Spring 2015 MATLAB – Help The most important thing to remmember about MATLAB – it has great Help and Documentation Just press Shift + F1 to search for needed function Or select a function and press F1 Djordje Gligorijevic, Temple University, Spring 2015

End of MATLAB introduction Any Questions? Djordje Gligorijevic, Temple University, Spring 2015