Introduction to MATLAB. Recommended bibliography. Need more help? Session 1. Getting started.

Similar documents
MATLAB is a multi-paradigm numerical computing environment fourth-generation programming language. A proprietary programming language developed by

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

An Introduction to MATLAB

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

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

2.0 MATLAB Fundamentals

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

Introduction to Mathematical Programming

MATLAB BASICS. M Files. Objectives

System Design S.CS301

Matlab Primer. Lecture 02a Optical Sciences 330 Physical Optics II William J. Dallas January 12, 2005

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

Introduction to MATLAB programming: Fundamentals

Introduction to MATLAB

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

HERIOT-WATT UNIVERSITY DEPARTMENT OF COMPUTING AND ELECTRICAL ENGINEERING. B35SD2 Matlab tutorial 1 MATLAB BASICS

Introduction to MATLAB

MATLAB. Devon Cormack and James Staley

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

SECTION 1: INTRODUCTION. ENGR 112 Introduction to Engineering Computing

Introduction to MatLab. Introduction to MatLab K. Craig 1

MATLAB: The Basics. Dmitry Adamskiy 9 November 2011

Introduction to MATLAB

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

Chapter 1 Introduction to MATLAB

1 Overview of the standard Matlab syntax

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

1 Introduction to MATLAB

Introduction and MATLAB Basics

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

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

Introduction to MATLAB

CERTIFICATE IN WEB PROGRAMMING

1 Introduction to Matlab

Introduction to MATLAB Programming

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

Introduction to MATLAB

Dr Richard Greenaway

MATLAB. Miran H. S. Mohammed. Lecture 1

The Mathematics of Big Data

Introduction to MATLAB

ECE Lesson Plan - Class 1 Fall, 2001

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

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

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

Introduction to Matlab

Introduction to MATLAB

Pace University. Fundamental Concepts of CS121 1

C++ (Non for C Programmer) (BT307) 40 Hours

MATLAB Lecture 1. Introduction to MATLAB

Introduction to MATLAB

MatLab Just a beginning

MATLAB Introductory Course Computer Exercise Session

MATH 5520 Basics of MATLAB

Getting To Know Matlab

YOGYAKARTA STATE UNIVERSITY MATHEMATICS AND NATURAL SCIENCES FACULTY MATHEMATICS EDUCATION STUDY PROGRAM

1 Introduction to MATLAB

MATLAB SUMMARY FOR MATH2070/2970

MATLAB to iphone Made Easy

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

Introduction to Matlab. By: Hossein Hamooni Fall 2014

LAB 2: Linear Equations and Matrix Algebra. Preliminaries

Introduction to Matlab

Scheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax

Getting started with MATLAB

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

A Guide to Using Some Basic MATLAB Functions

EE 216 Experiment 1. MATLAB Structure and Use

CPE 112 Spring 2015 Exam III (100 pts) April 8, True or False (12 Points)

Visual Basic for Applications

MATLAB Introduction To Engineering for ECE Topics Covered: 1. Creating Script Files (.m files) 2. Using the Real Time Debugger

MATLAB GUIDE UMD PHYS401 SPRING 2012

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

Computational Methods of Scientific Programming

Matlab Advanced Programming. Matt Wyant University of Washington

Introduction to Programming Using Java (98-388)

MATLAB GUIDE UMD PHYS375 FALL 2010

MATLAB GUIDE UMD PHYS401 SPRING 2011

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

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

Introduction to R Programming

WHAT IS MATLAB?... 1 STARTING MATLAB & USING THE COMMAND LINE... 1 BASIC ARITHMETIC OPERATIONS... 5 ORDER OF OPERATIONS... 7

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

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan

MATLAB for Experimental Research. Fall 2018 Vectors, Matrices, Matrix Operations

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

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

An Introduction to MATLAB See Chapter 1 of Gilat

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

MAT 343 Laboratory 2 Solving systems in MATLAB and simple programming

Introduction to Matlab for Econ 511b

A General Introduction to Matlab

Short Version of Matlab Manual

What is MATLAB and howtostart it up?

Name SECTION: 12:45 2:20. True or False (12 Points)

MATLAB - Lecture # 4

MATH 3511 Basics of MATLAB

Introduction to MATLAB for Engineers, Third Edition

Computational Modelling 102 (Scientific Programming) Tutorials

Chapter 1: An Overview of MATLAB

Transcription:

Getting started Mihaela Duta mihaela.duta@maths.ox.ac.uk Recommended bibliography Matlab Guide D. Higham and N. Higham, Matlab primer A. Davis A Guide to MATLAB: For Beginners and Experienced Users, B. Hunt, R. Lipsman and J. Rosenberg Essential MATLAB for Scientists and Engineers B.Hahn Numerical Methods in Finance: A MATLAB-based Introduction, P. Brandimarte Need more help? mihaela.duta@maths.ox.ac.uk www.mathworks.com http://www.mathtools.net/matlab/index.html 1

Today s topics Programming basics MATLAB background Development environment Scripts and functions Data types Matrices Arithmetical operators Interfacing with the OS Programming language An artificial language used to control the behaviour of a computer, in order to manipulate information and express algorithms. Structure and meaning is determined with syntactic rules semantic rules respectively. Semantics/syntax Semantics reflects the meaning of programs Syntax: the set of allowed reserved words and possible order of instructions in a program 2

Algorithm A procedure defined as a finite set of well-defined instructions for accomplishing some task recipe Implemented as functions They often have iterations - repetitions of a process: loops conditionals - execution choices based on a given condition: conditional statements MATLAB background Very powerful tool for technical computing Integrates Computation Visualisation Programming Interactive and easy to use MATLAB short history Cleve Moler invented MATLAB in late 70s Very popular within the applied maths community Joined by Jack Little and Steve Bangart to rewrite MATLAB in C found Mathworks in 1984 3

Overview Application Program Interface (API) Development Environment Command window Editor/Debugger Browsers (help etc) Graphics The MATLAB system The MATLAB language Function library The development environment Collection of graphical windows Command line window Editor/Debugger Browsers for help, workspace, commands history, directory Apart from command line window, all the other are optional everything can be done in the command window The Workspace Accumulates variables handled in a session Can be manipulated from Workspace browser Command line 4

Scripts Collection of MATLAB statements Stored in a.m file They runs in the same memory area with the main MATLAB session: Use variables from the workspace Changes made to the workspace remain after script finishes Functions Collections of MATLAB statements Syntax for declaration function [output args] = fname(input args) Run in a separate memory space than the main MATLAB session: does not have access to the callers workspace changes made to variables are local variables passed via input/output arguments Code comments Any text starting following % Recommend document all code while implementing it Example: function umax = exmax(u1,u2) % function exmax(u1,u2) % analytic extension of real max function sw = real(u1) > real(u2); umax = sw.*u1 + (1-sw).*u2; 5

Data types Basic: Numerical stored floating-point double-precision ( double ) a format that occupies two storage locations in computer memory e.g. >> a = 3.14; format: controls the way numerical variables are echoed in the command window Logical >> a = true; Strings >> a = 'Some text' ; Advanced: Cell arrays >> a = {'Text', [1 2 3], [true false]}; Structures >> a.location = 'Oxford'; a.date = '12-Oct-05'; Objects No need to declare the variables MATRIX The fundamental two-dimensional data storage unit Created with matrix creator operator [ ] >> a = [1 2 3 4]; % one-dimensional array (vector, array) >> b = [1 2; 3 4]; % two-dimensional matrix Element separator: space, column separator: ; Access elements with numerical indices >> c = a(1); >> i = 2; d = a(i); Concatenate >> a = [1 2]; b= [3 4]; >> c = [a b]; Selectively display rows/columns >> a = [1 2; 3 4; 5 6]; >> b = a(2, :); Empty matrix >> c = []; Delete rows/columns >> a(2) = []; Arithmetical operators +, -, *, / >> a=[1 2]; b = [3 4]; c = a+b; their element-wise counterparts.*,./ >> a=[10 20;30 40]; b=[1 2; 3 4]; c = a./b; d = a/b; ^ (raise to the power of); also.^ >> a = [10 20; 30 40]; b = a.^2; c = a^2; ' (transpose) >> a = [1 2 3]; b = a'; \ (left division) A\B: If A is a square matrix, A\B is roughly the same as inv(a)*b, except it is computed in a different way. 6

( * vs.* ), (/ vs./ ), (^ vs.^ ) ( * vs.* ), (/ vs./ ) 10 20 1 2 70 100 * 30 40 3 4 = 150 220 matrix multiplication vs 10 20 1 2 10 40.* 30 40 = 3 4 90 160 element-wise (^ vs.^ ) 10 20 10 20 10 20 700 1000 ^ 2 * 30 40 = 30 40 = 30 40 1500 2200 matrix power vs 10 20 100 400. ^ 2 = 30 40 900 1600 element-wise Strings Arrays of alpha-numeric elements Elements accessed like array elements Can be concatenated Useful functions strcmp/strcmpi strfind/findstr sprintf/sscanf num2str/str2num Structures A data unit made up of containers called fields The fields can be any data type Compact way of storing data <struct_name>.<fieldx> Build a structure by assigning values to its fields: >> a.location = 'Oxford'; struct function:>> a = struct( location, Oxford ); rmfield/isfield Can be used to build matrices 7

Cell arrays A way of storing a miscellaneous collection of data in matrix form {} cell arrays constructor operator >> a = {'Text', [1 2 3], [true false]}; Indices for elements given in {} >> a = {2} can be concatenated sort/size apply if these operations make sense for the elements of the cell array Interface with the OS Run OS commands from MATLAB prompt with preceding them with the character! e.g. >>!dir Manipulate files and directories using MATLAB functions: path pwd cd copyfile/movefile/delete mkdir/rmdir 8