Introduction to MATLAB

Slides:



Advertisements
Similar presentations
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
Advertisements

MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/22/2003.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Digital Image Processing Lecture3: Introduction to MATLAB.
Nonparametric Econometrics1 Intro to Matlab for Data Analysis and Statistical Modeling.
Introduction to MATLAB Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU.
Introduction to M ATLAB EE 100 – EE Dept. - JUST.
CIS Computer Programming Logic
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
Lecture 4 MATLAB Windows Arithmetic Operators Maintenance Functions
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Input, Output, and Processing
Piotr Wolski Introduction to R. Topics What is R? Sample session How to install R? Minimum you have to know to work in R Data objects in R and how to.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
INTRODUCTION TO MATLAB MATLAB is a software package for computation in engineering, science, and applied mathemat-ics. It offers a powerful programming.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Introduction to Matlab Patrice Koehl Department of Biological Sciences National University of Singapore
Lecture 11 Introduction to R and Accessing USGS Data from Web Services Jeffery S. Horsburgh Hydroinformatics Fall 2013 This work was funded by National.
MATLAB The name of MATLAB stands for matrix laboratory. Starting a MATLAB Session -On Microsoft® Windows® platforms, start the MATLAB program by double-clicking.
Bash Scripting CIRC Summer School 2016 Baowei Liu CIRC Summer School 2016 Baowei Liu.
Fundamentals of Programming I Overview of Programming
Egyptian Language School Computer Department
Matlab.
Topics Designing a Program Input, Processing, and Output
CIRC Winter Boot Camp 2017 Baowei Liu
Release Numbers MATLAB is updated regularly
Introduction to Matlab
Matlab Training Session 4: Control, Flow and Functions
GC211Data Structure Lecture2 Sara Alhajjam.
Lecture: MATLAB Chapter 1 Introduction
MatLab Programming By Kishan Kathiriya.
Revision Lecture
2) Platform independent 3) Predefined functions
JavaScript: Functions.
PHP Introduction.
Outline Matlab tutorial How to start and exit Matlab Matlab basics.
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Matlab Workshop 9/22/2018.
Introduction to MATLAB
Introduction to MATLAB
Lecture 1: Introduction
StatLab Matlab Workshop
What Is a Program? A program is like an algorithm, but describes a process that is ready or can be made ready to run on a real computer Retrieved from:
Use of Mathematics using Technology (Maltlab)
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
Digital Image Processing
Communication and Coding Theory Lab(CS491)
Introduction to Matlab
INTRODUCTION TO MATLAB
Introduction to MATLAB
CSE 307 Basics of Image Processing
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Topics Designing a Program Input, Processing, and Output
Matlab Basic Dr. Imtiaz Hussain
Experiment No. (1) - an introduction to MATLAB
Topics Designing a Program Input, Processing, and Output
Simulation And Modeling
R Course 1st Lecture.
Introduction to Matlab
Matlab Basics.
Presentation transcript:

Introduction to MATLAB Session 1 Getting started Mihaela Duta mihaela.duta@maths.ox.ac.uk MSc in Mathematical and Computational Finance Introduction to MATLAB Session 1

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 MSc in Mathematical and Computational Finance Introduction to MATLAB Session 1

Need more help? mihaela.duta@maths.ox.ac.uk www.mathworks.com http://www.mathtools.net/MATLAB/index.html MSc in Mathematical and Computational Finance Introduction to MATLAB Session 1

Today’s topics Programming basics MATLAB background Development environment Scripts and functions Data types Matrices Arithmetical operators Interfacing with the OS MSc in Mathematical and Computational Finance Introduction to MATLAB Session 1

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. MSc in Mathematical and Computational Finance Introduction to MATLAB Session 1

Semantics/syntax Semantics reflects the meaning of programs Syntax: the set of allowed reserved words and possible order of instructions in a program MSc in Mathematical and Computational Finance Introduction to MATLAB Session 1

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 MSc in Mathematical and Computational Finance Introduction to MATLAB Session 1

MATLAB background Very powerful tool for technical computing Integrates Computation Visualisation Programming Interactive and easy to use MSc in Mathematical and Computational Finance Introduction to MATLAB Session 1

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 MSc in Mathematical and Computational Finance Introduction to MATLAB Session 1

Application Program Interface (API) Overview Development Environment Command window Editor/Debugger Browsers (help etc) Application Program Interface (API) The MATLAB system Graphics Talk through the slide The MATLAB language Function library MSc in Mathematical and Computational Finance Introduction to MATLAB Session 1

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 Let’s have a look now at what has MATLAB environment to offer. Open MATLAB Discuss initial desktop configuration Name and describe briefly each visible window Show how you can type commands Show how one can customize the desktop by adding/removing windows Open the browser and point out that the studentsare supposed to make full use of help when solving the exercises MSc in Mathematical and Computational Finance Introduction to MATLAB Session 1

The Workspace Accumulates variables handled in a session Can be manipulated from Workspace browser Command line MSc in Mathematical and Computational Finance Introduction to MATLAB Session 1

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 Give operators example. Show workspace contents before and after MSc in Mathematical and Computational Finance Introduction to MATLAB Session 1

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 Same example with operators MSc in Mathematical and Computational Finance Introduction to MATLAB Session 1

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; MSc in Mathematical and Computational Finance Introduction to MATLAB Session 1

Data types Basic: Numerical Logical Strings Advanced: Cell arrays 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 a = 1; whos a = ‘text’ whos MSc in Mathematical and Computational Finance Introduction to MATLAB Session 1

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) = []; Bring back the previous examples a = 1; whos Show formats MSc in Mathematical and Computational Finance Introduction to MATLAB Session 1

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. Give extensive examples MSc in Mathematical and Computational Finance Introduction to MATLAB Session 1

( * vs .* ) , (/ vs ./ ), (^ vs .^ ) ( * vs .* ) , (/ vs ./ ) vs matrix multiplication element-wise (^ vs .^ ) matrix power element-wise MSc in Mathematical and Computational Finance Introduction to MATLAB Session 1

Strings Arrays of alpha-numeric elements Elements accessed like array elements Can be concatenated Useful functions strcmp/strcmpi strfind/findstr sprintf/sscanf num2str/str2num MSc in Mathematical and Computational Finance Introduction to MATLAB Session 1

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 MSc in Mathematical and Computational Finance Introduction to MATLAB Session 1

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 MSc in Mathematical and Computational Finance Introduction to MATLAB Session 1

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 MSc in Mathematical and Computational Finance Introduction to MATLAB Session 1