>> x = [1 2 3 4 5]; y = 2*x y = 2 4 6 8 10 Arrays x and y are one dimensional arrays called vectors. In MATLAB all variables are arrays. They allow functions.

Slides:



Advertisements
Similar presentations
Multidimensional Array
Advertisements

Introduction to M ATLAB Programming Ian Brooks Institute for Climate & Atmospheric Science School of Earth & Environment
Lecture 4.
Lecture 4 Sept 8 Complete Chapter 3 exercises Chapter 4.
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.
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
Division Example 2x - 3y + 4z = 10 x + 6y - 3z = 4 -5x + y + 2z = 3 A*X = B where A = B = >> X = A\B X =
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.
Part 1 Chapter 2 MATLAB Fundamentals
MATLAB Fundamentals.
What is MATLAB ? MATrix LABratory –Originally, it was a front-end to FORTRAN matrix routines developed in the U. of New Mexico and Stanford –Today.
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
Mathcad Variable Names A string of characters (including numbers and some “special” characters (e.g. #, %, _, and a few more) Cannot start with a number.
AN ENGINEER’S GUIDE TO MATLAB
INTRO TO PROGRAMMING Chapter 2. M-files While commands can be entered directly to the command window, MATLAB also allows you to put commands in text files.
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
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,
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
A Brief Introduction to Matlab Laila Guessous Dept. of Mechanical Engineering Oakland University.
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.
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
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.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
EGR 106 – Functions Functions – Concept – Examples and applications Textbook chapter p15-165, 6.11(p 178)
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
ES 240: Scientific and Engineering Computation. Chapter 2 Chapter 2: MATLAB Fundamentals Uchechukwu Ofoegbu Temple University.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Working with Arrays in MATLAB
INTRODUCTION TO MATLAB MATLAB is a software package for computation in engineering, science, and applied mathemat-ics. It offers a powerful programming.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Part 1 Chapter 2 MATLAB Fundamentals PowerPoints organized by Dr. Michael R. Gustafson II, Duke University and Prof. Steve Chapra, Tufts University All.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
(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 MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Digital Image Processing Introduction to MATLAB. Background on MATLAB (Definition) MATLAB is a high-performance language for technical computing. The.
Introduction to Engineering MATLAB – 4 Arrays Agenda Creating arrays of numbers  Vectors: 1-D Arrays  Arrays: 2-D Arrays Array Addressing Strings & String.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
M ATLAB – What Is It ? Name is from matrix laboratory Powerful tool for – Computation and visualization of engineering and science mathematics – Communication.
Matlab for Engineers Matlab Environment Chapter 2.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Tutorial 2 : Matlab - Getting Started.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
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.
Project Teams Project on Diffusion will be a TEAM project. 34 Students in class so 6 teams of 5 and one Team of 4. Determine members of team and a team.
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
An Introduction to Programming in Matlab Emily Blumenthal
1-2 What is the Matlab environment? How can you create vectors ? What does the colon : operator do? How does the use of the built-in linspace function.
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
EEE 244 Numerical Methods In Electrical Engineering
Part 1 Chapter 2 MATLAB Fundamentals
Arrays and Matrices in MATLAB
Array Creation ENGR 1181 MATLAB 02.
INTRODUCTION TO MATLAB
Part 1 Chapter 2 MATLAB Fundamentals
Working with Arrays in MATLAB
Presentation transcript:

>> x = [ ]; y = 2*x y = Arrays x and y are one dimensional arrays called vectors. In MATLAB all variables are arrays. They allow functions with many values to be described.

EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays Arrays chapter 2, pages Scripts chapter 4, pages

Recall from Last Week Variables: placeholders for numerical data – equal sign is an assignment operator c = 7.5 c = c + 1 – naming restrictions (not pi, etc. ) – can be complex valued ( x = 3 + i 7 ) Basic math on numbers and variables: Precedence ( ) ^ * / + -

Names for special sizes – scalar: 1 x 1 array 4 or [4] – row vector: 1 x C array [ ] is a 1 x 5 row vector – column vector: R x 1 array is a 3 x 1 column vector

Uniformly Spaced Vectors Colon operator first : increment : maximum yields a row vector of equally spaced values – examples: 0 : 2 : 10 [ ] 1 : 5 [ ] 7 : -2 : -3 [ ] 1 : 2 : 8 [ ] – default for increment is 1 Note – does not hit 8!!

Arrays Fundamental data unit in Matlab – all variables are stored as arrays Data values organized into rows and columns – numeric or alphanumeric entries

Array Construction Direct specification: – Name followed by an equal sign ( = ), just like variables – List values within a pair of brackets ( [ ] ) – Enter data one row at a time left to right, top to bottom order space or comma between the values rows separated by semicolons or the enter key

Size or dimension of an array: – number of rows and columns – written as R by C or R x C where R = number of rows C = number of columns e.g. yield is 3 by 4 test is 1 by 5

Building Arrays >>a = [1 2 3; 4 5 6; 7 8 9; ] >>a = [1:3; 4:6; 7:9; 10:12]

– Can use simple math operations as well as numerics as the entries: – Note the common format of all entries in the response (exp(1) = e = , log 10 (100) = 2, = ) – M ATLAB scales the exponent to the largest entry !!

– This scaling is sometimes deceptive: Not really zero Really zero

Concatenation – gluing arrays together if a = [ ] b = [ ] – Attaching left to right – use a comma [ a, b ] – Attaching top to bottom – use a semicolon [ a; b ] semicolon comma

– Note that sizes must match for this to work: if a = [ ] then [ a, b ] = ?? [ a; b ] = ?? – Size needs for concatenation: # of rows the same for side by side (comma) # of columns the same for top to bottom (semicolon)

Addressing and Sub-Arrays How to indicate a particular element within an array: – use parentheses after the array name – list desired row, comma, desired column – e.g. yield(2,4)

How About More than One Entry? Can specify a rectangular sub-array – again, use parenthesis after the array name – list desired rows, comma, desired columns as a vector, typically in brackets – e.g. yield([1 2],[3 4])

Used to read a value from an array (right hand side of = )

Addressing Errors

Things that do Work Single indexing of matrices counts down columns, starting at the top left

Some Useful Array Operators Transpose (single quote symbol ' ) – switches rows and columns

Useful Array Functions length(A) is the number of elements in the vector A [m n] = size(A), where A is a matrix with m rows and n columns ones(n) is an n x n matrix of ones zeros(n) is an n x n matrix of zeros

CHANGE THE MATRIX sample = >> sample(1,3)=9 sample =

Used to read a sub-array ( rhs of =) Note – scalar row choice does not need brackets!

Character Arrays Rows of the array are strings of alphanumeric characters, one array entry per character Enter using a single quotation mark ( ' ) at each end

Assigning values with too large an index just grows the array

Scalars work for sub- array replacement – they just scale up to the right size

Replacing with a null matrix is the same as deleting – but it only works for entire rows or columns

Rules of the road for arrays: Symbols to use: brackets to glue elements together to make an array (left to right or top to bottom) comma (or space) and semicolon (or enter) for separating column/row elements parentheses after the array name for addressing Be careful to match array sizes Remember – rows first, then columns in addressing

Scripts – Simple Programs So far, commands have been typed in the command window: – Executed by pressing “enter” – Edited using the arrow keys or the history window

Script (m-file) Concept A file containing Matlab commands – Can be re-executed – Is easily changed/modified or ed to someone Commands are executed one by one sequentially – File is executed by typing its name (without.m) – Results appear in the command window (or use ; ) Can be created using any text editor –.m extension – Listed in Current Directory window

Sample Scripts

DIFFUSION Diffusion – is the movement of matter driven by chemical and thermal processes such as concentration gradients and heating. Both are needed as it is an activation controlled process. Atoms will diffuse down a concentration gradient provided they have overcome the activation energy needed for the process. Copper atoms will diffuse into the Nickel until an equal concentration is Achieved. Remember that Cu-Ni system Is one of complete solid solubility. Position Cu

Practical Example Decarburization at 1200F after quench crack in material. The crack left enough open surface For the carbon to diffuse out and leave a ferrite layer either side of the crack.

ARRAYS FOR DIFFUSION DIFFUSION RATE AGAINST TEMPERATURE STRENGTH AGAINST CARBON CONTENT