C ENTER FOR I NTEGRATED R ESEARCH C OMPUTING MATLAB

Slides:



Advertisements
Similar presentations
Matlab Intro Simple introduction to some basic Matlab syntax. Declaration of a variable [ ] Matrices or vectors Some special (useful) syntax. Control statements.
Advertisements

Introduction to MATLAB The language of Technical Computing.
Introduction to Matlab
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
M AT L AB Programming: scripts & functions. Scripts It is possible to achieve a lot simply by executing one command at a time on the command line (even.
Arrays  An array is a collection of like elements.  There are many engineering applications that use arrays.  MATLAB ® stores data in arrays and performs.
Maths for Computer Graphics
Introduction to MATLAB Michael Fink Login and press the Matlab icon Part 1: Using vectors and matrices Part 2: Performing.
Introduction to Matlab By: Dr. Maher O. EL-Ghossain.
Computer Science in Practice This course is an introduction to problems (and solutions) that arise in applied fields of computer science such as machine.
Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples.
MATLAB Cell Arrays Greg Reese, Ph.D Research Computing Support Group Academic Technology Services Miami University.
MATLAB FOR PATTERN RECOGNITION By: Özge Öztimur. How Much Do We Know? Anybody who has never used MATLAB?
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.
Intro to Matrices Don’t be scared….
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
MATLAB and SimulinkLecture 11 To days Outline  Introduction  MATLAB Desktop  Basic Features  Branching Statements  Loops  Script file / Commando.
MATLAB Basics With a brief review of linear algebra by Lanyi Xu modified by D.G.E. Robertson.
1 Week 12 Arrays, vectors, matrices and cubes. Introduction to Scientific & Engineering Computing 2 Array subscript expressions n Each subscript in an.
Matlab tutorial course Lesson 2: Arrays and data types
Introduction to Matlab 1. Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators Plotting Flow Control Using of M-File Writing.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
Introduction to MATLAB. Windows in MATLAB Command Window – where you enter data, run MATLAB code, and display results Command History - displays a log.
A First Book of ANSI C Fourth Edition
1 Week 3: Vectors and Matrices (Part III) READING: 2.2 – 2.4 EECS Introduction to Computing for the Physical Sciences.
Matlab Programming, part 1 M-files It is generally more convenient to program in Matlab using m-files, ascii text files containing a set of Matlab commands.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
MATLAB Tutorial EE 327 Signals and Systems 1. What is MATLAB? MATLAB – Matrix Laboratory The premier number-crunching software Extremely useful for signal.
Introduction to MATLAB Session 3 Simopekka Vänskä, THL Department of Mathematics and Statistics University of Helsinki 2011.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Recap Script M-file Editor/Debugger Window Cell Mode Chapter 3 “Built in MATLAB Function” Using Built-in Functions Using the HELP Feature Window HELP.
Advanced Topics- Functions Introduction to MATLAB 7 Engineering 161.
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display.
Introduction to Matlab Module #4 Page 1 Introduction to Matlab Module #4 – Programming Topics 1.Programming Basics (fprintf, standard input) 2.Relational.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
Chapter 4 Controlling Execution CSE Objectives Evaluate logical expressions –Boolean –Relational Change the flow of execution –Diagrams (e.g.,
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
Introduction to Matlab Part II 1Daniel Baur / Introduction to Matlab Part II Daniel Baur / Michael Sokolov ETH Zurich, Institut für Chemie- und Bioingenieurwissenschaften.
Digital Image Processing Lecture 6: Introduction to M- function Programming.
Introduction to Matlab
Matlab Basic. MATLAB Product Family 2 3 Entering & Quitting MATLAB To enter MATLAB double click on the MATLAB icon. To Leave MATLAB Simply type quit.
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
CSE 455 : Computer Vision MATLAB 101 Getting Started with MATLAB.
Intro to Matlab Rogelio Long September 3, How to access MyDesktop Log in with your utep id and password.
Intro to Matlab Yipei Wang & Qihui Li {yipeiw,
1 ENERGY 211 / CME 211 Lecture 4 September 29, 2008.
Arrays. Arrays are objects that help us organize large amounts of information.
1 Introduction to Matlab. 2 What is Matlab? Matlab is basically a high level language which has many specialized toolboxes for making things easier for.
Relational and Logical Operators EE 201 1C7-2 Spring 2012.
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators.
13.4 Product of Two Matrices
L – Modeling and Simulating Social Systems with MATLAB
Scripts & Functions Scripts and functions are contained in .m-files
Matlab Workshop 9/22/2018.
Introduction to MATLAB
StatLab Matlab Workshop
Matlab review Matlab is a numerical analysis system
MATH 493 Introduction to MATLAB
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
Introduction to MATLAB [Vectors and Matrices] Lab 2
CS 175 Project in AI Discussion -- matlab
Vectors, matrices, and arithmetic
INTRODUCTION TO MATLAB
Announcements P3 due today
Arrays in Matlab UC Berkeley Fall 2004, E Copyright 2005, Andy Packard
Programming The ideal style of programming is Structured or
Presentation transcript:

C ENTER FOR I NTEGRATED R ESEARCH C OMPUTING MATLAB

Outline Programming in Matlab Data Types Operators Arrays Plotting Control Structures  For loops  If statements Scripts Functions

Data Types Everything in matlab is at least a matrix of rank 2! help datatype Basic Datatypes  single, double, logical, int8, int16,..., uint8, uint16,..., char, complex Cells are arrays without a uniform type  a={1,[2,3,4],'hi'}  a{2} Structs have components referenced by name  card.suit='diamonds'  card.rank=8 There are routines for converting between struct arrays, cell arrays, and numeric arrays – cell2mat, struct2mat, num2cell

Arrays Arrays can be indexed using a single number  a=[1,2,3;4,5,6]  size(a)=[2,3]  a(row,column)  a(1,2)=2  a(2)=4 Matlab is column major order – (columns are contiguous in memory). The constructors are 'row major'  In memory 'a' looks like

Arrays Arrays can be constructed using  a=zeros(10,10) – or zeros(10)  a=rand(10,10) – or rand(10)  a=zeros(1,10) will give a 10 element 'vector'  a=[1,0,0;0,1,0;0,0,1] – 3x3 identity matrix  a=[1:100] – [1,2,3,4,5,6,7,8,9,...,100]  a=[0:.1:1] – [0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0]  a=cat(3,[1,3;2,4],[5,7;6,8]) – [concatenates 2D matrices along 3 rd dimension]  size(a)=[2,2,2]  size(size(a))=[1,3]

Operators +, -,./,.*,.^.^,.*,./ is element wise exponentiation, multiplication, and division. (^, *, and / are reserved for matrix exponentiation, multiplication, and division). For scalars (matrix of size 1x1) it doesn't matter..' is transpose ' is transposed conjugate, =, ==, ~= ~ is logical negation & is logical and | is logical or && and || are 'short-circuit' versions. Stops evaluations if possible

Control structures for i=1:2:10 sum=sum+i if (i==7) break end Adds the numbers 1,3,5,7

Control structures i=1 while i < 10 sum=sum+i if (i == 7) break end i=i+2 end

Control structures if (a==b) printf('%f == %f', a, b) elseif (a < b) printf('%f > %f', a, b) else %(a > b) printf('%f > %f', a, b) end

Control structures switch a case 1 sprintf('a==1') case 2 sprintf('a==2') otherwise sprintf('a ~= 1 and a ~= 2') end

Mandelbrot Set The mandelbrot set is the set of numbers 'c' for which the following sequence does not 'blow up' starting with z=0 Write a program to calculate whether a given number is in the mandelbrot set or not – and whether the sequence reaches 1e6 in 1000 iterations.  Determine whether the following numbers are in the 'mandelbrot set'  [-2, -1, i, 1/2, 1, 2]

Plotting You can plot vectors using  plot(x) You can make a scatter plot of two vectors using  plot(x,y) You can also an 'array of vectors' using  plot(A) Or you can plot a matrix using imagesc(A)

Functions and Scripts Matlab scripts do not take inputs or return outputs (except by writing to standard out – or a data file etc...) Usually a single script will call functions, which in turn will call other functions, etc... Both scripts and functions are stored in '.m' files Functions have their own 'workspaces' so variables in the parent function are not available to the called functions unless explicitly declared global or passed as a function argument. Functions are usually stored in files with the same name. For example, fact.m would contain function f = fact(n) f = prod(1:n);

Exercise 2 Modify your mandelbrot script to call a mandelbrot function which returns the number of iterations required to reach a magnitude of 1e6 – (or the maximum number of iterations if the sequence does not diverge) Re run your program and report the number of iterations required to diverge for the same set of numbers For each pair of x=[-1.99:.02:1.99] and y=[-1.99:.02:1.99] calculate the divergence rate for the complex number x+iy and store the result in a 200 x 200 matrix A and plot the result.