Vectors, matrices, and arithmetic

Slides:



Advertisements
Similar presentations
Introduction to MATLAB The language of Technical Computing.
Advertisements

Introduction to Matlab
Lecture 4.
Maths for Computer Graphics
CIS 101: Computer Programming and Problem Solving Lecture 2 Usman Roshan Department of Computer Science NJIT.
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
C ENTER FOR I NTEGRATED R ESEARCH C OMPUTING MATLAB
Intro to Matlab 1.Vectors, matrices, and arithmetic 2.Plotting 3.Flow Constructs 4.Other Useful Things Can be found at:
MatlABBA. The Colon Operator (1) This is one MatLab’s most important operators 1:10 means the vector – :-7:50 –
EPSII 59:006 Spring Topics Using TextPad If Statements Relational Operators Nested If Statements Else and Elseif Clauses Logical Functions For Loops.
MATLAB Fundamentals.
MATLAB and SimulinkLecture 11 To days Outline  Introduction  MATLAB Desktop  Basic Features  Branching Statements  Loops  Script file / Commando.
Chapter 5. Loops are common in most programming languages Plus side: Are very fast (in other languages) & easy to understand Negative side: Require a.
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
Martin Ellison University of Warwick and CEPR Bank of England, December 2005 Introduction to MATLAB.
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
1 Week 3: Vectors and Matrices (Part III) READING: 2.2 – 2.4 EECS Introduction to Computing for the Physical Sciences.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
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.
MATLAB An Introduction to MATLAB (Matrix Laboratory) 1.
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
Intro to Matlab 1.Using scalar variables 2.Vectors, matrices, and arithmetic 3.Plotting 4.Solving Systems of Equations Can be found at:
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
ME6104: CAD. Module 4. ME6104: CAD. Module 4. Systems Realization Laboratory Module 4 Matlab ME 6104 – Fundamentals of Computer-Aided Design.
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”
MATLAB – PT1 The purpose of this workshop is to get you started and to have fun with MATLAB! Let’s talk a little and decide on what we will be covering.
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 Part II 1Daniel Baur / Introduction to Matlab Part II Daniel Baur / Michael Sokolov ETH Zurich, Institut für Chemie- und Bioingenieurwissenschaften.
Introduction to Matlab Electromagnetic Theory LAB by Engr. Mian Shahzad Iqbal.
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
The MatLab Language Mathematics Laboratory The MathWorks
MATLAB Lecture 1 염익준. Introduction MATLAB (MATrix LABoratory) a special purpose computer program optimized to perform engineering and scientific calculations.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
Intro to Matlab Rogelio Long September 3, How to access MyDesktop Log in with your utep id and password.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Manipulating MATLAB Vector, Matrices 1. Variables and Arrays What are variables? You name the variables (as the programmer) and assign them numerical.
CS100A, Fall 1998, Lecture 191 CS100A, Fall 1998 Lecture 19, Thursday Nov 05 Matlab Concepts: Matlab arrays Matlab subscripting Matlab plotting.
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
An Introduction to Programming in Matlab Emily Blumenthal
To add, subtract, multiply, and divide, absolutely follow the mathematical rules. 1. All the rules 2. The element-per-element operator 3. Ex1: graphing.
전자장 1 실험 - Matlab 사용법 - Photonic Systems Laboratory School of EE, Seoul National University Photonic Systems Lab School of EECS, S.N.U.
LAB 2 Vectors and Matrices Dr.Abdel Fattah FARES.
Introduction to Matlab PHY September Why Matlab? No need to compile code Huge amount of built-in functions Highly optimized and fast, in general.
Tutorial on Matlab Basics
ECE 1304 Introduction to Electrical and Computer Engineering
Introduction to Matlab
Multiplying Matrices.
Linear Algebra review (optional)
Scripts & Functions Scripts and functions are contained in .m-files
Outline Matlab tutorial How to start and exit Matlab Matlab basics.
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
EEE 244 Numerical Methods In Electrical Engineering
Multiplying Matrices.
MATH 493 Introduction to MATLAB
Use of Mathematics using Technology (Maltlab)
Multiplying Matrices.
MATLAB Programming Basics Copyright © Software Carpentry 2011
Multiplying Matrices.
Announcements P3 due today
How to Use MATLAB A Brief Introduction.
Matlab Basics.
Multiplying Matrices.
Multiplying Matrices.
Multiplying Matrices.
Presentation transcript:

Vectors, matrices, and arithmetic Can be found at: http://www.cs.unc.edu/~kim/matlab.ppt Intro to Matlab Vectors, matrices, and arithmetic Plotting Flow Constructs Other Useful Things

Why use Matlab? Advantages: Handles vector and matrices very nice Quick plotting and analysis EXTENSIVE documentation (type ‘help’) Lots of nice functions: FFT, fuzzy logic, neural nets, numerical integration, OpenGL (!?) Drawbacks: Slow compared to C or Java

Vectors and Matrices Can be to command line or from *.m file scalar: x = 3 vector: x = [1 0 0] 2D matrix: x = [1 0 0; 0 1 0; 0 0 1] arbitrarily higher dimensions (don’t use much) Can also use matrices / vectors as elements: x = [1 2 3] y = [ x 4 5 6]

Common matrices to use ones(3,3) 3x3 of all ones zeros(3,3) 3x3 of all zeros eye(3,3) 3x3 identity (har har har) linspace(1,10,100) linear spacing from 1 to 10, with 100 spacings (also logspace) x = 1:10 linear spacing from 1 to 10, counting by 1

Element access MATLAB IS NOT ZERO INDEXED! x retrieves entire matrix x x(1,2) retrieves element at row 1, col 2 x(1, 5:10) retrieves row 1, columns 5 to 10 x(1,:) retrieves row 1, all columns Useful functions: length(x) length of vector x (cols) size(x) rows, cols of x

Matrix Math Matrix math Scalar math Scalar / matrix math Dimensions must agree Scalar math Same as usual Scalar / matrix math Scalar + matrix = [scalar + matrix(x, y)] Scalar * matrix = [scalar * matrix(x, y)]

More Matrix Math The ‘.’ operator Example: “element by element” access Example: x = [1 2 3]; y = [4; 5; 6]; x * y = 32 x .* y = [4 10 18] For some functions (x same as above): x ^ 2 ERROR! x . ^2 fine

Plotting 2D graphing Example: BUT: x = linspace(-10,10,100) y = x .^2 plot(x,y) Example: x = linspace(-10,10,100) y = x .^2 BUT: z = x .^3 plot(x,z)

More Plotting Old plot got stomped Multiple data sets: To open a new graph, type ‘figure’ Multiple data sets: Type ‘hold on’ to add new plot to current graph Type ‘hold off’ to resume stomping Make your graph beautiful: title(‘apples over oranges’) xtitle(‘apples’) ytitle(‘oranges’)

3D Plotting 3D plots – plot an outer product x = 1:10 y = 1:10 z = x’ * y mesh(x,y,z) Single quote ‘ means transpose (can’t cut and paste though…)

Flow Constructs IF block if (<condition>) <body> elseif end WHILE block while (<condition>) <body> end Conditions same as C, ( ==, >=, <=) except != is ~=

More Flow Constructs FOR block for i = 1:10 <body> end SWITCH statement switch <expression> case <condition>, <statement> otherwise <condition>, end

Other Language Features Matlab language is pretty sophisticated Functions Stored in a *.m file of the same name: function <return variable> = <function name>(<args>) <function body> Structs point.x = 2; point.y = 3; point.z = 4; Even has try and catch (never used them)

Useful Commands Single quote is transpose % same as // comment in C, Java No /* block comments */ (annoying) ; suppresses printing More: max(x) min(x) mean(x) median(x) abs(x) dot(x,y) cross(x,y) flops (flops in this session)

Useful Constants Inf infinity NaN Not and number (div by zero) eps machine epsilon ans most recent unassigned answer pi 3.14159…. i and j Matlab supports imaginary numbers!

Final note Wrong: Right: Matlab is optimized for vectorization for x = 1:10 for y = 1:10 foo(x,y) = 2 * bar(x,y) end Right: foo = 2 * bar; Matlab is optimized for vectorization

Questions?