Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

Similar documents
Matlab and Octave: Quick Introduction and Examples 1 Basics

AN INTRODUCTION TO MATLAB

Laboratory 1 Octave Tutorial

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

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

Creates a 1 X 1 matrix (scalar) with a value of 1 in the column 1, row 1 position and prints the matrix aaa in the command window.

A Guide to Using Some Basic MATLAB Functions

MATLAB Basics. Configure a MATLAB Package 6/7/2017. Stanley Liang, PhD York University. Get a MATLAB Student License on Matworks

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

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

Some elements for Matlab programming

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

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

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

Colorado State University Department of Mechanical Engineering. MECH Laboratory Exercise #1 Introduction to MATLAB

Eric W. Hansen. The basic data type is a matrix This is the basic paradigm for computation with MATLAB, and the key to its power. Here s an example:

Introduction to MATLAB

EE 301 Signals & Systems I MATLAB Tutorial with Questions

Introduction to MatLab. Introduction to MatLab K. Craig 1

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

University of Alberta

Introduction to MATLAB Practical 1

Introduction to Matlab

Introduction to GNU-Octave

2.0 MATLAB Fundamentals

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

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

Numerical Methods in Engineering Sciences

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

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah)

Introduction to MATLAB

PART 1 PROGRAMMING WITH MATHLAB

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

Finding, Starting and Using Matlab

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

A very brief Matlab introduction

Mathematical Operations with Arrays and Matrices

Interactive Computing with Matlab. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University

Introduction to Matlab

A Brief Introduction to MATLAB

An Introductory Tutorial on Matlab

Stokes Modelling Workshop

Matlab Tutorial. Get familiar with MATLAB by using tutorials and demos found in MATLAB. You can click Start MATLAB Demos to start the help screen.

Introduction to MATLAB LAB 1

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

Desktop Command window

Getting started with MATLAB

Introduction to MATLAB

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

An Introduction to MATLAB

MATLAB Premier. Asst. Prof. Dr. Melik DÖLEN. Middle East Technical University Department of Mechanical Engineering 10/30/04 ME 304 1

Dr Richard Greenaway

ELEN E3084: Signals and Systems Lab Lab II: Introduction to Matlab (Part II) and Elementary Signals

1 Introduction to Matlab

MATLAB BASICS. < Any system: Enter quit at Matlab prompt < PC/Windows: Close command window < To interrupt execution: Enter Ctrl-c.

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

Introduction to MATLAB programming: Fundamentals

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

McTutorial: A MATLAB Tutorial

Lecture 2: Variables, Vectors and Matrices in MATLAB

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

MATLAB for beginners. KiJung Yoon, 1. 1 Center for Learning and Memory, University of Texas at Austin, Austin, TX 78712, USA

MATLAB: The Basics. Dmitry Adamskiy 9 November 2011

MATLAB/Octave Tutorial

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

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

Lecturer: Keyvan Dehmamy

1 Overview of the standard Matlab syntax

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

MATLAB TUTORIAL WORKSHEET

An Introduction to MATLAB II

Introduction to MATLAB Programming

Introduction to Matlab

Introduction to Matlab

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

LAB 1: Introduction to MATLAB Summer 2011

Homework 1 Description CmpE 362 Spring Instructor : Fatih Alagoz Teaching Assistant : Yekta Said Can Due: 3 March, 23:59, sharp

A/D Converter. Sampling. Figure 1.1: Block Diagram of a DSP System

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

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

Chapter 2. MATLAB Fundamentals

Introduction to Matlab

Chapter 1 Introduction to MATLAB

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

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

Matlab Tutorial: Basics

AMS 27L LAB #2 Winter 2009

MATLAB Tutorial. 1. The MATLAB Windows. 2. The Command Windows. 3. Simple scalar or number operations

ECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu

Short Introduction into MATLAB

A very short introduction to Matlab and Octave

Programming in Mathematics. Mili I. Shah

Introduction to MATLAB

EGR 111 Introduction to MATLAB

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS

What is Matlab? A software environment for interactive numerical computations

Eng Marine Production Management. Introduction to Matlab

MatLab Just a beginning

Computational Finance

Transcription:

Introduction to Octave/Matlab Deployment of Telecommunication Infrastructures 1

What is Octave? Software for numerical computations and graphics Particularly designed for matrix computations Solving equations, computing eigenvalues, etc Many engineering problems can be expressed as matrices and vectors and solved using matrix operations Has it's own programming language Works like a very powerful, programmable, graphical calculator Is an open source software It is syntax compatible with MATLAB (a proprietary software with similar functionalities) 2

Why and when to use Octave? Why? Solutions to mathematical problems take time to program in a normal highlevel language like C++ or java Octave has many built-in mathematical functions When? When you want to solve mathematical problems numerically Is NOT designed to find exact symbolic solutions to problems (unlike Mathematica or Maple) 3

The basics Starting octave type octave on the command prompt. You are in octave environment when you see: octave:1> Input conventions Commands can be typed at the prompt or read from a script. Scripts are plain text files with file suffix.m. To run a script, type the script name without the suffix ; separates commands in a line and suppresses the output (use, to separate without suppressing the output) Comments are preceded by %. Octave is case-sensitive. 4

Basic operations Getting help help lists all built-in functions and internal variables. help name explains the variable or function name. Octave as a calculator Just type mathematical commands at the prompt use +, -, *, /, ^, (), etc. with normal precedence. octave:01> 5 + 3^2 It also has mathematical built-in functions examples: sin, cos, sqrt, log, log10, exp, abs,... Practice: Calculate 10 sin(90 ) + ln(e) Note 1: trigonometric functions work in radians Note 2: pi and e (and i, j) are predefined variables, the ans variable is used to hold the result of the last operation 5

Dealing with Variables No need to declare the variable or its type variables are either floating point numbers or strings var=expression assigns the result of expression to var octave:##> 6*2 octave:##> a = ans/3, b = ''example string'' To see the value of a variable just type its name and press return Some useful functions: who Lists all functions and variables you created or used clear removes all variables from the workspace Recommendation: Use this at the beginning of all scripts clear VariableName removes specified variable 6

Generating Vectors and Matrices Vectors: Try the following: aa = [0 1 2 3] bb = 1:4 cc = 0.3:-0.1:0 dd = [1;2;3;4] ee = cc' ff = aa(2:3) gg = [aa,cc,5] hh = linspace(.1,1,10) ii = logspace(2,6,5) length(ii) Matrices: Try the following AA = [1 2; 3 4] AA(2,1) AA(1,:) AA(:,2) BB = [aa(1:2); bb(3:4)] CC = ones(3,2) DD = zeros(2,3) AA = [AA,[0;0],AA'] EE = eye(size(aa)) FF = rand(2,2) 7

Notes on Matrices and Vectors Vectors are just a special case of matrices, or space add elements to the same row, while ; starts a new row (when generating a matrix). : specifies a range of numbers min:step:max step can be negative, step is 1 if not specified The indexes of matrices and vectors should be > 1 You can delete or modify rows or columns of a matrix by using a combination of what you learned: AA(1,:) = zeros(size(aa(1,:))) AA(1,:) = [] 8

Matrix Operations Basic manipulations Some useful functions: find, sum, min, max, diag, size, rows, columns see the handout for details (and try in octave to understand) Basic arithmetics +, -, and * denote matrix addition, subtraction, and multiplication. note that dimensions should match accordingly A' transposes and conjugates A Element-wise operations a. (dot) before an operation, makes it work element-wise try A = [1 2 ; 3 4], B = A^2, C = A.^2.*,./,.^ are element-wise multiplication, division, and power.+ and.- are the same as + and - A.' transposes A but does not conjugate 9

Plotting graphs plot(x1, Y1, LineSpec, X2, Y2, LineSpec,...) plots Y1 versus X1 and Y2 vs. X2 on the same plot, with the attributes specified in LineSpec (a string) Example: x = linspace(0,2*pi,100); y = sin(x); plot(x,y,'ro') Linespecs Colors: w, m, c, r, g, b, y, k Line markers:., o, x, +, *, s, d, v, ^, <, >, p, h Line format: -, :, -., -- LineSpecs of different types can be used together LineSpecs should always be in string form (between quotes) Other useful plotting commands figure, figure(#), axis, hold on/off, grid on/off, title, xlabel, ylabel, legend 10

Control if for if expression elseif expression else end for variable = vector end while while expression end switch switch x case x1 case x2 otherwise end Note: expression is a logical expression. Use the Comparison and Boolean Operators in the handout for making logical expressions. 11

Scripts To create make a text file containing the sequence of commands which lead to your desired result save the file with the extension.m (called M-files) To run just type the filename without extension on the command line and press return Exercise: This has the same effect as entering the same sequence of commands line by line into octave Write a script that calculates and plots on the same figure exactly two periods (0 to 4¼ ) of the following sine waves: 12

Functions To create: make a file containing the following: function [out1,out2,...] = function_name (in1, in2,...) function-body end Note: the end is optional (except for nested functions) To run: type the following at octave command line: octave:##> [o1,o2,...] = function_name[i1,i2,...] Exercise: Write a simple function that calculates the angle between two vectors in degrees. Note that for vectors v and u we have the following relationship between their dot product and the angle between them 13