Introduction to MATLAB. Computational Probability and Statistics CIS 2033 Section 003

Similar documents
CDA5530: Performance Models of Computers and Networks. Chapter 8: Using Matlab for Performance Analysis and Simulation

CDA6530: Performance Models of Computers and Networks. Chapter 4: Using Matlab for Performance Analysis and Simulation

CDA6530: Performance Models of Computers and Networks. Chapter 4: Using Matlab for Performance Analysis and Simulation

Introduction to Matlab

Introduction to Engineering gii

To start using Matlab, you only need be concerned with the command window for now.

Chapter 1 Introduction to MATLAB

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

Introduction to MATLAB

Introduction to MATLAB

Outline. CSE 1570 Interacting with MATLAB. Outline. Starting MATLAB. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

Quick MATLAB Syntax Guide

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline (Cont d) MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP)

Lecturer: Keyvan Dehmamy

Introduction to MatLab. Introduction to MatLab K. Craig 1

Programming in Mathematics. Mili I. Shah

PART 1 PROGRAMMING WITH MATHLAB

Starting Matlab. MATLAB Laboratory 09/09/10 Lecture. Command Window. Drives/Directories. Go to.

Matlab Programming Introduction 1 2

PROGRAMMING WITH MATLAB DR. AHMET AKBULUT

Chapter 3. built in functions help feature elementary math functions data analysis functions random number functions computational limits

Introduction to MATLAB programming: Fundamentals

Chapter 2. MATLAB Basis

MATLAB Tutorial The Basics

Welcome to EGR 106 Foundations of Engineering II

MATLAB Tutorial EE351M DSP. Created: Thursday Jan 25, 2007 Rayyan Jaber. Modified by: Kitaek Bae. Outline

Introduction to MATLAB for Numerical Analysis and Mathematical Modeling. Selis Önel, PhD

What is MATLAB? What is MATLAB? Programming Environment MATLAB PROGRAMMING. Stands for MATrix LABoratory. A programming environment

Introduction to MATLAB

Part V Appendices c Copyright, Todd Young and Martin Mohlenkamp, Department of Mathematics, Ohio University, 2017

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial

MATLAB QUICK START TUTORIAL

Digital Image Analysis and Processing CPE

SECTION 1: INTRODUCTION. ENGR 112 Introduction to Engineering Computing

Introduction to Python, Cplex and Gurobi

What is a Function? EF102 - Spring, A&S Lecture 4 Matlab Functions

Stokes Modelling Workshop

A Quick Tutorial on MATLAB. Zeeshan Ali

Experiment 1: Introduction to MATLAB I. Introduction. 1.1 Objectives and Expectations: 1.2 What is MATLAB?

MATLAB Lesson I. Chiara Lelli. October 2, Politecnico di Milano

What is Matlab? The command line Variables Operators Functions

Introduction to MATLAB. Simon O Keefe Non-Standard Computation Group

Lab of COMP 406. MATLAB: Quick Start. Lab tutor : Gene Yu Zhao Mailbox: or Lab 1: 11th Sep, 2013

2.0 MATLAB Fundamentals

Lab 1 - Worksheet Spring 2013

Introduction to Matlab

9 Using Equation Networks

Introduction to MATLAB

Consider this m file that creates a file that you can load data into called rain.txt

LabVIEW MathScript Quick Reference

CSI31 Lecture 5. Topics: 3.1 Numeric Data Types 3.2 Using the Math Library 3.3 Accumulating Results: Factorial

Matlab Tutorial, CDS

MATLAB. A Tutorial By. Masood Ejaz

Introduction to MATLAB Practical 1

selected topic in transportation 2552/2. 1 Prepared by Lect.Weerakaset Suanpaga

This is a basic tutorial for the MATLAB program which is a high-performance language for technical computing for platforms:

Introduction to PartSim and Matlab

MATLAB Fundamentals. Berlin Chen Department of Computer Science & Information Engineering National Taiwan Normal University

A Quick Introduction to MATLAB/Octave. Kenny Marino, Nupur Chatterji

Introduction to Matlab

MATLAB and Numerical Analysis

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

CME 192: Introduction to Matlab

A very brief Matlab introduction

Python Lists: Example 1: >>> items=["apple", "orange",100,25.5] >>> items[0] 'apple' >>> 3*items[:2]

Introduction to MATLAB for Engineers, Third Edition

Programming in MATLAB

Introduction to Computer Programming with MATLAB Matlab Fundamentals. Selis Önel, PhD

LAB 1 General MATLAB Information 1

Introduction to Matlab. By: Dr. Maher O. EL-Ghossain

Chapter 2. MATLAB Fundamentals

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS

Introduction to GNU-Octave

MATLAB Vocabulary. Gerald Recktenwald. Version 0.965, 25 February 2017

Finding, Starting and Using Matlab

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

Introduction to MATLAB

Extending Ninox with NX

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices

OUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors.

INTRODUCTION TO MATLAB

Getting started with MATLAB

Introduction to MATLAB LAB 1

MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras

Some elements for Matlab programming

Chapter 1 MATLAB Preliminaries

MATH (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

! The MATLAB language

Math Sciences Computing Center. University ofwashington. September, Fundamentals Making Plots Printing and Saving Graphs...

Part #1. A0B17MTB Matlab. Miloslav Čapek Filip Kozák, Viktor Adler, Pavel Valtr

12 whereas if I terminate the expression with a semicolon, the printed output is suppressed.

Chapter 4: Basic C Operators

EP375 Computational Physics

Numerical Analysis First Term Dr. Selcuk CANKURT

Introduction to Matlab

Introduction to Python Practical 1

A Short Introduction to Matlab

Transcription:

Introduction to MATLAB Computational Probability and Statistics CIS 2033 Section 003

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

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-licensedsoftware

Matlab Layouts Layouts of versions MATLAB 1.0 to MATLAB 8.2 Editor Workspace Current folder view Command Window Command History

Matlab Layouts new movement Layouts of versions MATLAB 8.3 - Editor/Variables View Current Window Workspace Command Window

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.

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 inf Smallest difference between two numbers MATALB can see Stands for an infinite value NaN Undefined value (Not-a-Number), Ex. 0/0 i Imaginary one

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:

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

Matlab Structures, Contd. 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 end >> D =[]; D=[D;5]; D=[D;6;7] >> E = zeros(4, 5) Matrices and Vectors

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)

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)

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

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

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

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

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

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

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

Programming in MATLAB Control Flow MATLAB allows control flow operations: Conditional statements, loops, branching

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

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); 100 100 80 80 60 60 40 40 20 20 0 10 5 0 0 2 4 6 8 10 0 10 5 0 0 2 4 6 8 10

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

End of MATLAB introduction Any Questions?