EGR 115 Introduction to Computing for Engineers MATLAB Basics 1: Variables & Arrays Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers.

Slides:



Advertisements
Similar presentations
Etter/Ingber Arrays and Matrices. Etter/Ingber One-Dimensional Arrays 4 An array is an indexed data structure 4 All variables stored in an array are of.
Advertisements

Introduction to arrays
Chapter 1 Computing Tools Data Representation, Accuracy and Precision Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction.
Maths for Computer Graphics
ECE122 L14: Two Dimensional Arrays March 27, 2007 ECE 122 Engineering Problem Solving with Java Lecture 14 Two Dimensional Arrays.
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.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
Introduction of Arrays. Arrays Array form an important part of almost all programming language. It provides a powerful feature and can be used as such.
Dr. Jie Zou PHY Welcome to PHY 3320 Computational Methods in Physics and Engineering.
Lecture 2 MATLAB fundamentals Variables, Naming Rules, Arrays (numbers, scalars, vectors, matrices), Arithmetical Operations, Defining and manipulating.
EGR 106 – Week 3 – More on Arrays Brief review of last week Additional ideas: – Special arrays – Changing an array – Some array operators – Character arrays.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
CE 311 K - Introduction to Computer Methods Daene C. McKinney
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 Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
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.
Learner’s Guide to MATLAB® Chapter 2 : Working with Arrays.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
Matrix Arithmetic. A matrix M is an array of cell entries (m row,column ) and it must have rectangular dimensions (Rows x Columns). Example: 3x x.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
Chapter 4 Review: Manipulating Matrices Introduction to MATLAB 7 Engineering 161.
Lesson 11-1 Matrix Basics and Augmented Matrices Objective: To learn to solve systems of linear equation using matrices.
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
A string is an array of characters Strings have many uses in MATLAB Display text output Specify formatting for plots Input arguments for some functions.
CPS120: Introduction to Computer Science Lecture 15 Arrays.
Meeting 18 Matrix Operations. Matrix If A is an m x n matrix - that is, a matrix with m rows and n columns – then the scalar entry in the i th row and.
Slide Copyright © 2009 Pearson Education, Inc. 7.3 Matrices.
EGR 115 Introduction to Computing for Engineers Designing The Battleship Game in MATLAB Monday 22 Sept 2014 EGR 115 Introduction to Computing for Engineers.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 3: Array Operations Monday 08 Sept 2014 EGR 115 Introduction to Computing for Engineers.
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
EGR 115 Introduction to Computing for Engineers MATLAB Basics 5: Applications – Vector Math Friday 12 Sept 2014 EGR 115 Introduction to Computing for Engineers.
Introduction to Engineering MATLAB – 4 Arrays Agenda Creating arrays of numbers  Vectors: 1-D Arrays  Arrays: 2-D Arrays Array Addressing Strings & String.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
Computer Programming for Engineers
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)
1 Arrays of Arrays Quick review … arrays Arrays of arrays ≡ multidimensional array Example: times table Representation in memory Ragged arrays Example:
Arrays. Topics to be Covered... Arrays ◦ Declaration ◦ Assigning values ◦ Array manipulation using loops Multi-dimensional arrays ◦ 2D arrays ◦ Declaration.
Engineering Computing I Chapter 5 Pointers and Arrays.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
EGR 115 Introduction to Computing for Engineers Loops and Vectorization – Part 3 Friday 17 Oct 2014 EGR 115 Introduction to Computing for Engineers.
C++ Array 1. C++ provides a data structure, the array, which stores a fixed-size sequential collection of elements of the same type. An array is used.
1.8 Multidimensional Arrays academy.zariba.com 1.
Two dimensional arrays A two dimensional m x n array A is a collection of m. n elements such that each element is specified by a pair of integers (such.
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.
Introduction to Programming Lecture 12. Today’s Lecture Includes Strings ( character arrays ) Strings ( character arrays ) Algorithms using arrays Algorithms.
Chapter 1 Computing Tools Variables, Scalars, and Arrays Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Matrices. Variety of engineering problems lead to the need to solve systems of linear equations matrixcolumn vectors.
Arrays An array is a sequence of objects all of which have the same type. The objects are called the elements of the array and are numbered consecutively.
Multiplying Matrices.
ECE 1304 Introduction to Electrical and Computer Engineering
Linear Algebra review (optional)
Chapter 3 Arrays and Vectors
EGR 115 Introduction to Computing for Engineers
Matrix Operations Monday, August 06, 2018.
Multiplying Matrices.
CSCI N207 Data Analysis Using Spreadsheet
Multidimensional array
Multiplying Matrices.
Multi-Dimensional Arrays
Multiplying Matrices.
Working with Arrays in MATLAB
Multiplying Matrices.
Multiplying Matrices.
Presentation transcript:

EGR 115 Introduction to Computing for Engineers MATLAB Basics 1: Variables & Arrays Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers

Lecture Outline Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers MATLAB Basics  Variables and arrays Slide 2 of 14

MATLAB basics Variables and arrays: Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers A variable is a symbolic name (or identifier) which serves as a placeholder or container for “data”  It is good programming practice to use a pertinent name for variables o E.g., >> accel_due_to_gravity = 9.81;% g in m/s^2  Variables exhibit a variety of properties o Scope or visibility – Is it globally or only locally visible? o Extent – Life-time of the variable? o Type – Is it an integer, float, character, … Slide 3 of 14

MATLAB basics Variables and arrays: Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers Strongly typed languages  Requires that the data type of the variable must be declared before it is used o E.g., int miles; – The variable “miles” is declared to be of type integer Weakly typed languages  Does NOT Requires that the data type of the variable be declared before it is used o E.g., >> letters = ‘ab’; – The variable “letters ” is determined to be of type character because of the type of data assigned to the variable. C programming language MATLAB programming language Slide 4 of 14

MATLAB basics Variables and arrays – Matrices (2D arrays) Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers An array is a multi-dimensional list  A matrix is a 2-dimensional array with rows and columns o E.g., the game Battleships Slide 5 of 14

MATLAB basics Variables and arrays – Matrices (2D arrays) Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers row 1 row 2 row 3 row 4 column 1column 2column 3column 4column 5 M ( row, column ) Answer: M( 2, 4 ) ? What is the address of the element in question? Answer: It is a 4 X 5 matrixWhat is the size of the matrix? Slide 6 of 14

MATLAB basics Variables and arrays – Vectors (1D arrays) Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers A vector is a one-dimensional array  It could be a row vector  Or, it could be a column vector A scalar is an array with only a single element  E.g., a 1X1 matrix or a vector with only one entry Slide 7 of 14

MATLAB basics Variables and arrays: Matrix, Vector, and scalar examples Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers Examples  ‘a’ is a 3  2 array or 3  2 matrix  ‘b’ is a 1  4 array or 4-element row vector  ‘c’ is a 3  1 array or 3-element column vector  ‘d’ is a scalar Slide 8 of 14

MATLAB basics Variables and arrays – Data types Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers MATLAB stores var as a double precision float Slide 9 of 14

MATLAB basics Variables and arrays - Initialization Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers In MATLAB variables are automatically created when they are initialized. >> x = [ ] o Creates a 1  3 1D array ‘x’ (row vector) of doubles >> x = [2.2, 1.0, 3.5] o Same as above (the commas are optional) >> y = [2.2; 1.0; 3.5] o Creates a 3  1 column vector. >> y = [ ] o Same as above Slide 10 of 14

MATLAB basics Variables and arrays: Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers Creating and initializing a matrix >> z = [ 1 2 3; 4 5 6] o Creates a 2  3 array (matrix) >> z = [ ] o Same as above >> z = [ 1, 2, 3; 4, 5, 6] o Same as above >> z = [] o Creates an empty array (size is undefined) Must be a rectangular (or square) matrix All cols the same length and All rows the same length Must be a rectangular (or square) matrix All cols the same length and All rows the same length Slide 11 of 14

MATLAB basics Variables and arrays: Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers Abbreviated Initialization  X = start : increment : end >> x = 0.5 : 1.5 : 6 Initializing with built-in functions >> a = zeros(2, 5) >> b = ones(1, 4) >> c = zeros(3, 1) >> d = ones(3, 2) Can ask MATLAB to determine the size of an array >> size(d) Slide 12 of 14

MATLAB basics Variables and arrays: Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers Initializing with keyboard input  val = input('Any text to prompt user to enter a value '); o Try it!! MATLAB supports arrays with greater than two dimensions  We will rarely go beyond 2D arrays (i.e., matrices) How does MATLAB store matrices in memory?  Column major order o 1 st col, then 2 nd col, …. E.g., >> z = [ 1, 2, 3; 4, 5, 6] Answer: z(3) = z(1,2) = 2What is the value of z(3)? Slide 13 of 14

Next Lecture Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers Sub-Arrays Displaying data Slide 14 of 14