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

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

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

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

Introduction to Matlab

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

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

Some elements for Matlab programming

Introduction to MatLab. Introduction to MatLab K. Craig 1

Fundamentals of MATLAB Usage

Lecturer: Keyvan Dehmamy

Getting Started with MATLAB

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

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

Introduction to MATLAB

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS

A Guide to Using Some Basic MATLAB Functions

MATLAB and Numerical Analysis

MATLAB Lecture 1. Introduction to MATLAB

Learning from Data Introduction to Matlab

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix.

Computational Foundations of Cognitive Science. Inverse. Inverse. Inverse Determinant

Programming in Mathematics. Mili I. Shah

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

LabVIEW MathScript Quick Reference

MATH 3511 Basics of MATLAB

CS129: Introduction to Matlab (Code)

Matlab Tutorial, CDS

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

Grace days can not be used for this assignment

Introduction to MATLAB

Introduction to MATLAB. CS534 Fall 2016

Fall 2015 Math 337. Basic MatLab

Mathematical Operations with Arrays and Matrices

MATH 5520 Basics of MATLAB

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

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

MATLAB Premier. Middle East Technical University Department of Mechanical Engineering ME 304 1/50

A very brief Matlab introduction

Introduction to GNU-Octave

Introduction to Matlab

Introduction to Matlab

A Brief Introduction to MATLAB

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

ENGR Fall Exam 1

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

Entering the numbers in these two ways creates the same matrix A.

Fall 2014 MAT 375 Numerical Methods. Introduction to Programming using MATLAB

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

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

A 30 Minute Introduction to Octave ENGR Engineering Mathematics Tony Richardson

A Quick Tutorial on MATLAB. Zeeshan Ali

Eng Marine Production Management. Introduction to Matlab

What is Matlab? A software environment for interactive numerical computations

2.0 MATLAB Fundamentals

Chapter 1 MATLAB Preliminaries

Stokes Modelling Workshop

Laboratory 1 Octave Tutorial

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

STAT/MATH 395 A - PROBABILITY II UW Winter Quarter Matlab Tutorial

Image Processing CS 6640 : An Introduction to MATLAB Basics Bo Wang and Avantika Vardhan

ENGR Fall Exam 1

Lecture 2: Variables, Vectors and Matrices in MATLAB

Signals and Systems Profs. Byron Yu and Pulkit Grover Fall Homework 1

Chapter 1 Introduction to MATLAB

How to Use MATLAB. What is MATLAB. Getting Started. Online Help. General Purpose Commands

Introduction to Matlab

Chapter 2 (Part 2) MATLAB Basics. dr.dcd.h CS 101 /SJC 5th Edition 1

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

(5) ifit/math: «One Class to do some Math» God damn it! Just compute it! ifit workshop NBI Jan 2012 Math - 1

FreeMat Tutorial. 3x + 4y 2z = 5 2x 5y + z = 8 x x + 3y = -1 xx

AMATH 352: MATLAB Tutorial written by Peter Blossey Department of Applied Mathematics University of Washington Seattle, WA

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

PART 1 PROGRAMMING WITH MATHLAB

MATLAB Basics. Mohamed Taha. Communication Engineering Department Princess Sumaya University Page 1 of 32. Full Screen.

INTRODUCTION TO MATLAB (MATrix LABoratory): INTUITIVE APPROACH

Math Scientific Computing - Matlab Intro and Exercises: Spring 2003

Introduction to MATLAB programming: Fundamentals

Introduction to MATLAB

How to learn MATLAB? Some predefined variables

Short Introduction into MATLAB

What is MATLAB and howtostart it up?

Getting started with MATLAB

Math 375 Natalia Vladimirova (many ideas, examples, and excersises are borrowed from Profs. Monika Nitsche, Richard Allen, and Stephen Lau)

PC-MATLAB PRIMER. This is intended as a guided tour through PCMATLAB. Type as you go and watch what happens.

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis

Matlab course at. P. Ciuciu 1,2. 1: CEA/NeuroSpin/LNAO 2: IFR49

MATLAB Functions and Graphics

The Mathematics of Big Data

Brief Matlab tutorial

Introduction to MATLAB

Introduction to Matlab. By: Hossein Hamooni Fall 2014

Variable Definition and Statement Suppression You can create your own variables, and assign them values using = >> a = a = 3.

A. Matrix-wise and element-wise operations

Basics. Bilkent University. CS554 Computer Vision Pinar Duygulu

Matlab and Psychophysics Toolbox Seminar Part 1. Introduction to Matlab

Introduction to Matlab

EE 350. Continuous-Time Linear Systems. Recitation 1. 1

Table of Contents. Basis CEMTool 7 Tutorial

Matlab Tutorial 1: Working with variables, arrays, and plotting

BSM510 Numerical Analysis

Transcription:

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

Objective Learn a useful tool for mathematical analysis and simulation Interpreted language, easy to learn Use it to facilitate our simulation projects A good tool to plot simulation/experiment results figures for academic papers More powerful than excel Could directly create.eps for Latex 2

Introduction MatLab : Matrix Laboratory Numerical Computations with matrices Every number can be represented as matrix Why Matlab? User Friendly (GUI) Easy to work with Powerful tools for complex mathematics Matlab has extensive demo and tutorials to learn by yourself Use help command 3

Matlab Software Access all UCF in-campus computers have student-version Matlab installed If you have no access to Matlab, you can use Octave, an open-source free software http://www.gnu.org/software/octave/ The programming should be almost identical 4

Matrices in Matlab 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) 5

Basic Mathematical Operations Remember that every variable can be a matrix! 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) 6

Generating basic matrices Matrix with ZEROS: >> A = zeros(m, n) Matrix with ONES: >> B = ones(m, n) IDENTITY Matrix: >> I = eye(m, n) m Rows n Columns zeros, ones, eye Matlab functions 7

Obtain 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 A(:, 2)=[] Delete second column 8

Basic Matrix Functions Inv(A): inverse of A Rank(A): rank of matrix A A : transpose of A Det(A): determinant V= eig(a): eigenvalue vector of A [V,D] = eig(a) produces matrices of eigenvalues (D) and eigenvectors (V) of matrix A, so that A*V = V*D 9

Random Number Generators Rand(m,n): matrix with each entry ~ U(0,1) You can use this for the programming project 1 Randn(m,n): standard normal distribution You cannot use this in programming project 1 You must use the polar method I introduced! 10

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]) Legend( ) Grid Example demo 11

Elementary Math Function Abs(), sign() Sign(A) = A./abs(A) Sin(), cos(), asin(), acos() Exp(), log(), log10() Ceil(), floor() Sqrt() Real(), imag() 12

Elementary Math Function Vector operation: Max(), min(): max/min element of a vector Mean(), median() Std(), var(): standard deviation and variance Sum(), prod(): sum/product of elements Sort(): sort in ascending order 13

Save fname Save/Load Data Save all workspace data into fname.mat Save fname x y z Save(fname): when fname is a variable Load fname Load fname x y No error in data You can run simulation intermittently Save/load data between runs 14

Input/Output for Text Files Input data file for further analysis in Matlab Run simulation using C matlab is slow in doing many loops Use Matlab for post-data processing Matrix calculation, utilize Matlab math functions Simply use Matlab for figure ploting Excel has constraint on data vector length (<300?) Functions: [A,B ]= Textread(fname, format) Read formated data Use fprintf(), fscanf() similar to C Note that variables here can be vectors/matrices Show examples here of writing data to text file 15

Subplot(m, n, p) Advanced Graph breaks the Figure window into an m-by-n matrix of small axes, selects the p-th axes for the current plot, and returns the axis handle. Semilogx(), semilogy(), loglog() 16

3-D 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 17

M-file Script or function Scripts are m-files containing MATLAB statements Functions are like any other m-file, but they accept arguments It is always recommended to name function file the same as the function name function A = changesign(b) % change sign for each element [m,n] = size(b); A = zeros(m,n); for i=1:m for j=1:n A(i,j)= -B(i,j); end end return 18

Online Tutorials Matlab itself contains many tutorials Other online tutorials: http://www.math.siu.edu/matlab/tutorials.html http://www.cs.cmu.edu/~ggordon/780/lecture s/matlab_tutorial.pdf Google search matlab tutorial ppt to find a lot more 19

Example on Using Matlab for Markov Chain Steady State Calculation 20

Discrete-time Markov Chain transition matrix: ¼ P = ¼, ¼ [1 1 1 1] T = 1 ¼ (P I) = 0, But we cannot use it directly Replace first column in (P-I) with [1 1..1] T to be A, then we can solve the linear equation set by ¼ = [1 0 0 0] A -1 Another way: P*P*P*P 21

Tutorial on Matlab Simulink 22

Graphical programming language Drag and draw line to program Configure each object for parameters Powerful modeling tool Differential Equations Physiological systems Control systems Transfer functions M-file can call a simulink model sim fname Use current workspace variables Simulation results can be saved to workspace variables Thus can be process after simulink 23

Example: Internet Worm Propagation di(t) dt = I(t) [N I(t)] N: vulnerable population : worm host average scan rate Ω: scanning IP space size 24

Example 2: RC Circuit Transfer function: 25

Save result to workspace variables the save format is "structure with time". Suppose the workspace variable is X_t. Then: X_t.time saves the simulation step times (vector) X_t.signals.values saves the simulation results (vector). plot(x_t.time, X_t.signals.values); Variable step simulation or fixed step simulation: "to workspace" use "-1" for sample time (inherited) Then X_t.time has variable size "to workspace" use "1" for sample time Then each time tick has one result value 26