LAB 2 VECTORS AND MATRICES

Size: px
Start display at page:

Download "LAB 2 VECTORS AND MATRICES"

Transcription

1 EN001-4: Intro to Computational Design Tufts University, Department of Computer Science Prof. Soha Hassoun LAB 2 VECTORS AND MATRICES 1.1 Background Overview of data types Programming languages distinguish different types of data; every piece of data is associated with a data type. MATLAB stores all numeric values as a double-precision floatingpoint number, or double for short. This default cannot be changed. MATLAB has other data types, such as logicals (which we will discuss later) and characters (char). Matrices in MATLAB store data. All elements of any matrix must have the same type. For example, you can create a matrix of doubles or a matrix oflogical True/False variables. MATLAB provides powerful built-in functions to perform arithmetic (e.g., * for matrix multiplication) and logical (e.g., greater than a particular value) operations on matrices. In this lab, we will work with matrices of double. The learning objectives of this lab are: Construct and examine data types Create vectors, access and modify elements within them, and perform vector-vector and scalar-vector operations Create matrices, access and modify elements within them, and perform matrix-matrix and scalar-matrix operations Explain column-major ordering for matrices Become familiar with many built-in matrix-based MATLAB functions including find, sum, isempty, etc You should read the Background sections first, and cut/paste the code into a MATLAB window to verify what it does and to play with it yourself. 1.2 Background: looking at data types All MATLAB variables belong to a class. Each class has different characteristics. When MATLAB encounters a new variable name, it creates the variable and allocates the proper storage for it according to its class. Each MATLAB variable is stored in an array. For example, performing the operation a = 8, allocates storage for an array of size 1x1, and labels that storage as a. By default, MATLAB stores all numeric variables as doubleprecision floating-point values. This means that MATLAB allocates 64-bits (8 bytes) of storage to hold this value. You can examine the data type of a variable using the whos command. 1

2 2 LAB 2VECTORS AND MATRICES EXAMPLE 1.1 Examining Data Types >> a = 8 a = 8 >>whos Name Size Bytes Class Attributes a 1x1 8 double 1.3 Background: creating vectors We can think of a vector as a 1-dimensional array (collection) with several elements. A row vector that holds n data points has the dimension 1 n. A vector can be defined using an assignment operator, and can be specified by explicitly listing each element or by using the colon operator to generate the vector iteratively with the proper step size (first:step:last). The size of the vector can be obtained using the keyword size, and two values are returned. The first refers to the 1 dimensional nature of the vector. The second refers to the number of elements in the vector. You can use the length command, which returns the largest dimension of the vector. Alternatively, you can use numel(v) to obtain the number of elements in the vector. To create a vector of all ones, or all zeros, MATLAB provides special functions called ones and zeros. An empty vector is created using the empty square brackets, [ ]. An element (or more) is deleted by assigning the particular vector element(s) to [ ]. EXAMPLE 1.2 Creating Vectors >> v=[ ] v = >> v2 = 20:10:50 v2 = >> size(v2) 1 4

3 BACKGROUND: ACCESSING AND MODIFYING ELEMENTS WITHIN A VECTOR 3 >> v = ones(1, 5) v = >> v = [] v = [] 1.4 Background: accessing and modifying elements within a vector Elements in a vector are numbered sequentially starting with element number 1. The n th element of vector v can be accessed using the parenthesis notation, v(n). A subset of the vector, from element i to element k inclusive, can be accessed using subscripted indexing via the range notation, v(i : k). Assignment to an individual element is performed using the assignment operator. Beware of out-of-range indexing. EXAMPLE 1.3 Accessing and Modifying Elements within a Vector >> v=[ ] v = >> v(2) = [] >> v(2:3) = [] 20 >> v = [v ] v =

4 4 LAB 2VECTORS AND MATRICES 1.5 Background: vector operations MATLAB provides scalar operations that perform the same operation on each individual element within a vector. For example, the code v = v*3 will multiply every element of a vector v by 3. MATLAB also provides element-by-element operations that apply one vector to another of matching size on term-by-term basis. For example, if v1 and v2 are two vectors of the same dimensions, then v1 + v2 results in a vector of the same dimension where each element is the sum of the appropriate terms in v1 and v2. The difference between scalar and element-by-element operations is obvious from the context if one operand is a simple number, then it s a scalar operation. For a small number of operations (most notably, multiplication or * ), MATLAB provides yet a third type of operation. MATLAB allows you to do matrix multiplication (which you probably learned about in high-school), where you multiply entire rows and columns to multiply two matrices. To distinguish between element-by-element multiplication and matrix multiplication, MATLAB uses.* for the former and * for the latter. Addition and subtraction do not need any extra operators, since all addition of two matrices is element by element. EXAMPLE 1.4 Scalar and Array Operators on Vectors >> v1=[2 4 6] v1 = >> v1* >> v2=[ ] v2 = >> v1.* v >> v1 + v2

5 BACKGROUND: CONSTRUCTING MATRICES Background: constructing matrices Creating a matrix is similar to creating a vector. Matrices are defined by entering the elements row by row separated by semicolons (;). You can also create a matrix of zeros or ones of any size using zeros or ones commands. A matrix of random numbers can be built by rand. size(a) returns the size of matrix A. EXAMPLE 1.5 Constructing Matrices >> m1=[1 2 3; 4 5 6] m1 = >> size(m1) 2 3 >> m2=zeros(4,2) m2 = >> m3=ones(3,5) m3 = >> m4=rand(2,2) m4 =

6 6 LAB 2VECTORS AND MATRICES Background: accessing and modifying elements within a matrix To reference a particular element of a matrix, specify its row and column number with the matrix name, A(row, column). When you index into the matrix A using only one subscript (e.g. A(5)), MATLAB treats A as if its elements were strung out in a long column vector, by going down the columns consecutively. You can select a submatrix of a given matrix by specifying the rows and columns to extract. You can use : to indicate all rows or columns of a matrix. EXAMPLE 1.6 Accessing and Modifying Elements within a Matrix >> m1=[1 2 3; 4 5 6]; >> m1(1,3) 3 >> m1(2,2) 5 >> m1(5) 3 >> m5=[ ; ; ; ]; >> m5([2 4], [2 3 4]) >> m5(2,:)

7 BACKGROUND: MATRIX OPERATIONS Background: matrix operations Matrices in MATLAB can be manipulated in many ways. For example, you can find the transpose of a matrix by apostrophe key ( ). Rows are changed to columns and columns are changed to rows. EXAMPLE 1.7 Matrix Transpose >> m There are 3 types of matrix multiplication in MATLAB: Scalar multiplication. A matrix is multiplied by a constant value. Matrix multiplication. C = A*B is the linear algebraic product of the matrices A and B where each element of C is C(i, j) = p k=1 A(i, k)b(k, j). Element-wise multiplication. This is a element by element multiplication (C = A.*B). EXAMPLE 1.8 Matrix Multiplication >> m6=[1 3 5; 2 4 7]; >> 3 * m >> m7=[ ; ; 4 0 8]; >> m6*m >> m8=[2 6 7; 1 4 2]; >> m6.*m8

8 8 LAB 2VECTORS AND MATRICES To test the equality of two matrices, you can use isqual(a, B) where A and B are the matrices. isequal returns 1 if the matrices are numerically equal. Otherwise, it returns 0. EXAMPLE 1.9 Matrix Equality >> m9=[1 2 3; 4 5 6]; >> m10=[1 2 3; 4 5 6]; >> m11=[6 7 8; ]; >> isequal(m9, m10) 1 >> isequal(m10, m11) Background: the find function and column-major ordering The find function locates elements within a matrix that meet particular criterion. The command, ind = find(a), locates all nonzero elements of A and and returns the linear indices of those elements in vector ind. The command, find(a>x), returns the indices for the elements of A that are greater than x. Here, it is important to realize that MATLAB indexes its elements in a notation called, column major. Column-major order refers to arranging multidimensional arrays in linear fashion such that consecutive elements of the columns are contiguous. For a 2 by 2 matrix, element A(1,1) will be the first element, and element A(2,1) is the second element, and element A(1,2) is the third element, and element A(2,2) is the fourth element. EXAMPLE 1.10 Using the find Function >> m=[0 2 0; 4 5 6] m = >> find (m)

9 BACKGROUND: GREAT FUNCTIONS TO KNOW! >> find (m>3) Background: great functions to know! sum(a): Returns a row vector of the sums of each column inv(a): Calculates the inverse of matrix A det(a): Returns the determinant of the square matrix A. isempty(a): Returns 1 if A is empty eye(n): Generates the n by n identity matrix diag(a): Returns the main diagonal of matrix A triu(a): Returns the upper triangular part of A tril(a): Returns the lower triangular part of A 1.11 Problems Consider the following two matrices: A = [ ; ; ; ; ] B = [ ; ; ; ; ] To code the answers to these problems, create one new script and call it L2.m. You might want to write and debug each section; and then comment it out while writing the following section. MATLAB can comment out an entire block of code using the %{ and %} operators. Do not forget to uncomment *ALL* sections before turning in the assignment. Your code should display the answers in the order specified by the problem set, simply by not putting a semicolon (;) after the appropriate calculation. Also, make sure you write your name at the top of the script.

10 10 LAB 2VECTORS AND MATRICES 1. Create a vector V with values 100, 300, 500, 3, and 10. Use this vector for each part of the problem below. (a) Add 2 to every element in V. (b) Divide every element in V by 3 (using the original V, not the result of part (a)). (c) Square every element in V. 2. Given matrix A from above, (a) extract the 3rd row. (b) extract the 5th column. (c) extract a submatrix composed of rows 1, 3, 5 and columns 2, 4. (d) find the sum of column 5. In each case, use the original matrix A for each sub-problem, rather than the result of the previous sub-problem. 3. Given matrices A and B from above, (a) calculate the inverse of matrix A (b) sum the elements in matrices A and B (c) perform matrix multiplication of A and B (d) perform element-wise multiplication of A and B. 4. Given matrices A and B from above, (a) use the sum command to sum all columns of matrix B (b) sum all rows of matrix B (c) sum all entries in matrix B 5. Use the find and sum commands to sum all entries in B greater than 5.

Lecture 2: Variables, Vectors and Matrices in MATLAB

Lecture 2: Variables, Vectors and Matrices in MATLAB Lecture 2: Variables, Vectors and Matrices in MATLAB Dr. Mohammed Hawa Electrical Engineering Department University of Jordan EE201: Computer Applications. See Textbook Chapter 1 and Chapter 2. Variables

More information

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

TUTORIAL 1 Introduction to Matrix Calculation using MATLAB TUTORIAL 1 INTRODUCTION TO MATRIX CALCULATION USING MATLAB INTRODUCTION TO MATRIX CALCULATION USING MATLAB Learning objectives Getting started with MATLAB and it s user interface Learn some of MATLAB s commands and syntaxes Get a simple introduction to use of

More information

MATLAB: The Basics. Dmitry Adamskiy 9 November 2011

MATLAB: The Basics. Dmitry Adamskiy 9 November 2011 MATLAB: The Basics Dmitry Adamskiy adamskiy@cs.rhul.ac.uk 9 November 2011 1 Starting Up MATLAB Windows users: Start up MATLAB by double clicking on the MATLAB icon. Unix/Linux users: Start up by typing

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab Andreas C. Kapourani (Credit: Steve Renals & Iain Murray) 9 January 08 Introduction MATLAB is a programming language that grew out of the need to process matrices. It is used extensively

More information

MATLAB COURSE FALL 2004 SESSION 1 GETTING STARTED. Christian Daude 1

MATLAB COURSE FALL 2004 SESSION 1 GETTING STARTED. Christian Daude 1 MATLAB COURSE FALL 2004 SESSION 1 GETTING STARTED Christian Daude 1 Introduction MATLAB is a software package designed to handle a broad range of mathematical needs one may encounter when doing scientific

More information

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB In this laboratory session we will learn how to 1. Create matrices and vectors. 2. Manipulate matrices and create matrices of special types

More information

AMATH 352: MATLAB Tutorial written by Peter Blossey Department of Applied Mathematics University of Washington Seattle, WA

AMATH 352: MATLAB Tutorial written by Peter Blossey Department of Applied Mathematics University of Washington Seattle, WA AMATH 352: MATLAB Tutorial written by Peter Blossey Department of Applied Mathematics University of Washington Seattle, WA MATLAB (short for MATrix LABoratory) is a very useful piece of software for numerical

More information

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

Armstrong State University Engineering Studies MATLAB Marina 2D Arrays and Matrices Primer Armstrong State University Engineering Studies MATLAB Marina 2D Arrays and Matrices Primer Prerequisites The 2D Arrays and Matrices Primer assumes knowledge of the MATLAB IDE, MATLAB help, arithmetic operations,

More information

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB MATLAB is a computer software commonly used in both education and industry to solve a wide range of problems. This Laboratory provides a brief

More information

A Quick Introduction to MATLAB/Octave. Kenny Marino, Nupur Chatterji

A Quick Introduction to MATLAB/Octave. Kenny Marino, Nupur Chatterji A Quick Introduction to MATLAB/Octave Kenny Marino, Nupur Chatterji Basics MATLAB (and it s free cousin Octave) is an interpreted language Two basic kinds of files Scripts Functions MATLAB is optimized

More information

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

OUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors. 1 LECTURE 3 OUTLINES Variable names in MATLAB Examples Matrices, Vectors and Scalar Scalar Vectors Entering a vector Colon operator ( : ) Mathematical operations on vectors examples 2 VARIABLE NAMES IN

More information

Introduction to MATLAB for Engineers, Third Edition

Introduction to MATLAB for Engineers, Third Edition PowerPoint to accompany Introduction to MATLAB for Engineers, Third Edition William J. Palm III Chapter 2 Numeric, Cell, and Structure Arrays Copyright 2010. The McGraw-Hill Companies, Inc. This work is

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB Introduction MATLAB is an interactive package for numerical analysis, matrix computation, control system design, and linear system analysis and design available on most CAEN platforms

More information

Matlab- Command Window Operations, Scalars and Arrays

Matlab- Command Window Operations, Scalars and Arrays 1 ME313 Homework #1 Matlab- Command Window Operations, Scalars and Arrays Last Updated August 17 2012. Assignment: Read and complete the suggested commands. After completing the exercise, copy the contents

More information

Dr Richard Greenaway

Dr Richard Greenaway SCHOOL OF PHYSICS, ASTRONOMY & MATHEMATICS 4PAM1008 MATLAB 3 Creating, Organising & Processing Data Dr Richard Greenaway 3 Creating, Organising & Processing Data In this Workshop the matrix type is introduced

More information

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

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial 1 Matlab Tutorial 2 Lecture Learning Objectives Each student should be able to: Describe the Matlab desktop Explain the basic use of Matlab variables Explain the basic use of Matlab scripts Explain the

More information

Introduction to MATLAB Programming

Introduction to MATLAB Programming Introduction to MATLAB Programming Arun A. Balakrishnan Asst. Professor Dept. of AE&I, RSET Overview 1 Overview 2 Introduction 3 Getting Started 4 Basics of Programming Overview 1 Overview 2 Introduction

More information

Vectors and Matrices. Chapter 2. Linguaggio Programmazione Matlab-Simulink (2017/2018)

Vectors and Matrices. Chapter 2. Linguaggio Programmazione Matlab-Simulink (2017/2018) Vectors and Matrices Chapter 2 Linguaggio Programmazione Matlab-Simulink (2017/2018) Matrices A matrix is used to store a set of values of the same type; every value is stored in an element MATLAB stands

More information

ECE Lesson Plan - Class 1 Fall, 2001

ECE Lesson Plan - Class 1 Fall, 2001 ECE 201 - Lesson Plan - Class 1 Fall, 2001 Software Development Philosophy Matrix-based numeric computation - MATrix LABoratory High-level programming language - Programming data type specification not

More information

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

MATLAB for Experimental Research. Fall 2018 Vectors, Matrices, Matrix Operations MATLAB for Experimental Research Fall 2018 Vectors, Matrices, Matrix Operations Matlab is more than a calculator! The array is a fundamental form that MATLAB uses to store and manipulate data. An array

More information

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

FreeMat Tutorial. 3x + 4y 2z = 5 2x 5y + z = 8 x x + 3y = -1 xx 1 of 9 FreeMat Tutorial FreeMat is a general purpose matrix calculator. It allows you to enter matrices and then perform operations on them in the same way you would write the operations on paper. This

More information

Matrices 4: use of MATLAB

Matrices 4: use of MATLAB Matrices 4: use of MATLAB Anthony Rossiter http://controleducation.group.shef.ac.uk/indexwebbook.html http://www.shef.ac.uk/acse Department of Automatic Control and Systems Engineering Introduction The

More information

MATLAB Lecture 1. Introduction to MATLAB

MATLAB Lecture 1. Introduction to MATLAB MATLAB Lecture 1. Introduction to MATLAB 1.1 The MATLAB environment MATLAB is a software program that allows you to compute interactively with matrices. If you want to know for instance the product of

More information

Matlab notes Matlab is a matrix-based, high-performance language for technical computing It integrates computation, visualisation and programming usin

Matlab notes Matlab is a matrix-based, high-performance language for technical computing It integrates computation, visualisation and programming usin Matlab notes Matlab is a matrix-based, high-performance language for technical computing It integrates computation, visualisation and programming using familiar mathematical notation The name Matlab stands

More information

Lecture 2. Arrays. 1 Introduction

Lecture 2. Arrays. 1 Introduction 1 Introduction Lecture 2 Arrays As the name Matlab is a contraction of matrix laboratory, you would be correct in assuming that Scilab/Matlab have a particular emphasis on matrices, or more generally,

More information

Arrays and Matrix Operations

Arrays and Matrix Operations 9 Arrays and Matrix Operations 1 THE PRIMARY MATLAB DATA STRUCTURE As we have previously stated, the basic data element in the MATLAB system is the array. A scalar is represented as a 1 * 1 array that

More information

Chapter 1 Introduction to MATLAB

Chapter 1 Introduction to MATLAB Chapter 1 Introduction to MATLAB 1.1 What is MATLAB? MATLAB = MATrix LABoratory, the language of technical computing, modeling and simulation, data analysis and processing, visualization and graphics,

More information

Identity Matrix: >> eye(3) ans = Matrix of Ones: >> ones(2,3) ans =

Identity Matrix: >> eye(3) ans = Matrix of Ones: >> ones(2,3) ans = Very Basic MATLAB Peter J. Olver January, 2009 Matrices: Type your matrix as follows: Use space or, to separate entries, and ; or return after each row. >> [;5 0-3 6;; - 5 ] or >> [,5,6,-9;5,0,-3,6;7,8,5,0;-,,5,]

More information

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix.

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix. MATLAB Tutorial 1 1 Department of Mathematics and Statistics, The University of New Mexico, Albuquerque, NM 87131 August 28, 2016 Contents: 1. Scalars, Vectors, Matrices... 1 2. Built-in variables, functions,

More information

Computational Mathematics

Computational Mathematics Computational Mathematics Hilary Term Lecture 1: Programming Andrew Thompson Outline for Today: Schedule this term Review Introduction to programming Examples Arrays: the foundation of MATLAB Basics MATLAB

More information

MATH (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab

MATH (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab MATH 495.3 (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab Below is a screen similar to what you should see when you open Matlab. The command window is the large box to the right containing the

More information

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

Introduction to Matlab. By: Dr. Maher O. EL-Ghossain Introduction to Matlab By: Dr. Maher O. EL-Ghossain Outline: q What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display Facilities Flow Control

More information

Using the fprintf command to save output to a file.

Using the fprintf command to save output to a file. Using the fprintf command to save output to a file. In addition to displaying output in the Command Window, the fprintf command can be used for writing the output to a file when it is necessary to save

More information

An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type.

An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type. Data Structures Introduction An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type. Representation of a large number of homogeneous

More information

(Creating Arrays & Matrices) Applied Linear Algebra in Geoscience Using MATLAB

(Creating Arrays & Matrices) Applied Linear Algebra in Geoscience Using MATLAB Applied Linear Algebra in Geoscience Using MATLAB (Creating Arrays & Matrices) Contents Getting Started Creating Arrays Mathematical Operations with Arrays Using Script Files and Managing Data Two-Dimensional

More information

Dr. Iyad Jafar. Adapted from the publisher slides

Dr. Iyad Jafar. Adapted from the publisher slides Computer Applications Lab Lab 2 Arrays in Matlab Chapter 2 Sections 1,2,6,7 Dr. Iyad Jafar Adapted from the publisher slides Outline Introduction Arrays in Matlab Vectors and arrays Creation Addressing

More information

Physics 326G Winter Class 2. In this class you will learn how to define and work with arrays or vectors.

Physics 326G Winter Class 2. In this class you will learn how to define and work with arrays or vectors. Physics 326G Winter 2008 Class 2 In this class you will learn how to define and work with arrays or vectors. Matlab is designed to work with arrays. An array is a list of numbers (or other things) arranged

More information

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

Lab of COMP 406. MATLAB: Quick Start. Lab tutor : Gene Yu Zhao Mailbox: or Lab 1: 11th Sep, 2013 Lab of COMP 406 MATLAB: Quick Start Lab tutor : Gene Yu Zhao Mailbox: csyuzhao@comp.polyu.edu.hk or genexinvivian@gmail.com Lab 1: 11th Sep, 2013 1 Where is Matlab? Find the Matlab under the folder 1.

More information

1 Overview of the standard Matlab syntax

1 Overview of the standard Matlab syntax 1 Overview of the standard Matlab syntax Matlab is based on computations with matrices. All variables are matrices. Matrices are indexed from 1 (and NOT from 0 as in C!). Avoid using variable names i and

More information

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB MATLAB sessions: Laboratory MAT 75 Laboratory Matrix Computations and Programming in MATLAB In this laboratory session we will learn how to. Create and manipulate matrices and vectors.. Write simple programs

More information

Introduction to MATLAB

Introduction to MATLAB Computational Photonics, Seminar 0 on Introduction into MATLAB, 3.04.08 Page Introduction to MATLAB Operations on scalar variables >> 6 6 Pay attention to the output in the command window >> b = b = >>

More information

An Introduction to MATLAB Programming

An Introduction to MATLAB Programming An Introduction to MATLAB Programming Center for Interdisciplinary Research and Consulting Department of Mathematics and Statistics University of Maryland, Baltimore County www.umbc.edu/circ Winter 2008

More information

Matrices. A Matrix (This one has 2 Rows and 3 Columns) To add two matrices: add the numbers in the matching positions:

Matrices. A Matrix (This one has 2 Rows and 3 Columns) To add two matrices: add the numbers in the matching positions: Matrices A Matrix is an array of numbers: We talk about one matrix, or several matrices. There are many things we can do with them... Adding A Matrix (This one has 2 Rows and 3 Columns) To add two matrices:

More information

MATLAB Tutorial Matrices & Vectors MATRICES AND VECTORS

MATLAB Tutorial Matrices & Vectors MATRICES AND VECTORS MATRICES AND VECTORS A matrix (m x n) with m rows and n columns, a column vector (m x 1) with m rows and 1 column, and a row vector (1 x m) with 1 row and m columns all can be used in MATLAB. Matrices

More information

Introduction to MATLAB

Introduction to MATLAB Chapter 1 Introduction to MATLAB 1.1 Software Philosophy Matrix-based numeric computation MATrix LABoratory built-in support for standard matrix and vector operations High-level programming language Programming

More information

Computational Photonics, Seminar 01 on Introduction into MATLAB, Page 1

Computational Photonics, Seminar 01 on Introduction into MATLAB, Page 1 Computational Photonics, Seminar 0 on Introduction into MATLAB,.04.06 Page Introduction to MATLAB Operations on scalar variables >> a=6 6 Pay attention to the response from the workspace >> b= b = >> a+b

More information

0_PreCNotes17 18.notebook May 16, Chapter 12

0_PreCNotes17 18.notebook May 16, Chapter 12 Chapter 12 Notes BASIC MATRIX OPERATIONS Matrix (plural: Matrices) an n x m array of elements element a ij Example 1 a 21 = a 13 = Multiply Matrix by a Scalar Distribute scalar to all elements Addition

More information

Computer Packet 1 Row Operations + Freemat

Computer Packet 1 Row Operations + Freemat Computer Packet 1 Row Operations + Freemat For this packet, you will use a website to do row operations, and then learn to use a general purpose matrix calculator called FreeMat. To reach the row operations

More information

MAT 343 Laboratory 2 Solving systems in MATLAB and simple programming

MAT 343 Laboratory 2 Solving systems in MATLAB and simple programming MAT 343 Laboratory 2 Solving systems in MATLAB and simple programming In this laboratory session we will learn how to 1. Solve linear systems with MATLAB 2. Create M-files with simple MATLAB codes Backslash

More information

Introduction to MatLab. Introduction to MatLab K. Craig 1

Introduction to MatLab. Introduction to MatLab K. Craig 1 Introduction to MatLab Introduction to MatLab K. Craig 1 MatLab Introduction MatLab and the MatLab Environment Numerical Calculations Basic Plotting and Graphics Matrix Computations and Solving Equations

More information

Introduction to MATLAB

Introduction to MATLAB to MATLAB Spring 2019 to MATLAB Spring 2019 1 / 39 The Basics What is MATLAB? MATLAB Short for Matrix Laboratory matrix data structures are at the heart of programming in MATLAB We will consider arrays

More information

Introduction to MATLAB

Introduction to MATLAB CHEE MATLAB Tutorial Introduction to MATLAB Introduction In this tutorial, you will learn how to enter matrices and perform some matrix operations using MATLAB. MATLAB is an interactive program for numerical

More information

Introduction to MATLAB. CS534 Fall 2016

Introduction to MATLAB. CS534 Fall 2016 Introduction to MATLAB CS534 Fall 2016 What you'll be learning today MATLAB basics (debugging, IDE) Operators Matrix indexing Image I/O Image display, plotting A lot of demos... Matrices What is a matrix?

More information

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

MATLAB for beginners. KiJung Yoon, 1. 1 Center for Learning and Memory, University of Texas at Austin, Austin, TX 78712, USA MATLAB for beginners KiJung Yoon, 1 1 Center for Learning and Memory, University of Texas at Austin, Austin, TX 78712, USA 1 MATLAB Tutorial I What is a matrix? 1) A way of representation for data (# of

More information

Mathematics 4330/5344 #1 Matlab and Numerical Approximation

Mathematics 4330/5344 #1 Matlab and Numerical Approximation David S. Gilliam Department of Mathematics Texas Tech University Lubbock, TX 79409 806 742-2566 gilliam@texas.math.ttu.edu http://texas.math.ttu.edu/~gilliam Mathematics 4330/5344 #1 Matlab and Numerical

More information

Matlab Introduction. Scalar Variables and Arithmetic Operators

Matlab Introduction. Scalar Variables and Arithmetic Operators Matlab Introduction Matlab is both a powerful computational environment and a programming language that easily handles matrix and complex arithmetic. It is a large software package that has many advanced

More information

Introduction to Matlab. By: Hossein Hamooni Fall 2014

Introduction to Matlab. By: Hossein Hamooni Fall 2014 Introduction to Matlab By: Hossein Hamooni Fall 2014 Why Matlab? Data analytics task Large data processing Multi-platform, Multi Format data importing Graphing Modeling Lots of built-in functions for rapid

More information

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB MAT 75 Laboratory Matrix Computations and Programming in MATLAB In this laboratory session we will learn how to. Create and manipulate matrices and vectors.. Write simple programs in MATLAB NOTE: For your

More information

How to Use MATLAB. What is MATLAB. Getting Started. Online Help. General Purpose Commands

How to Use MATLAB. What is MATLAB. Getting Started. Online Help. General Purpose Commands How to Use MATLAB What is MATLAB MATLAB is an interactive package for numerical analysis, matrix computation, control system design and linear system analysis and design. On the server bass, MATLAB version

More information

Matrix Inverse 2 ( 2) 1 = 2 1 2

Matrix Inverse 2 ( 2) 1 = 2 1 2 Name: Matrix Inverse For Scalars, we have what is called a multiplicative identity. This means that if we have a scalar number, call it r, then r multiplied by the multiplicative identity equals r. Without

More information

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

Experiment 1: Introduction to MATLAB I. Introduction. 1.1 Objectives and Expectations: 1.2 What is MATLAB? Experiment 1: Introduction to MATLAB I Introduction MATLAB, which stands for Matrix Laboratory, is a very powerful program for performing numerical and symbolic calculations, and is widely used in science

More information

Introduction to MATLAB 7 for Engineers

Introduction to MATLAB 7 for Engineers PowerPoint to accompany Introduction to MATLAB 7 for Engineers William J. Palm III Chapter 2 Numeric, Cell, and Structure Arrays Copyright 2005. The McGraw-Hill Companies, Inc. Permission required for

More information

Vector: A series of scalars contained in a column or row. Dimensions: How many rows and columns a vector or matrix has.

Vector: A series of scalars contained in a column or row. Dimensions: How many rows and columns a vector or matrix has. ASSIGNMENT 0 Introduction to Linear Algebra (Basics of vectors and matrices) Due 3:30 PM, Tuesday, October 10 th. Assignments should be submitted via e-mail to: matlabfun.ucsd@gmail.com You can also submit

More information

Matrix Multiplication

Matrix Multiplication Matrix Multiplication CPS343 Parallel and High Performance Computing Spring 2013 CPS343 (Parallel and HPC) Matrix Multiplication Spring 2013 1 / 32 Outline 1 Matrix operations Importance Dense and sparse

More information

EN 001-4: Introduction to Computational Design. Matrices & vectors. Why do we care about vectors? What is a matrix and a vector?

EN 001-4: Introduction to Computational Design. Matrices & vectors. Why do we care about vectors? What is a matrix and a vector? EN 001-: Introduction to Computational Design Fall 2017 Tufts University Instructor: Soha Hassoun soha@cs.tufts.edu Matrices & vectors Matlab is short for MATrix LABoratory. In Matlab, pretty much everything

More information

ENGR 1181 MATLAB 02: Array Creation

ENGR 1181 MATLAB 02: Array Creation ENGR 1181 MATLAB 02: Array Creation Learning Objectives: Students will read Chapter 2.1 2.4 of the MATLAB book before coming to class. This preparation material is provided to supplement this reading.

More information

Addition/Subtraction flops. ... k k + 1, n (n k)(n k) (n k)(n + 1 k) n 1 n, n (1)(1) (1)(2)

Addition/Subtraction flops. ... k k + 1, n (n k)(n k) (n k)(n + 1 k) n 1 n, n (1)(1) (1)(2) 1 CHAPTER 10 101 The flop counts for LU decomposition can be determined in a similar fashion as was done for Gauss elimination The major difference is that the elimination is only implemented for the left-hand

More information

function [s p] = sumprod (f, g)

function [s p] = sumprod (f, g) Outline of the Lecture Introduction to M-function programming Matlab Programming Example Relational operators Logical Operators Matlab Flow control structures Introduction to M-function programming M-files:

More information

One-dimensional Array

One-dimensional Array One-dimensional Array ELEC 206 Prof. Siripong Potisuk 1 Defining 1-D Array Also known as a vector A list of numbers arranged in a row row vector or a column column vector A scalar variable is a one-element

More information

ME305: Introduction to System Dynamics

ME305: Introduction to System Dynamics ME305: Introduction to System Dynamics Using MATLAB MATLAB stands for MATrix LABoratory and is a powerful tool for general scientific and engineering computations. Combining with user-friendly graphics

More information

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB MATLAB sessions: Laboratory MAT 75 Laboratory Matrix Computations and Programming in MATLAB In this laboratory session we will learn how to. Create and manipulate matrices and vectors.. Write simple programs

More information

Module 6: Array in C

Module 6: Array in C 1 Table of Content 1. Introduction 2. Basics of array 3. Types of Array 4. Declaring Arrays 5. Initializing an array 6. Processing an array 7. Summary Learning objectives 1. To understand the concept of

More information

Introduction and MATLAB Basics

Introduction and MATLAB Basics Introduction and MATLAB Basics Lecture Computer Room MATLAB MATLAB: Matrix Laboratory, designed for matrix manipulation Pro: Con: Syntax similar to C/C++/Java Automated memory management Dynamic data types

More information

Basics. Bilkent University. CS554 Computer Vision Pinar Duygulu

Basics. Bilkent University. CS554 Computer Vision Pinar Duygulu 1 Basics CS 554 Computer Vision Pinar Duygulu Bilkent University 2 Outline Image Representation Review some basics of linear algebra and geometrical transformations Slides adapted from Octavia Camps, Penn

More information

MATLAB GUIDE UMD PHYS401 SPRING 2012

MATLAB GUIDE UMD PHYS401 SPRING 2012 MATLAB GUIDE UMD PHYS40 SPRING 202 We will be using Matlab (or, equivalently, the free clone GNU/Octave) this semester to perform calculations involving matrices and vectors. This guide gives a brief introduction

More information

Lecture 5: Matrices. Dheeraj Kumar Singh 07CS1004 Teacher: Prof. Niloy Ganguly Department of Computer Science and Engineering IIT Kharagpur

Lecture 5: Matrices. Dheeraj Kumar Singh 07CS1004 Teacher: Prof. Niloy Ganguly Department of Computer Science and Engineering IIT Kharagpur Lecture 5: Matrices Dheeraj Kumar Singh 07CS1004 Teacher: Prof. Niloy Ganguly Department of Computer Science and Engineering IIT Kharagpur 29 th July, 2008 Types of Matrices Matrix Addition and Multiplication

More information

Matrix Multiplication

Matrix Multiplication Matrix Multiplication CPS343 Parallel and High Performance Computing Spring 2018 CPS343 (Parallel and HPC) Matrix Multiplication Spring 2018 1 / 32 Outline 1 Matrix operations Importance Dense and sparse

More information

How to declare an array in C?

How to declare an array in C? Introduction An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type. Representation of a large number of homogeneous values.

More information

Fundamentals of MATLAB Usage

Fundamentals of MATLAB Usage 수치해석기초 Fundamentals of MATLAB Usage 2008. 9 담당교수 : 주한규 joohan@snu.ac.kr, x9241, Rm 32-205 205 원자핵공학과 1 MATLAB Features MATLAB: Matrix Laboratory Process everything based on Matrix (array of numbers) Math

More information

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

MATLAB Basics. Configure a MATLAB Package 6/7/2017. Stanley Liang, PhD York University. Get a MATLAB Student License on Matworks MATLAB Basics Stanley Liang, PhD York University Configure a MATLAB Package Get a MATLAB Student License on Matworks Visit MathWorks at https://www.mathworks.com/ It is recommended signing up with a student

More information

Arithmetic operations

Arithmetic operations Arithmetic operations Add/Subtract: Adds/subtracts vectors (=> the two vectors have to be the same length). >> x=[1 2]; >> y=[1 3]; >> whos Name Size Bytes Class Attributes x 1x2 16 double y 1x2 16 double

More information

CS129: Introduction to Matlab (Code)

CS129: Introduction to Matlab (Code) CS129: Introduction to Matlab (Code) intro.m Introduction to Matlab (adapted from http://www.stanford.edu/class/cs223b/matlabintro.html) Stefan Roth , 09/08/2003 Stolen

More information

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

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah) Introduction ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah) MATLAB is a powerful mathematical language that is used in most engineering companies today. Its strength lies

More information

NatSciLab - Numerical Software Introduction to MATLAB

NatSciLab - Numerical Software Introduction to MATLAB Outline 110112 NatSciLab - Numerical Software Introduction to MATLAB Onur Oktay Jacobs University Bremen Spring 2010 Outline 1 MATLAB Desktop Environment 2 The Command line A quick start Indexing 3 Operators

More information

x = 12 x = 12 1x = 16

x = 12 x = 12 1x = 16 2.2 - The Inverse of a Matrix We've seen how to add matrices, multiply them by scalars, subtract them, and multiply one matrix by another. The question naturally arises: Can we divide one matrix by another?

More information

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

Introduction to MATLAB. Simon O Keefe Non-Standard Computation Group Introduction to MATLAB Simon O Keefe Non-Standard Computation Group sok@cs.york.ac.uk Content n An introduction to MATLAB n The MATLAB interfaces n Variables, vectors and matrices n Using operators n Using

More information

Getting To Know Matlab

Getting To Know Matlab Getting To Know Matlab The following worksheets will introduce Matlab to the new user. Please, be sure you really know each step of the lab you performed, even if you are asking a friend who has a better

More information

ELEN E3084: Signals and Systems Lab Lab II: Introduction to Matlab (Part II) and Elementary Signals

ELEN E3084: Signals and Systems Lab Lab II: Introduction to Matlab (Part II) and Elementary Signals ELEN E384: Signals and Systems Lab Lab II: Introduction to Matlab (Part II) and Elementary Signals 1 Introduction In the last lab you learn the basics of MATLAB, and had a brief introduction on how vectors

More information

Linear Algebra in LabVIEW

Linear Algebra in LabVIEW https://www.halvorsen.blog Linear Algebra in LabVIEW Hans-Petter Halvorsen, 2018-04-24 Preface This document explains the basic concepts of Linear Algebra and how you may use LabVIEW for calculation of

More information

Operators. Java operators are classified into three categories:

Operators. Java operators are classified into three categories: Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.

More information

The Mathematics of Big Data

The Mathematics of Big Data The Mathematics of Big Data Linear Algebra and MATLAB Philippe B. Laval KSU Fall 2015 Philippe B. Laval (KSU) Linear Algebra and MATLAB Fall 2015 1 / 23 Introduction We introduce the features of MATLAB

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab November 22, 2013 Contents 1 Introduction to Matlab 1 1.1 What is Matlab.................................. 1 1.2 Matlab versus Maple............................... 2 1.3 Getting

More information

Twister: Language Reference Manual

Twister: Language Reference Manual Twister: Language Reference Manual Manager: Anand Sundaram (as5209) Language Guru: Arushi Gupta (ag3309) System Architect: Annalise Mariottini (aim2120) Tester: Chuan Tian (ct2698) February 23, 2017 Contents

More information

Teaching Manual Math 2131

Teaching Manual Math 2131 Math 2131 Linear Algebra Labs with MATLAB Math 2131 Linear algebra with Matlab Teaching Manual Math 2131 Contents Week 1 3 1 MATLAB Course Introduction 5 1.1 The MATLAB user interface...........................

More information

6.094 Introduction to MATLAB January (IAP) 2009

6.094 Introduction to MATLAB January (IAP) 2009 MIT OpenCourseWare http://ocw.mit.edu 6.094 Introduction to MATLAB January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. 6.094 Introduction

More information

McTutorial: A MATLAB Tutorial

McTutorial: A MATLAB Tutorial McGill University School of Computer Science Sable Research Group McTutorial: A MATLAB Tutorial Lei Lopez Last updated: August 2014 w w w. s a b l e. m c g i l l. c a Contents 1 MATLAB BASICS 3 1.1 MATLAB

More information

Computer Vision. Matlab

Computer Vision. Matlab Computer Vision Matlab A good choice for vision program development because Easy to do very rapid prototyping Quick to learn, and good documentation A good library of image processing functions Excellent

More information

CITS2401 Computer Analysis & Visualisation

CITS2401 Computer Analysis & Visualisation FACULTY OF ENGINEERING, COMPUTING AND MATHEMATICS CITS2401 Computer Analysis & Visualisation SCHOOL OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING Topic 3 Introduction to Matlab Material from MATLAB for

More information

CMAT Language - Language Reference Manual COMS 4115

CMAT Language - Language Reference Manual COMS 4115 CMAT Language - Language Reference Manual COMS 4115 Language Guru: Michael Berkowitz (meb2235) Project Manager: Frank Cabada (fc2452) System Architect: Marissa Ojeda (mgo2111) Tester: Daniel Rojas (dhr2119)

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB --------------------------------------------------------------------------------- Getting MATLAB to Run Programming The Command Prompt Simple Expressions Variables Referencing Matrix

More information