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

Similar documents
An Introduction to MATLAB. Lab tutor : Dennis Yang LIU Lab 1: Sept. 11, 2014

2.0 MATLAB Fundamentals

Getting started with MATLAB

An Introduction to MATLAB II

An Introduction to MATLAB

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

Introduction to MATLAB

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

Introduction to MATLAB

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

Introduction to MATLAB

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

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

A Guide to Using Some Basic MATLAB Functions

Programming in Mathematics. Mili I. Shah

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

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

Chapter 1 Introduction to MATLAB

MATLAB. Miran H. S. Mohammed. Lecture 1

1 Introduction to Matlab

MATLAB NOTES. Matlab designed for numerical computing. Strongly oriented towards use of arrays, one and two dimensional.

Introduction to MATLAB

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

Dr Richard Greenaway

Matlab Programming Introduction 1 2

Course Layout. Go to follow instr. Accessible within campus (only for the first download)

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

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

Introduction to Engineering gii

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

MATLAB: The Basics. Dmitry Adamskiy 9 November 2011

Introduction to MatLab. Introduction to MatLab K. Craig 1

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB

Computer Project: Getting Started with MATLAB

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

CME 192: Introduction to Matlab

Lab 1 Intro to MATLAB and FreeMat

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB

MATLAB Project: Getting Started with MATLAB

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

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

PROGRAMMING WITH MATLAB DR. AHMET AKBULUT

Finding, Starting and Using Matlab

Introduction to MATLAB

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

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

MATLAB. Devon Cormack and James Staley

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.

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

Introduction to MATLAB LAB 1

LAB 1 General MATLAB Information 1

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

Matlab Programming MET 164 1/24

MATLAB Project: Getting Started with MATLAB

MATLAB BASICS. M Files. Objectives

MATLAB Lecture 1. Introduction to MATLAB

Introduction to MATLAB

Math 2250 MATLAB TUTORIAL Fall 2005

MATLAB GUIDE UMD PHYS401 SPRING 2012

EGR 102 Introduction to Engineering Modeling. Lab 05A Managing Data

Introduction to MATLAB

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

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

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

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

A General Introduction to Matlab

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

Introduction to MATLAB

Introduction to Matlab

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

Matlab Tutorial and Exercises for COMP61021

EGR 111 Introduction to MATLAB

A very brief Matlab introduction

Dr Richard Greenaway

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

SMS 3515: Scientific Computing Lecture 1: Introduction to Matlab 2014

Introduction to Matlab

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

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

Introduction to Matlab for Econ 511b

General Information. There are certain MATLAB features you should be aware of before you begin working with MATLAB.

Introduction to Matlab

MATLAB TUTORIAL WORKSHEET

Lab. Manual. Practical Special Topics (Matlab Programming) (EngE416) Prepared By Dr. Emad Saeid

1 Overview of the standard Matlab syntax

Teaching Manual Math 2131

Introduction to Scientific and Engineering Computing, BIL108E. Karaman

University of Alberta

Computer Programming in MATLAB

Introduction. Matlab for Psychologists. Overview. Coding v. button clicking. Hello, nice to meet you. Variables

Introduction to MATLAB

LAB 2: Linear Equations and Matrix Algebra. Preliminaries

A Brief Introduction to MATLAB

Matlab Tutorial for COMP24111 (includes exercise 1)

Introduction to Matlab

MATLAB COURSE FALL 2004 SESSION 1 GETTING STARTED. Christian Daude 1

ME305: Introduction to System Dynamics

A GUIDE FOR USING MATLAB IN COMPUTER SCIENCE AND COMPUTER ENGINEERING TABLE OF CONTENTS

Introduction to MATLAB Practical 1

MATLAB Tutorial Matrices & Vectors MATRICES AND VECTORS

Transcription:

Lab of COMP 406 MATLAB: Quick Start Lab tutor : Gene Yu Zhao Mailbox: csyuzhao@comp.polyu.edu.hk or genexinvivian@gmail.com Lab 1: 11th Sep, 2013 1

Where is Matlab? Find the Matlab under the folder 1. Y:\Win32\Matlab\R2012a 2. Double click it and open Matlab Or open Matlab on your computer 1. Click 'Start' 2. Click 'Run' 3. Input 'nalwin32' 4. Find the Matlab under the folder /Network Application Packages/Statistical & Mathematical/Matlab Send shortcut to your folder, for example: J:\starry If you have any problem, please contact the technical staffs in PQ608. They are very nice and helpful. 2

What is MATLAB? MATLAB MATrix LABoratory: MATLAB is a program for doing numerical computation. It was originally designed for solving linear algebra type problems using matrices. It s name is derived from MATrix LABoratory. MATLAB has since been expanded and now has built-in functions for solving problems requiring data analysis, signal processing, optimization, and several other types of scientific computations. It also contains functions for 2-D and 3-D graphics and animation. 3

How to get MATLAB Considering MATLAB at home Standard edition Available for roughly 2 thousand dollars Student edition Available for roughly 1 hundred dollars. Some limitations, such as the allowable size of a matrix 4

Matlab Desktop Launch Pad Current Directory Command Window Workspace History 5

Matlab Desktop - con t Command Window type commands Workspace view program variables clear to clear clear all: removes all variables, globals, functions and MEX links clc: clear command window double click on a variable to see it in the Array Editor Command History view past commands Launch Pad access help, tools, demos and documentation 6

Matlab Desktop - con t Launch Pad Workspace Current DIrectory Command Window History 7

How to Resume Default Desktop 8

Matlab Help Different ways to find information help help general, help mean, sqrt... helpdesk - an html document with links to further information 9

Command window The MATLAB environment is command oriented somewhat like UNIX. A prompt (>>) appears on the screen and a MATLAB statement can be entered. When the <ENTER> key is pressed, the statement is executed, and another prompt appears. If a statement is terminated with a semicolon ( ; ), no results will be displayed. Otherwise results will appear before the next prompt.»a=5;»b=a/2 b = 2.5000» 10

MATLAB Math Operators Power ^ or.^ a^b or a.^b Multiplication * (matrix multiply) or.* (array multiply) a*b or a.*b Division / or./ a/b or a./b or \ or.\ b\a or b.\a NOTE: 56/8 = 8\56 Addition + a + b Subtraction - a - b Assignment = a = b (assign b to a) cos () Cosine value of a specific angle sin() Sine value of a specific angle 11

Ex 1 As you work in MATLAB, you issue commands that create variables and call functions. For example, create a variable named a by typing this statement at the command line: a = 1 MATLAB adds variable a to the workspace and displays the result in the Command Window. Try more: b = 2 c = a + b d = cos(a) 12

Ex 1 con t When you do not specify an output variable, MATLAB uses the variable ans, short for answer, to store the results of your calculation. ans = 0.8415 sin(a) If you end a statement with a semicolon, MATLAB performs the computation, but suppresses the display of output in the Command Window. e = a*b; 13

Matrices and Arrays MATLAB is an abbreviation for matrix laboratory. While other programming languages mostly work with numbers one at a time, MATLAB is designed to operate primarily on whole matrices and arrays. All MATLAB variables are multidimensional arrays, no matter what type of data. A matrix is a two-dimensional array often used for linear algebra. 14

Creation To create an array with four elements in a single row, separate the elements with either a comma (,) or a space. a = [1 2 3 4] a = 1 2 3 4 This type of array is a row vector. To create a matrix that has multiple rows, separate the rows with semicolons. a = [1 2 3; 4 5 6; 7 8 10] 15

Creation Another way to create a matrix is to use a function, such as ones, zeros, or rand. For example, create a 5-by-1 column vector of zeros. z = zeros(5,1) z = 0 0 0 0 0 16

Matrix and Array Operations MATLAB allows you to process all of the values in a matrix using a single arithmetic operator or function. Practice more: a + 10 sin(a) To transpose a matrix, use a single quote ('): a' 17

Matrix and Array Operations You can perform standard matrix multiplication, which computes the inner products between rows and columns, using the * operator. For example, confirm that a matrix times its inverse returns the identity matrix: p = a*inv(a) 18

Matrix and Array Operations Notice that p is not a matrix of integer values. MATLAB stores numbers as floating-point values, and arithmetic operations are sensitive to small differences between the actual value and its floating-point representation. You can display more decimal digits using the format command: format long p = a*inv(a) 19

Matrix and Array Operations Reset the display to the shorter format using format short format affects only the display of numbers, not the way MATLAB computes or saves them. To perform element-wise multiplication rather than matrix multiplication, use the.* operator: p = a.*a 20

Matrix and Array Operations The matrix operators for multiplication, division, and power each have a corresponding array operator that operates element-wise. For example, raise each element of a to the third power: a.^3 21

Concatenation Concatenation is the process of joining arrays to make larger ones. In fact, you made your first array by concatenating its individual elements. The pair of square brackets [] is the concatenation operator. A = [a,a] 22

Concatenation Concatenating arrays next to one another using commas is called horizontal concatenation. Each array must have the same number of rows. Similarly, when the arrays have the same number of columns, you can concatenate vertically using semicolons. A = [a; a] 23

Workspace Variables The workspace contains variables that you create within or import into MATLAB from data files or other programs. For example, these statements create variables A and B in the workspace. A = magic(4); B = rand(3,5,2); You can view the contents of the workspace using whos. whos The variables also appear in the Workspace pane on the desktop. 24

Workspace Variables Workspace variables do not persist after you exit MATLAB. Save your data for later use with the save command, save myfile.mat Saving preserves the workspace in your current working folder in a compressed file with a.mat extension, called a MAT-file. To clear all the variables from the workspace, use the clear command. Restore data from a MAT-file into the workspace using load. load myfile.mat 25

What We have Learned? 1. Matlab Description and Desktop Basics 2. Matrices and Arrays 3. Workspace Variables 26

Next Lab Task 1. Array Indexing 2. Character Strings 3. Calling Functions 4. 2-D and 3-D Plots 5. Programming and Scripts 27