MATLAB Part 1 Oct

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

Computing Seminar Introduction Oct

Math F302: Octave Miscellany September 28, e 1 x3 dx. Here s how to find a numerical approximation with Octave

ELEMENTARY MATLAB PROGRAMMING

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

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

Matlab Introduction. Scalar Variables and Arithmetic Operators

Getting started with Matlab: Outline

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

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

MATLAB Project: Getting Started with MATLAB

MATLAB Project: Getting Started with MATLAB

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

Math 2250 MATLAB TUTORIAL Fall 2005

Introduction to MATLAB

How to program with Matlab (PART 1/3)

Matlab Advanced Programming. Matt Wyant University of Washington

Interactive MATLAB use. Often, many steps are needed. Automated data processing is common in Earth science! only good if problem is simple

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

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

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.

Chapter 1 Introduction to MATLAB

MATLAB The first steps. Edited by Péter Vass

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

SECTION 1: INTRODUCTION. ENGR 112 Introduction to Engineering Computing

Scientific Computing: Lecture 1

An Introduction to MATLAB

MATLAB. Devon Cormack and James Staley

Computer Project: Getting Started with MATLAB

The Cantor Handbook. Alexander Rieder

CITS2401 Computer Analysis & Visualisation

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

What is MATLAB and howtostart it up?

Stokes Modelling Workshop

Outline. Numerical Analysis Basics. Some Higher-Level Languages. Programming Languages. BASIC and VBA MATLAB

EE 301 Signals & Systems I MATLAB Tutorial with Questions

ECE 3793 Matlab Project 1

Introduction to MATLAB

Introduction to Scientific Computing with Matlab

Introduction to MATLAB

Introduction to Matlab

MATLAB/Octave Tutorial

Physics 251 Laboratory Introduction to Spreadsheets

Introduction to Engineering gii

Dr Richard Greenaway

MATLAB Tutorial III Variables, Files, Advanced Plotting

A Guide to Using Some Basic MATLAB Functions

Variable Definition and Statement Suppression You can create your own variables, and assign them values using = >> a = a = 3.

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

Shell scripting and system variables. HORT Lecture 5 Instructor: Kranthi Varala

Computer Science 102. Into to Computational Modeling Special Topics: Programming in Matlab

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

ARRAY VARIABLES (ROW VECTORS)

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.

CSE/Math 485 Matlab Tutorial and Demo

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

SF1901 Probability Theory and Statistics: Autumn 2016 Lab 0 for TCOMK

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

MATLAB. Miran H. S. Mohammed. Lecture 1

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

Introduction in MATLAB (TSRT04)

Data needs to be prepped for loading into matlab.

CSE/Math 456 and CSE/Math 550 Matlab Tutorial and Demo

Introduction to Scientific Computing with Matlab

A Brief Introduction to MATLAB

1 Introduction. 2 Useful linear algebra (reprise) Introduction to MATLAB Reading. Spencer and Ware (2008), secs. 1-7, 9-9.3,

MATLAB BASICS. < Any system: Enter quit at Matlab prompt < PC/Windows: Close command window < To interrupt execution: Enter Ctrl-c.

AMS 27L LAB #1 Winter 2009

Introduction to Julia. HA Van Thao Faculty of Math & Computer Science, HCMUS

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

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

Matlab and Octave: Quick Introduction and Examples 1 Basics

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

Matlab- Command Window Operations, Scalars and Arrays

Matlab Tutorial, CDS

A Brief Introduction to MATLAB Evans Library Research Support Workshops

RELATIONAL AND LOGICAL OPERATORS

Day 15: Science Code in Python

Matlab Programming MET 164 1/24

NUMERICAL INTEGRATION AND FUNCTION FUNCTIONS

2 A little on Spreadsheets

An Introduction to Numerical Methods

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

Getting To Know Matlab

EPIB Four Lecture Overview of R

Chapter 1: An Overview of MATLAB

MATLAB Lesson I. Chiara Lelli. October 2, Politecnico di Milano

CS1110 Lab 1 (Jan 27-28, 2015)

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

SHELL SCRIPT BASIC. UNIX Programming 2014 Fall by Euiseong Seo

Microsoft Excel 2007 Lesson 7: Charts and Comments

Introduction to MATLAB

Dynamics and Vibrations Mupad tutorial

How to learn MATLAB? Some predefined variables

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

Class #15: Experiment Introduction to Matlab

Getting started with MATLAB

Introduction to Unix and Matlab

Finding, Starting and Using Matlab

University of Alberta

Transcription:

MATLAB Part 1 Oct 13 2010 1

Rough schedule First week, MATLAB as calculator : basics, MATLABspecific syntax, MATLAB command line (the MATLAB shell ) Second week, programming in MATLAB : more detail about arrays, functions, vectorized calculations, basic profiler Third week: more advanced plotting, debugger, profiler 2

What is MATLAB? MATrix LABoratory: www.mathworks.com MATLAB is an interpreted language This means you can write programs but you can also use it interactively to analyze and display data, simulations, etc. (In a sense, it is like a much more powerful Excel) The interactive nature makes it extremely useful for initial analysis of data or development of algorithms Creating a program requires a plan of what to do ahead of time; interactive use lets you develop on the fly. MATLAB is good at moving between these two regimes. 3

MATLAB strengths There are really no truly standard programming languages in atmospheric science, but MATLAB comes close On the fly type conversion & variable creation Lots of built-in functions & toolboxes to leverage Lots of built in graphics Many ways to solve numerical problems 4

MATLAB weaknesses The huge library of built in functions can be overwhelming there are probably too many different ways to do the same thing. Some functionality is split into toolboxes, which each can introduce their own peculiarities Cost each tool box is an added charge but, student license is reasonable, $100 from DoIT open source alternative (Octave) http://www.gnu.org/software/octave Octave is almost completely equivalent for most computations, but the graphics are somewhat different 5

Different ways to run MATLAB From Windows: run from start menu or desktop icon (if there is one) From UNIX shell: The GUI user> matlab & Lightweight options this will run it inside the terminal window (good if you are running remotely) user> matlab -nodesktop user> matlab -nojvm 6

The GUI (lots of stuff) 7

Editor, Figure Variable List, Command History, Command Window 8

Command Line Similar to a (graphing) calculators simple_example_script.m... 9

Basic Scripts Can easily collect basic commands into a script file (or sometimes called a batch script e.g., run a batch of commands) Go back & forth with mouse cursor context menu, cells in the script file Examples... 10

MATLAB syntax Some MATLAB specifics comment character % Relational operators: == ~= < > <= >= Operators: +.*./.^ (for arrays) * / ^ (for matrices, scalars more on this later) Arrays are indexed as A(n, m). First index is 1 LOTS of ways to create arrays (more on that later) End each line with ; (otherwise the result is echoed to the command line) Variable names are case sensitive (Search Naming Variables for more info) 11

MATLAB variable classes Standard things: Numeric types, Logical (True or False), Characters, Structures Arrays (note that all variables in MATLAB are really arrays scalars are actually 1 element arrays) Not so standard things: Empty array (zero elements) Cell arrays (more on these later) Function handles Use whos or class(x) to find a variable's type. 12

MATLAB numeric types Any numeric array created in MATLAB automatically defaults to double precision Helpful because you rarely need to worry about floating point roundoff error with double precision Not helpful because data is rarely stored as double precision large data arrays will use up twice as much memory Remember that you might need to round the data to get integers. In general, if x is some floating point variable, the expression: may or may not be equal to 1! 100 x 99 x x 13

The empty array Lots of ways to make one (but rarely do you want to). Example below. Some built-in functions return these, so mind them... >> not_empty_array = 1; empty_array = []; >> size(not_empty_array) 1 1 >> size(empty_array) 0 0 >> isempty(not_empty_array) 0 >> isempty(empty_array) 1 14

Function Handle Can create a variable that is a reference to a function Useful for certain built-in numeric computations (like quad: numeric integration on any function specified by the input function handle) Think of this as a representation of a mathematical function (rather than a function as a computer programming term.) Syntax: function_handle = @function_name; function_handle = @(x) f(x); 15

Function Handle Simple example cos(x), integrate from 0 pi/4. Analytic result is / 4 0 cos x dx= [sin x ] 0 / 4 = 1 2 >> foo = @(t) cos(t); >> quad(foo,0,pi/4) 0.7071 >> sqrt(1/2) 0.7071 16

Function Handle Simple example x 3, and then integrate from 0 1.5. 3 /2 Analytic result is 0 >> xcubed = @(x) x.^3; >> quad(xcubed, 0, 1.5) 1.2656 x 3 dx=[ 1 4 x4]0 3 /2= 1 4 3 2 4 = 81 64 >> 81/64 1.2656 >> quad(xcubed, 0, 1.5) - 81/64-2.2204e-16 17

Let's make something useful Blackbody curve (emittance) as a function of wavenumber: E,T =1.191 10 8 [W / m 2 cm 1 ] 3 exp 1.439[K cm] T 1 Create a MATLAB function handle use quad to integrate & compare to Stefan-Boltzmann E T =5.67 10 8 [W m 2 ]T 4 18

Let's make something useful E,T =1.191 10 8 [W / m 2 cm 1 ] 3 exp 1.439[K cm] T 1 bbemit = @(T,nu) 1.191e-8.*pi.*nu.^3./... (exp(1.439*nu./t)-1); E T =5.67 10 8 [W m 2 ]T 4 stefbolt = @(T) 5.67e-8 * T.^4; 19

Let's make something useful >> T = 255; >> stefbolt(t) 239.7418 >> quad(bbemit,1,8000)??? Input argument "nu" is undefined. Remember that bbemit requires 2 inputs T and nu. Need to create another function handle that sets the value of T: >> bbemit_t = @(nu) bbemit(t,nu); >> quad(bbemit_t, 1, 8000) 239.6003 20