Tutorial 1SEG7550 Introduction to MATLAB 18 th, SEP. 2009.

Slides:



Advertisements
Similar presentations
Matlab Intro Simple introduction to some basic Matlab syntax. Declaration of a variable [ ] Matrices or vectors Some special (useful) syntax. Control statements.
Advertisements

Introduction to Matlab
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
Debugging in Matlab C. Reed 4/5/11. Bugs Debugging is a natural part of programming: Three standard types of errors: –Syntax errors: you simply have typed.
Flow Charts, Loop Structures
Lecture 5 Review Programming Program Structures Comparison Repetition: looping or iteration Conditional execution: branching Bubble Sort.
Introduction to Matlab By: Dr. Maher O. EL-Ghossain.
Lecture 4 Sept 8 Complete Chapter 3 exercises Chapter 4.
Week 6 - Programming I So far, we’ve looked at simple programming via “scripts” = programs of sequentially evaluated commands Today, extend features to:
General Computer Science for Engineers CISC 106 Lecture 08 Dr. John Cavazos Computer and Information Sciences 2/27/2009.
C ENTER FOR I NTEGRATED R ESEARCH C OMPUTING MATLAB
Lecture 4 Sept 7 Chapter 4. Chapter 4 – arrays, collections and indexing This chapter discusses the basic calculations involving rectangular collections.
EPSII 59:006 Spring Topics Using TextPad If Statements Relational Operators Nested If Statements Else and Elseif Clauses Logical Functions For Loops.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 21P. 1Winter Quarter MATLAB: Structures.
MATLAB and SimulinkLecture 11 To days Outline  Introduction  MATLAB Desktop  Basic Features  Branching Statements  Loops  Script file / Commando.
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.
Introduction to Matlab 1. Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators Plotting Flow Control Using of M-File Writing.
Introduction to MATLAB. Windows in MATLAB Command Window – where you enter data, run MATLAB code, and display results Command History - displays a log.
1 Week 3: Vectors and Matrices (Part III) READING: 2.2 – 2.4 EECS Introduction to Computing for the Physical Sciences.
Array Addition  Two arrays can be added if and only if both arrays have exactly the same dimensions.  Assuming the dimension requirement is satisfied,
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
Learner’s Guide to MATLAB® Chapter 2 : Working with Arrays.
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
Introduction to MATLAB Session 3 Simopekka Vänskä, THL Department of Mathematics and Statistics University of Helsinki 2011.
1 Lab 2 of COMP 319 Lab tutor : Shenghua ZHONG Lab 2: Sep. 28, 2011 Data and File in Matlab.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
CMPS 1371 Introduction to Computing for Engineers CONDITIONAL STATEMENTS.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
PHP Logic. Review: Variables Variables: a symbol or name that stands for a value – Data types ( Similar to C++ or Java): Int, Float, Boolean, String,
MAE 1202: AEROSPACE PRACTICUM An Introduction to MATLAB: Part 2 Mechanical and Aerospace Engineering Department Florida Institute of Technology Developed.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display.
Chapter 4 Controlling Execution CSE Objectives Evaluate logical expressions –Boolean –Relational Change the flow of execution –Diagrams (e.g.,
Exponents Tutorial 3f a number, letter, or algebraic expression written above and to the right of another number, letter, or expression called the base.
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
Introduction to Matlab Part II 1Daniel Baur / Introduction to Matlab Part II Daniel Baur / Michael Sokolov ETH Zurich, Institut für Chemie- und Bioingenieurwissenschaften.
Digital Image Processing Lecture 6: Introduction to M- function Programming.
Digital Image Processing Introduction to M-function Programming.
Introduction to Matlab
Structured Programming II: If Statements By the end of this class you should be able to: implement branching in a program describe and use an “if” statement.
General Computer Science for Engineers CISC 106 Lecture 13 - Midterm Review James Atlas Computer and Information Sciences 10/02/2009.
General Computer Science for Engineers CISC 106 Lecture 15 Dr. John Cavazos Computer and Information Sciences 03/16/2009.
CSE 455 : Computer Vision MATLAB 101 Getting Started with MATLAB.
A L I MAM M OHAMMAD B IN S AUD I SLAMIC U NIVERSITY C OLLEGE OF S CIENCES D EPARTMENT OF M ATHEMATICS MATLAB 251 : MATH SOFTWARE Introduction to MATLAB.
NoViC, Dept. of Mechanical Eng Acoustics Lab., NoViC 1. Download Matlab 2.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators.
Introduction to Matlab PHY September Why Matlab? No need to compile code Huge amount of built-in functions Highly optimized and fast, in general.
Properties and Applications of Matrices
Multiplying Matrices.
Introduction to Programming for Mechanical Engineers (ME 319)
L – Modeling and Simulating Social Systems with MATLAB
Chapter 4 MATLAB Programming
MATLAB DENC 2533 ECADD LAB 9.
Matlab Workshop 9/22/2018.
MATLAB: Structures and File I/O
Multiplying Matrices.
Use of Mathematics using Technology (Maltlab)
Introduction to MATLAB [Vectors and Matrices] Lab 2
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Multiplying Matrices.
Matlab Basics.
Multiplying Matrices.
Multiplying Matrices.
Multiplying Matrices.
Presentation transcript:

Tutorial 1SEG7550 Introduction to MATLAB 18 th, SEP. 2009

Announcement If you are from other departments other than SEEM, leave your student ID, name and department to me before you leave. A temporary account will be created for you.

Access MATLAB outside campus 1 Department VPN service currently is only available to SEEM/AECT Staff, gds and MSc only. 2 Idle timeout of 4 hours 3 First set up a vpn: Running X Applications (UNIX) remotely from MS Windows with VPN sl.se.cuhk.edu.hk/seem/index.php/Computer_Facilities:External_Acce ss_Route#Running_X_Applications_.28UNIX.29_remotely_from_MS_ Windows_with_VPN sl.se.cuhk.edu.hk/seem/index.php/Computer_Facilities:External_Acce ss_Route#Running_X_Applications_.28UNIX.29_remotely_from_MS_ Windows_with_VPN

Introduction to MATLAB Current version in lab: MATLAB (R2009b) Help: F1 In most cases, we will need to read function help.

Function help

Programs Usually long programs will be written in m file. (File->new->blank m-file) To run the program, press (save and run), or F5.

Initial a matrix Ones: Create array of all ones Syntax:Y = ones(n); Y = ones(m,n); Zeros: Create array of all zeros Syntax:Y = zeros(n); Y = zeros(m,n);

Vector Functions Addition: A = [1 2 3] B = [6 4 7] A + B = ?

Vector Functions In Matlab A = [1 2 3]; B = [6 4 7]; A + B ans =

Vector Functions Substraction A = [ ] B = [7 4 7] A -B = ?

Vector Functions In Matlab A = [ ]; B = [7 4 7]; A - B ans =

Vector Functions Multiplication In matrix calculation, there are two kinds of multiplication, element by element and matrix multiplication. Please note that the multiplication of vector must match their size. For example, the size of A and B are m x n and k x j vector respectively. Then m must be equal to k For element by element multiplication, two matrix must have same size.

Vector Functions A = [1 2 3] B = [2 2 3]' A * B' = ? and A' * B = ?

Vector Functions In Matlab A = [1 2 3]; B = [2 2 3]; A * B Error using ==> * Inner matrix dimensions must agree A * B' ans = 15 A' * B ans =

Vector Functions A = [1 2 3] B = [2 3 1] we want aij * bij, how?

Vector Functions In Matlab A = [1 2 3]; B = [2 3 1]; A.*B ans = 2 6 3

Vector Functions Division element by element (i.e. aij / bij): “./” A = [ ] B = [2 3 5] aij./ bij = ?

In Matlab A = [4 6 10]; B = [2 3 5]; A./B ans = 2 2 2

If if expression, statements, end If can be used with else, elseif to deal with complicated cases if expression1 statements1 elseif expression2 statements2 else statements3 end

An exercise Could you use Matlab to implement the following logic? Case OP_CP > 0 and OP_LO > 0 and CP_HI <= 0 : A = 1 Case OP_CP = 0 and OP_LO > 0 and CP_HI < 0 : A = 2 Case OP_CP = 0 and OP_LO = 0 and CP_HI < 0 : A =3 Otherwise, A=4

Answer Matlab Code: if op_cp > 0 & op_lo >= 0 & cp_hi <= 0 A = 1; elseif op_cp == 0 & op_lo > 0 & cp_hi < 0 A = 2; elseif op_cp = 0 & op_lo = 0 & cp_hi < 0 A = 3; else A = 4; end

FOR Repeat statements a specific number of times. for x=initval:endval, statements, end Example: Assign 1,2,3,4, to A(1), A(2), A(3), A(4), A(5),... A(10) use if.

A=zeros(10,1); for j=1:10, A(j) = j; end

while Repeatedly execute statements while condition is true. Syntax: while expression, statements, end Example Assign 1,2,3,4, to A(1), A(2), A(3), A(4), A(5),... A(10) use while.

A=zeros(10,1); j=1; while j<11 A(j) = j; j=j+1; end

Example: Manipulation of the specific row of matrix or vectors A = [ ] Subtract the 2nd row from 1st row of 3 x 3 matrix

In Matlab A = [ 1, 2, 3;6,1,4;7, 9, 2; ] A = for j=1:3, A(2,j) = A(2,j) - A(3,j); end A ans =