Chapter 1 Computing Tools Variables, Scalars, and Arrays Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Slides:



Advertisements
Similar presentations
Flow Charts, Loop Structures
Advertisements

Arrays  An array is a collection of like elements.  There are many engineering applications that use arrays.  MATLAB ® stores data in arrays and performs.
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.
An Introduction to Programming with C++ Fifth Edition
Introduction to Programming with C++ Fourth Edition
Copyright © The McGraw-Hill Companies, Inc
Dr. Jie Zou PHY Welcome to PHY 3320 Computational Methods in Physics and Engineering.
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
Matrix Mathematics in MATLAB and Excel
Chapter 9 Numerical Integration Numerical Integration Application: Normal Distributions Copyright © The McGraw-Hill Companies, Inc. Permission required.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 2 Image Slides.
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 8 Traffic-Analysis Techniques. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 8-1.
Chapter 4 MATLAB Programming Combining Loops and Logic Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Mathcad Variable Names A string of characters (including numbers and some “special” characters (e.g. #, %, _, and a few more) Cannot start with a number.
Chapter 6 Finding the Roots of Equations
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Chapter 1 Computing Tools Analytic and Algorithmic Solutions Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Part 2 Chapter 7 Optimization
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
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.
Part 3 Chapter 11 Matrix Inverse and Condition PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright © The McGraw-Hill.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 9 Arrays.
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 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
© Copyright 2013 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 8 Multidimensional Arrays.
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.
Chapter 1 Computing Tools Analytic and Algorithmic Solutions Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
ENG College of Engineering Engineering Education Innovation Center 1 Array Accessing and Strings in MATLAB Topics Covered: 1.Array addressing. 2.
Working with Arrays in MATLAB
An Introduction to Programming with C++ Fifth Edition Chapter 11 Arrays.
Computer Programming TCP1224 Chapter 11 Arrays. Objectives Using Arrays Declare and initialize a one-dimensional array Manipulate a one-dimensional array.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter 3.
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.
Newton’s Method, Root Finding with MATLAB and Excel
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.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
MT411 Robotic Engineering Asian Institution of Technology (AIT) Chapter 1 Introduction to Matrix Narong Aphiratsakun, D.Eng.
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.
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.
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.
Chapter 2 Excel Fundamentals Logical IF (Decision) Statements Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
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
Chapter 13 Transportation Demand Analysis. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display
Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Third Edition by Tony Gaddis.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 3 - Chapter 8 Linear Algebraic Equations and Matrices.
Chapter 7 Matrix Mathematics
Linear Algebraic Equations and Matrices
Accuracy and Precision
Chapter 4 MATLAB Programming
Plotting Data with MATLAB
Working with Arrays in MATLAB
Announcements.
Presentation transcript:

Chapter 1 Computing Tools Variables, Scalars, and Arrays Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Variables To solve the projectile problem, data was needed (projectile velocity, angle, time, height, and so on) In programs, data is stored in variables In Excel, each cell is a variable that can hold data In Matlab, the variables are given names, usually a name that reminds you what is in the variable (t for time, h for height) Engineering Computation: An Introduction Using MATLAB and Excel

Scalars and Arrays Variables can be a scalar or an array A scalar is a single value that can be represented on a numerical scale In a spreadsheet, each cell is contains a scalar value. This is an advantage of spreadsheets; the storage of results is automatic Engineering Computation: An Introduction Using MATLAB and Excel

Scalars and Arrays (cont.) In a spreadsheet, we do not need to name every variable: the cell address (row/column) defines the storage location In MATLAB and other programming languages, the variables must be named and storage of results must be planned Example: In the cannon problem, we can call time “t”. If t is a scalar, then the value of t is overwritten every time we complete a calculation loop Engineering Computation: An Introduction Using MATLAB and Excel

Scalars and Arrays (cont.) In the projectile problem, the time and height were calculated multiple times If we keep t and h in a scalar, each new calculation replaces the last one An array is a variable that has multiple values We can use arrays for data that is changing, if we want to keep all of its 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 For example, suppose that we store values for time at 0.1 second intervals. If we say that t(5) = 0.4, then we mean that the 5 th value in the array of time values is equal to 0.4 Important: Indices must be positive integers, and must start with one 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