An Introduction to MATLAB II

Similar documents
Getting started with MATLAB

Introduction to MATLAB

Introduzione a MatLab. Prof. Sebastiano Battiato

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

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

Introduction to MATLAB LAB 1

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

EE 301 Signals & Systems I MATLAB Tutorial with Questions

Lab of COMP 406 Introduction of Matlab (II) Graphics and Visualization

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

Introduction to 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.

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

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

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

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

DSP Laboratory (EELE 4110) Lab#1 Introduction to Matlab

INTRODUCTION TO MATLAB PLOTTING WITH MATLAB

Introduction to Matlab

1 Introduction to Matlab

Some elements for Matlab programming

Lecturer: Keyvan Dehmamy

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

Introduction to MATLAB

What is MATLAB? It is a high-level programming language. for numerical computations for symbolic computations for scientific visualizations

A Guide to Using Some Basic MATLAB Functions

EGR 111 Introduction to MATLAB

How to learn MATLAB? Some predefined variables

Stokes Modelling Workshop

Physics 326G Winter Class 2. In this class you will learn how to define and work with arrays or vectors.

A General Introduction to Matlab

A very brief Matlab introduction

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

MATLAB TUTORIAL WORKSHEET

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

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

Laboratory 1 Octave Tutorial

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

A Very Brief Introduction to Matlab

! The MATLAB language

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

A Brief Introduction to MATLAB

Introduction to MATLAB

Finding, Starting and Using Matlab

Chapter 2. MATLAB Fundamentals

LAB 1: Introduction to MATLAB Summer 2011

Lecture 2 Introduction to MATLAB. Dr.Tony Cahill

Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name:

Matlab notes Matlab is a matrix-based, high-performance language for technical computing It integrates computation, visualisation and programming usin

GUI Alternatives. Syntax. Description. MATLAB Function Reference plot. 2-D line plot

Matlab Lecture 1 - Introduction to MATLAB. Five Parts of Matlab. Entering Matrices (2) - Method 1:Direct entry. Entering Matrices (1) - Magic Square

Matlab Tutorial and Exercises for COMP61021

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

Introduction to MATLAB

Matlab 1: Get Started

University of Alberta

Quick introduction to Matlab. Edited by Michele Schiavinato

This module aims to introduce Precalculus high school students to the basic capabilities of Matlab by using functions. Matlab will be used in

EEE161 Applied Electromagnetics Laboratory 1

Basic Graphs. Dmitry Adamskiy 16 November 2011

Getting Started. Chapter 1. How to Get Matlab. 1.1 Before We Begin Matlab to Accompany Lay s Linear Algebra Text

Dr Richard Greenaway

Introduction to Matlab. Matlab Basics. Ondrej Lexa.

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

Introduction to MATLAB

2. Plotting in MATLAB

Logical Subscripting: This kind of subscripting can be done in one step by specifying the logical operation as the subscripting expression.

Getting Started with MATLAB

Introduction to MATLAB

Introduction to Matlab

MATLAB Tutorial Matrices & Vectors MATRICES AND VECTORS

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

AMS 27L LAB #2 Winter 2009

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

Appendix A. Introduction to MATLAB. A.1 What Is MATLAB?

Introduction to MATLAB Practical 1

Introduction to Matlab to Accompany Linear Algebra. Douglas Hundley Department of Mathematics and Statistics Whitman College

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

2.0 MATLAB Fundamentals

The value of f(t) at t = 0 is the first element of the vector and is obtained by

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

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

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

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

Matlab Tutorial for COMP24111 (includes exercise 1)

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

6.094 Introduction to MATLAB January (IAP) 2009

Lab #1 Revision to MATLAB

Desktop Command window

TUTORIAL 1 Introduction to Matrix Calculation using MATLAB TUTORIAL 1 INTRODUCTION TO MATRIX CALCULATION USING MATLAB

AN INTRODUCTION TO MATLAB

Mechanical Engineering Department Second Year (2015)

A Quick Tutorial on MATLAB. Zeeshan Ali

Getting To Know Matlab

Why use MATLAB? Mathematcal computations. Used a lot for problem solving. Statistical Analysis (e.g., mean, min) Visualisation (1D-3D)

Introduction to MatLab. Introduction to MatLab K. Craig 1

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

Introduction to Matlab

Octave Tutorial Machine Learning WS 12/13 Umer Khan Information Systems and Machine Learning Lab (ISMLL) University of Hildesheim, Germany

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.

Transcription:

Lab of COMP 319 An Introduction to MATLAB II Lab tutor : Gene Yu Zhao Mailbox: csyuzhao@comp.polyu.edu.hk or genexinvivian@gmail.com Lab 2: 16th Sep, 2013 1

Outline of Lab 2 Review of Lab 1 Matrix in Matlab MATLAB Graphics More Practices 2

Outline of Lab 2 Review of Lab 1 Matrix in Matlab MATLAB Graphics More Practices 3

Review of Lab 1 Compute the following quantities sin 2 ( π / 4) + cos 2 ( π / 4) iπ e +1 ( 1+ 3i) /(1 3i) x = 32π ; y = cos x 2 sin 2 x 4

Answers 5

Outline of Lab 2 Review of Lab 1 Matrix in Matlab MATLAB Graphics More Practices 6

MATLAB Matrices MATLAB treats all variables as matrices. For our purposes a matrix can be thought of as an array, in fact, that is how it is stored. Vectors are special forms of matrices and contain only one row OR one column. Scalars are matrices with only one row AND one column 7

MATLAB Matrices A matrix with only one row AND one column is a scalar. A scalar can be created in MATLAB as follows:» a_value=23 a_value = 23 8

MATLAB Matrices A matrix with only one row is called a row vector. A row vector can be created in MATLAB as follows (note the commas):» rowvec = [12, 14, 63] or rowvec = [12 14 63] rowvec = 12 14 63 9

MATLAB Matrices A matrix with only one column is called a column vector. A column vector can be created in MATLAB as follows (note the semicolons):» colvec = [13 ; 45 ; -2] colvec = 13 45-2 10

MATLAB Matrices A matrix can be created in MATLAB as follows (note the commas AND semicolons):» matrix = [1, 2, 3 ; 4, 5,6 ; 7, 8, 9] matrix = 1 2 3 4 5 6 7 8 9 11

Extracting a Sub-Matrix A portion of a matrix can be extracted and stored in a smaller matrix by specifying the names of both matrices, the rows and columns. The syntax is: sub_matrix = matrix ( r1 : r2, c1 : c2 ) ; where r1 and r2 specify the beginning and ending rows and c1 and c2 specify the beginning and ending columns to be extracted to make the new matrix. 12

MATLAB Matrices A column vector can be extracted from a matrix. As an example we create a matrix below:» matrix=[1,2,3;4,5,6;7,8,9] matrix = 1 2 3 4 5 6 7 8 9 Here we extract column 2 of the matrix and make a column vector:» col_two=matrix( :, 2) col_two = 2 5 8 13

MATLAB Matrices A row vector can be extracted from a matrix. As an example we create a matrix below:» matrix=[1,2,3;4,5,6;7,8,9] matrix = 1 2 3 4 5 6 7 8 9 Here we extract row 2 of the matrix and make a row vector. Note that the 2:2 specifies the second row and the 1:3 specifies which columns of the row.» rowvec=matrix(2 : 2, 1 : 3) rowvec = 4 5 6 14

Matrices transpose a vector x = [1 2 5 1] x = 1 2 5 1 transpose y = x y = 1 2 5 1 15

Scalar - Matrix Addition»a=3;» b=[1, 2, 3;4, 5, 6] b = 1 2 3 4 5 6» c= b+a % Add a to each element of b c = 4 5 6 7 8 9 16

Scalar - Matrix Subtraction»a=3;» b=[1, 2, 3;4, 5, 6] b = 1 2 3 4 5 6» c = b - a %Subtract a from each element of b c = -2-1 0 1 2 3 17

Scalar - Matrix Multiplication»a=3;» b=[1, 2, 3; 4, 5, 6] b = 1 2 3 4 5 6» c = a * b % Multiply each element of b by a c = 3 6 9 12 15 18 18

Scalar - Matrix Division»a=3;» b=[1, 2, 3; 4, 5, 6] b = 1 2 3 4 5 6» c = b / a % Divide each element of b by a c = 0.3333 0.6667 1.0000 1.3333 1.6667 2.0000 19

Other operators [ ] concatenation ( ) subscription x = [ zeros(1,3) ones(1,2) ] x = 0 0 0 1 1 x = [ 1 3 5 7 9] x = 1 3 5 7 9 y = x(2) y = 3 y = x(2:4) y = 3 5 7 20

Outline of Lab 2 Review of Lab 1 Matrix in Matlab MATLAB Graphics More Practices 21

Matlab Graphics t_vect=0:0.01:2*pi; X_vect=16*(sin(t_vect) ).^3; Y_vect=13*cos(t_vect)- 5*cos(2*t_vect)- 2*cos(3*t_vect)- cos(4*t_vect fill(x_vect,y_vect,'r' ); 22

Matlab Graphics x = 0:pi/100:2*pi; y = sin(x); plot(x,y) xlabel('x = 0:2\pi') ylabel('sine of x') title('plot of the Sine Function') 23

Multiple Graphs t = 0:pi/100:2*pi; y1=sin(t); y2=sin(t+pi/2); plot(t,y1,t,y2) grid on 24

Multiple Plots t = 0:pi/100:2*pi; y1=sin(t); y2=sin(t+pi/2); subplot(2,2,1) plot(t,y1) subplot(2,2,2) plot(t,y2) 25

Graph Functions (summary) plot linear plot stem discrete plot grid add grid lines xlabel add X-axis label ylabel add Y-axis label title add graph title subplot divide figure window figure create new figure window pause wait for user response 26

Some Useful MATLAB commands who List known variables whos List known variables plus their size help >> help sqrt Help on using sqrt lookfor >> lookfor sqrt Search for keyword sqrt in on MATLABPATH. what >> what ('directory') List MATLAB files in directory clear Clear all variables from work space clear x y Clear variables x and y from work space clc Clear the command window 27

Some Useful MATLAB commands dir List all files in current directory ls Same as dir type test Display the content of test.m in command window delete test Delete test.m cd a: Change directory to a: chdir a: Same as cd pwd Show current directory which test Display directory path to closest test.m 28

Outline of Lab 2 Review of Lab 1 Matrix in Matlab MATLAB Graphics More Practices 29

More Practices Please add variable A and B to Matlab workspace What s the transpose of A? What s the result of (A+B+10)/3? Concatenate A and B horizontally, then vertically. Subtract the 2nd row vector from A. Please clear A and B from Matlab workspace. 30

More Practices Make some simple plots: y = sin(x), x [0, 2π] Try to make it smoother by making the step smaller Add x-axis label This is x label and y-axis label This is y label Add a title This is the title Add a legend This is the legend 31

Answers of Practices A=[1 2 3 4; 4 3 2 1; 2 3 4 1; 3 2 4 1]; B=[1+4*j 2+3*j 3+2*j 4+j; 4+j 3+2*j 2+3*j 1+4*j; 2+3*j 3+2*j 4+j 1+4*j; 3+2*j 2+3*j 4+j 1+4*j]; A (A + B + 10)/3 [A, B] [A;B] A(2, :); clear 32

Answers of Practices Make some simple plots: x = 0:2*pi; y = sin(x); plot(x,y) This may look a little funny, so try to make it smoother by making the step smaller: x = 0:0.1: 2*pi; y = sin(x); plot(x,y) Add x-axis label This is x label and y-axis label This is y label : xlabel( This is the x label ) ; ylabel( This is the y label ); Add a title This is the title : title( This is the title ); Add a legend This is the legend : legend( This is the legend ); 33

What we have learned? 1. Basic matrices manipulation 2. Graphics in Matlab 34

Next lab course 1. More about matrices manipulation 2. Matlab file (.m) building 3. More exercises 35