Working with Arrays in MATLAB

Slides:



Advertisements
Similar presentations
Flow Charts, Loop Structures
Advertisements

Chapter 1 Computing Tools Data Representation, Accuracy and Precision Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction.
Maths for Computer Graphics
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.
Introduction to Programming with C++ Fourth Edition
Lecture 2 MATLAB fundamentals Variables, Naming Rules, Arrays (numbers, scalars, vectors, matrices), Arithmetical Operations, Defining and manipulating.
Part 3 Chapter 8 Linear Algebraic Equations and Matrices PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright © The.
Linear Simultaneous Equations
Pam Perlich Urban Planning 5/6020
Matrix Mathematics in MATLAB and Excel
CE 311 K - Introduction to Computer Methods Daene C. McKinney
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.
Chapter 7 Matrix Mathematics Matrix Operations Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 2 Systems of Linear Equations and Matrices Section 2.4 Multiplication of Matrices.
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.
CPS120: Introduction to Computer Science Arrays. Arrays: A Definition A list of variables accessed using a single identifier May be of any data type Can.
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,
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter 2.
CMPS 1371 Introduction to Computing for Engineers MATRICES.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Matlab for Engineers Manipulating Matlab Matrices Chapter 4.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
ENG College of Engineering Engineering Education Innovation Center 1 Array Accessing and Strings in MATLAB Topics Covered: 1.Array addressing. 2.
An Introduction to Programming with C++ Fifth Edition Chapter 11 Arrays.
CPS120: Introduction to Computer Science Lecture 15 Arrays.
The goal is to give an introduction to the mathematical operations with matrices. A matrix is a 2-dimensional arrangement of (real valued) data. The data.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Chapter 6 Matrices and Determinants Copyright © 2014, 2010, 2007 Pearson Education, Inc Matrix Operations and Their Applications.
Slide Copyright © 2009 Pearson Education, Inc. 7.3 Matrices.
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.
3.6 Solving Systems Using Matrices You can use a matrix to represent and solve a system of equations without writing the variables. A matrix is a rectangular.
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.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 1: Variables & Arrays Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers.
1 Lecture 3 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
BRIAN D. HAHN AND DANIEL T. VALENTINE THIRD EDITION Essential MATLAB® for Engineers and Scientists.
Chapter 2: Heat Conduction Equation
Computer Science: A Structured Programming Approach Using C1 8-7 Two-Dimensional Arrays The arrays we have discussed so far are known as one- dimensional.
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)
1. 2  Introduction  Array Operations  Number of Elements in an array One-dimensional array Two dimensional array Multi-dimensional arrays Representation.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Chapter 4 MATLAB Programming MATLAB Troubleshooting Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Manipulating MATLAB Vector, Matrices 1. Variables and Arrays What are variables? You name the variables (as the programmer) and assign them numerical.
MULTI-DIMENSIONAL ARRAYS 1. Multi-dimensional Arrays The types of arrays discussed so far are all linear arrays. That is, they all dealt with a single.
Finishing up Chapter 5. Will this code enter the if statement? G=[30,55,10] if G
Matrix Algebra Basics Chapter 3 Section 5. Algebra.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 3 - Chapter 8 Linear Algebraic Equations and Matrices.
Chapter 1 Computing Tools Variables, Scalars, and Arrays Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Copyright © 2001 by the McGraw-Hill Companies, Inc. Barnett/Ziegler/Byleen Precalculus: Functions & Graphs, 5 th Edition Chapter Nine Matrices & Determinants.
ENG College of Engineering Engineering Education Innovation Center 1 Arrays in MATLAB Topics Covered: 1.Creating arrays of numbers vectors matrices.
ECE 1304 Introduction to Electrical and Computer Engineering
ECE 1304 Introduction to Electrical and Computer Engineering
Chapter 7 Matrix Mathematics
Linear Algebraic Equations and Matrices
Chapter 4 MATLAB Programming
Vectors and Matrices I.
Communication and Coding Theory Lab(CS491)
Array Creation ENGR 1181 MATLAB 02.
EECS Introduction to Computing for the Physical Sciences
Working with Arrays in MATLAB
Announcements.
Presentation transcript:

Working with Arrays in MATLAB Chapter 3 MATLAB Fundamentals Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Review: Scalars and Arrays In a spreadsheet, we do not need to name every variable: the cell address (row/column) defines the storage location Storage locations for time and displacement values Engineering Computation: An Introduction Using MATLAB and Excel

Arrays In MATLAB and other programming languages, the variables must be named and storage of results must be planned An array is a variable that has multiple values An array’s name is followed by an index (or indices, for multi-dimensional arrays) in parentheses Engineering Computation: An Introduction Using MATLAB and Excel

Indices of Arrays Think of the index value as an address Important: Indices must be positive integers, and must start with one Example: To store these results, we would define t(1) = 0, t(2) = 0.1, t(3) = 0.2… y(1) = 3, y(2) = 2.45016… Engineering Computation: An Introduction Using MATLAB and Excel

Common Mistakes Using Indices with MATLAB Using an index of zero: Using an index not an integer: setting t(0.1) equal to a value results in the same error as above Engineering Computation: An Introduction Using MATLAB and Excel

Common Mistakes Using Indices with MATLAB Progressing indices by values other than 1. For example, if we take a temperature reading every 10 seconds, and set the first value as T(10), then zeros are filled in for the first nine values of T: (No error is reported, but this result is probably not what is desired) All of these errors result from confusion between independent variables and indices. Thinking of indices as addresses helps avoid these errors Engineering Computation: An Introduction Using MATLAB and Excel

Multi-Dimensional Arrays A variable may have more than one index. A two-dimensional array is similar to the data storage of a spreadsheet. Instead of a row number and a column letter, a two-dimensional array has two index numbers Examples: t(1,5) R(3,3) temp(1,20) Efficient way to store data: if both indices range from 1-10, then the number of values stored is 10 X 10 = 100 Engineering Computation: An Introduction Using MATLAB and Excel

Matrices One- and two-dimensional arrays are also called matrices Many mathematical operations can be performed with matrices - the name MATLAB comes from “Matrix Laboratory” The size of a matrix is defined by the numbers of rows and columns. Example; a 3 X 2 matrix: Engineering Computation: An Introduction Using MATLAB and Excel

Vectors One-dimensional matrices are referred to in MATLAB as vectors Vectors can be classified as column vectors (all values arranged in a single column) or row vectors (all values arranged in a single row) Caution: in mechanics classes, the term “vector” has a different definition: a vector is defined as a physical quantity which is defined by magnitude and direction Engineering Computation: An Introduction Using MATLAB and Excel

Entering Arrays in MATLAB Consider the matrix: To enter this matrix in MATLAB: or Commas or spaces separate elements within a row, semi-colons separate rows Engineering Computation: An Introduction Using MATLAB and Excel

Arrays We will work with matrix math later, with applications such as solving simultaneous equations We will create large arrays of results using programming loops. Loops control the execution of repetitive calculations, and the results are often stored in arrays Engineering Computation: An Introduction Using MATLAB and Excel