Arrays and Matrices in MATLAB

Slides:



Advertisements
Similar presentations
Maths for Computer Graphics
Advertisements

EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
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.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Lecture 2 MATLAB fundamentals Variables, Naming Rules, Arrays (numbers, scalars, vectors, matrices), Arithmetical Operations, Defining and manipulating.
Lecture 8: Cascaded Linear Transformations Row and Column Selection Permutation Matrices Matrix Transpose Sections 2.2.3, 2.3.
1 Chapter 3 Matrix Algebra with MATLAB Basic matrix definitions and operations were covered in Chapter 2. We will now consider how these operations are.
1.3 Matrices and Matrix Operations.
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
1 Introduction to MATLAB MATLAB is all of the following: 1.Computational environment 2.Plotting software 3.Programming language Typical applications: 1.Calculations.
Creating scalars, vectors, matrices Ex1 & 2. Dot Product & Cross Product Ex3. Plotting Graphs Ex4. Conversion Table Ex5. Plotting functions Finishing Ex4.
Martin Ellison University of Warwick and CEPR Bank of England, December 2005 Introduction to MATLAB.
Linear Algebra Lecture 25.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
Introduction to MATLAB Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
Matlab Chapter 2: Array and Matrix Operations. What is a vector? In Matlab, it is a single row (horizontal) or column (vertical) of numbers or characters.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
CSE123 Lecture 5 Arrays and Array Operations. Definitions Scalars: Variables that represent single numbers. Note that complex numbers are also scalars,
Chapter 2 Numeric, Cell, and Structure Arrays. Physics Connection - Specification of a position vector using Cartesian coordinates. Figure 2.1–1 2-2 The.
1.3 Matrices and Matrix Operations. Definition A matrix is a rectangular array of numbers. The numbers in the array are called the entries in the matrix.
Arrays 1 Multiple values per variable. Why arrays? Can you collect one value from the user? How about two? Twenty? Two hundred? How about… I need to collect.
Introduction to Matlab Module #2 Page 1 Introduction to Matlab Module #2 – Arrays Topics 1.Numeric arrays (creation, addressing, sizes) 2.Element-by-Element.
Matlab for Engineers Manipulating Matlab Matrices Chapter 4.
>> x = [ ]; y = 2*x y = Arrays x and y are one dimensional arrays called vectors. In MATLAB all variables are arrays. They allow functions.
Chapter 2 Creating Arrays Legend: MATLAB command or syntax : Blue MATLAB command OUTPUT : LIGHT BLUE.
(The Transpose Operator) 1 >> C=[ ; ; ] C = >> D=C' D =
Array Creation ENGR 1181 MATLAB 2. Civil engineers store seismic data in arrays to analyze plate tectonics as well as fault patterns. These sets of data.
Array Creation ENGR 1187 MATLAB 2. Today’s Topics  Arrays: What are they?  Vectors  Matrices  Creating Arrays.
Introduction to Engineering MATLAB – 4 Arrays Agenda Creating arrays of numbers  Vectors: 1-D Arrays  Arrays: 2-D Arrays Array Addressing Strings & String.
CMPS 1371 Introduction to Computing for Engineers VECTORS.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
Digital Image Processing. Converting between Data Classes The general syntax is B = data_class_name (A) Where data_class_name is one of the names defined.
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.
Table of Contents Matrices - Definition and Notation A matrix is a rectangular array of numbers. Consider the following matrix: Matrix B has 3 rows and.
An Introduction to Programming in Matlab Emily Blumenthal
Matrices. Variety of engineering problems lead to the need to solve systems of linear equations matrixcolumn vectors.
ENG College of Engineering Engineering Education Innovation Center 1 Arrays in MATLAB Topics Covered: 1.Creating arrays of numbers vectors matrices.
LAB 2 Vectors and Matrices Dr.Abdel Fattah FARES.
Goals for today Learn to create, combine, and index arrays Learn to multiply arrays in MATLAB Use matrix multiplication to simulate a real-world problem.
מטלב וניתוח נתונים ממערכות עצביות היכרות עם MATLAB
Matrices and Vector Concepts
7.1 Matrices, Vectors: Addition and Scalar Multiplication
Introduction to MATLAB for Engineers, Third Edition
ECE 1304 Introduction to Electrical and Computer Engineering
Linear Algebra review (optional)
Manipulating MATLAB Matrices Chapter 4
1.5 Matricies.
Chapter 2 Creating Arrays.
Introduction to MATLAB 7
MATHEMATICS Matrix Multiplication
Vectors and Matrices Chapter 2 Attaway MATLAB 4E.
Vectors and Matrices I.
Digital Image Processing
CSCI N207 Data Analysis Using Spreadsheet
Array and Matrix Functions
Communication and Coding Theory Lab(CS491)
Matrices Introduction.
Matrices and Matrix Operations
Array Creation ENGR 1181 MATLAB 02.
Matlab Intro.
Vectors and Matrices Chapter 2 Attaway MATLAB 4E.
Linear Algebra review (optional)
Introduction to MATLAB 7
Arrays in Matlab UC Berkeley Fall 2004, E Copyright 2005, Andy Packard
Matrices in MATLAB Dr. Risanuri Hidayat.
EECS Introduction to Computing for the Physical Sciences
Matlab Intro.
Presentation transcript:

Arrays and Matrices in MATLAB EE 201

Class Learning Objectives Achieve Comprehension LOL of Arrays and Matrices in MATLAB.

Creating Numeric Arrays We can create numeric array using: a- Square bracket b- Colon operator

Square bracket([ ]) Row array :The elements of the array must be separated by commas or spaces. Example:

Column array: The elements of the array must be separated by: -semicolon or use the -transpose notation(‘) which converts a row vector into a column vector or vice versa. For example:

Colon Operator(:) The colon operator generates a sequence of numbers that you can use in creating or indexing into arrays. Numeric Sequence Range Generate a sequential series of regularly spaced numbers from first to last using the syntax first:last. For an incremental sequence from 6 to 17, use: N = 6:17

Example:

Colon Operator(:) Numeric Sequence Step Generate a sequential series of numbers, each number separated by a step value, using the syntax : first:step:last. For a sequence from 2 through 38, stepping by 4 between each entry, use: A = 2:4:38

Example:

linspace command The linspace command also creates a linearly spaced row vector, but instead you specify the number of values rather than the increment.   The syntax is linspace (x1,x2,n), where x1 and x2 are the lower and upper limits and n is the number of points. , where q is step. Which means: q= (x2-x1)/(n-1) -For example, linspace (5,8,31) is equivalent to [5:0.1:8]. -If n is omitted, generates a row vector of 100 linearly equally spaced points between x1 and x2.

logspace command The logspace command creates an array of logarithmically spaced elements. Its syntax is logspace(a,b,n), where n is the number of points between 10a and 10b. For example, x=logspace(-1,1,4) is equivalent to x=10.^[-1:2/3:1]; produces the vector : x=[0.1000,0.4642, 2.1544,10.000]. If n is omitted, the number of points defaults to 50.

Array Index Array index points to a particular element in the array. It uses to know the value of element in the array. Example: Use MATLAB to compute w=5sinu for u=0,0.1,0.2…..10 and determine the value of the seventh element in the array u and w.

Solution of example

Matrices A matrix has multiple rows and columns. For example, the matrix M= has four rows and three columns. Vectors are special cases of matrices having one row or one column.

Creating Matrices If the matrix is small you can type it row by row, separating the elements in a given row with spaces or commas and separating the rows with semicolons. For example, typing: >>A=[2,4,10;16,3,7]; creates the following matrix:  A= Remember, spaces or commas separate elements in different columns, whereas semicolons separate elements in different rows.

Creating Matrices from Vectors Suppose a= [1,3,5] and b=[7,9,11] (row vectors). Note the difference between the results given by: [a b] and [a ; b] in the following session: >>c=[a b] >>d=[a;b] c= d= 1 3 5 7 9 11 1 3 5 7 9 11

Array Addressing v(:) represents all the row or column elements of the vector v. v(2:5) represents the second through fifth elements; that is v(2), v(3), v(4), v(5) . A(:,3) denotes all the elements in the third column of the matrix A A(:,2:5) denotes all the elements in the second through fifth columns of A. A(2:3,1:3) denotes all the elements in the second and third rows that are also in the first through third columns.

You can use array indices to extract a smaller array from another array. For example, if you first create the array B. B= then type C=B(2:3,1:3),you can produce the following array: c=

Empty array The empty(null) array contains no elements and is expressed as []. Rows and columns can be deleted by setting the selected row or column equal to the null array, for example: -A(3,:)=[ ] deletes the third row in A -A([1 4],:)=[ ] deletes the first row and fourth rows of A Let A= -A(1,5)=3 changes matrix to: A=

-B=A(:,5:-1:1) B= -suppose C=[-4,12,3,5,8] , B(2,:)=C B= -suppose D=[3,8,5;2,-6,9] , E=D([2,2,2],:) E=