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

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

1 Overview of the standard Matlab syntax

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

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

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

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

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

Introduction to MATLAB

MATLAB TUTORIAL WORKSHEET

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

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

EGR 111 Introduction to MATLAB

MATLAB Tutorial Matrices & Vectors MATRICES AND VECTORS

2.0 MATLAB Fundamentals

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

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

Chapter 1 Introduction to MATLAB

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

University of Alberta

An Introduction to MATLAB

Introduction to MATLAB

Introduction to MATLAB

Introduction to MatLab. Introduction to MatLab K. Craig 1

Introduction to Matlab for Econ 511b

Vector: A series of scalars contained in a column or row. Dimensions: How many rows and columns a vector or matrix has.

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

Introduction to MATLAB

Vectors and Matrices. Chapter 2. Linguaggio Programmazione Matlab-Simulink (2017/2018)

Armstrong State University Engineering Studies MATLAB Marina 2D Arrays and Matrices Primer

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

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

(Creating Arrays & Matrices) Applied Linear Algebra in Geoscience Using MATLAB

1 Introduction to MATLAB

1 Introduction to Matlab

MATLAB = MATrix LABoratory. Interactive system. Basic data element is an array that does not require dimensioning.

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

Computer Packet 1 Row Operations + Freemat

ENGR 1181 MATLAB 02: Array Creation

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

MATLAB: The Basics. Dmitry Adamskiy 9 November 2011

A Guide to Using Some Basic MATLAB Functions

Dr Richard Greenaway

1 Introduction to MATLAB

MATLAB. Devon Cormack and James Staley

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

EE 301 Signals & Systems I MATLAB Tutorial with Questions

AN INTRODUCTION TO MATLAB

Introduction to Matlab

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

Getting Started with MATLAB

Matlab- Command Window Operations, Scalars and Arrays

Grace days can not be used for this assignment

Laboratory 1 Octave Tutorial

Getting started with MATLAB

MATLAB Project: Getting Started with MATLAB

An Introduction to MATLAB II

QUICK INTRODUCTION TO MATLAB PART I

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

Introduction to MATLAB programming: Fundamentals

Introduction to MATLAB

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

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 Practical 1

MATLAB Project: Getting Started with MATLAB

MATLAB Tutorial III Variables, Files, Advanced Plotting

Matlab (Matrix laboratory) is an interactive software system for numerical computations and graphics.

Introduction to MATLAB

MATLAB GUIDE UMD PHYS401 SPRING 2012

Introduction to Matlab

CME 192: Introduction to Matlab

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

Introduction to Matlab

An Introductory Tutorial on Matlab

ECE Lesson Plan - Class 1 Fall, 2001

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

Introduction to Matlab

CITS2401 Computer Analysis & Visualisation

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

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

0_PreCNotes17 18.notebook May 16, Chapter 12

Identity Matrix: >> eye(3) ans = Matrix of Ones: >> ones(2,3) ans =

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

Introduction and MATLAB Basics

MATLAB Tutorial. Primary Author: Shoumik Chatterjee Secondary Author: Dr. Chuan Li

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

Introduction to Matlab

Objectives. 1 Running, and Interface Layout. 2 Toolboxes, Documentation and Tutorials. 3 Basic Calculations. PS 12a Laboratory 1 Spring 2014

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

AMS 27L LAB #2 Winter 2009

Lecture 2. Arrays. 1 Introduction

Matlab Tutorial: Basics

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

Matlab Tutorial and Exercises for COMP61021

Introduction to Matlab

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

Introduction to Matlab. By: Hossein Hamooni Fall 2014

Introduction to Matrix Operations in Matlab

MATLAB SUMMARY FOR MATH2070/2970

Matlab Tutorial for COMP24111 (includes exercise 1)

Desktop Command window

Transcription:

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

MATLAB Tutorial I What is a matrix? 1) A way of representation for data (# of rows: dimensionality, # of columns: the number of data). 5 # of data 4 y-axis 3 2 dim 1 0 5 4 3 2 1 0 1 2 3 4 5 x-axis 2) Linear transformation (e.g. scaling, rotation, projection, reflection etc.). 3 y-axis 2 1 0 0 1 2 3 x-axis 3) A system of linear equations. 2

Why MATLAB? MATLAB (matrix laboratory) is an interactive, matrix-based numerical computing system, which works with essentially only one kind of object, which is a matrix. Easy to learn. Many useful features ( toolboxes ). Standard: used all over by engineers and scientists, etc. Not good for large software projects. Proprietary. How to open it? Click the matlab icon generated after installation, or type "matlab" or "matlab -nodisplay" in a terminal window (especially for opening many matlab sessions). How to create a matrix?» A = [1 2 3; 4 5 6; 7 8 9]» A = [ 1 2 3 4 5 6 7 8 9] Scalars or vectors are a special case of matrix:» B = [1]» B = 1» B = [1 2 3]» B = [1;2;3] 3

How to reference an element, a row, or a column vector: A(1:2, : ) A(1, : ) A(2, 3) A( :, 1)» A(2,3)» A(1,:)» A(1:2,:)» A(:,3)» A(:) Matrix arithmetic: + addition: (A + B) i j = A i j + B i j subtraction: (A B) i j = A i j B i j multiplication: (A B) i j = A ik B k j k=1. element-by-element multiplication: (A. B) i j = A i j B i j / division: A/B = A B 1,A\B = A 1 B./ element-by-element division: (A./B) i j = A i j /B i j power: Aˆ2 = A A. element-by-element power: (A.ˆ2) i j = A i j A i j transpose: (A ) i j = A ji 4

Exercise for matrix arithmetic:» % try addition and subtraction between the 1st and 2nd columns of A.» A(:,1) + A(:,2)» A(:,1) A(:,2)» % try element-wise square and transpose of the 1st row of A.» A(1,:).ˆ2» A(1,:)» % try inner product of the 1st and 2nd columns of A.» A(:,1) A(:,2)» % try inner product of the 1st and 2nd rows of A.» A(1,:) A(2,:)» % try element-wise product of the 1st and 2nd columns of A.» A(:,1). A(:,2) Usage of colon and semicolon 1) Matrix row separator: When used within square brackets to create a new matrix or concatenate existing arrays, the semicolon creates a new row in the array. 2) If the last character of a statement is a semicolon, the printing is suppressed, but the assignment is carried out. This is essential in suppressing unwanted printing and intermediate results.» x = sin(a);» x = sin(a) 3) The colon notation can be used to access sub-matrices or sub-vectors of a matrix. 4) Range specifier: A colon allows ones to generate a series of numbers without the use of loops, which will be studied in the next class.» x = 1:10 5

» x = 10:-1:1» x = 0:0.5:3 What is M-files? MATLAB can execute a sequence of statements stored in a file. Such files are called M-files because they must have the file type of ".m" as the last part of their filename. Much of your work with MATLAB will be in creating and refining M-files. M-files are usually created using your local editor. There are two types of M-files: script files and function files. 1) Script files consist of a sequence of normal MATLAB statements. If the file has the filename, say, test.m, then the MATLAB command test will cause the statements in the file to be executed.» % write test.m with the following pseudo-code:» % type cmd+n to create a new file.» % make a column vector originating from (0,0) to (2,1), and assign it to x.» x = [2;1];» % make a scaling matrix (scale factor : 2), and assign it to A.» A = [2 0;0 2];» % scale up x twice, assign it to y, and print it out.» y = A x 2) Function files provide extensibility to MATLAB. You can create new functions specific to your problem which will then have the same status as other MATLAB functions. (This was not studied in the class.)» % write scaling.m that scales up a vector by an arbitrary amount β.» function [vscaled] = scaling(vinput, beta)» scalemat = [beta 0; 0 beta];» vscaled = scalemat * vinput; 6

3) Modify test.m by incorporating the scaling function. (This was not studied in the class.) How to make a 2D plot?» % "doc functionname" displays documentation for the functionality specified by name.» doc plot» % plot the input vector x and the scaled vector y» % set axis limit, marker(size, color) and show axis label, title, legend, etc.» % refer to the attached file test.m 7