Creating scalars, vectors, matrices Ex1 & 2. Dot Product & Cross Product Ex3. Plotting Graphs Ex4. Conversion Table Ex5. Plotting functions Finishing Ex4.

Slides:



Advertisements
Similar presentations
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 10.
Advertisements

Lecture 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.
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.
Matrix Mathematics in MATLAB and Excel
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.
Lecture 7: Matrix-Vector Product; Matrix of a Linear Transformation; Matrix-Matrix Product Sections 2.1, 2.2.1,
Chapter 2 Systems of Linear Equations and Matrices Section 2.4 Multiplication of Matrices.
Part 1 Chapter 2 MATLAB Fundamentals
MATLAB Fundamentals.
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.
Martin Ellison University of Warwick and CEPR Bank of England, December 2005 Introduction to MATLAB.
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,
ARRAY REFERENCING 1 1. II. Array Referencing Assume an array has values. It is useful to “refer to” the elements contained within it – as smaller portions.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
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,
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.
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.
MATLAB An Introduction to MATLAB (Matrix Laboratory) 1.
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.
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.
ES 240: Scientific and Engineering Computation. Chapter 2 Chapter 2: MATLAB Fundamentals Uchechukwu Ofoegbu Temple University.
Digital Image Processing Lecture4: Fundamentals. Digital Image Representation An image can be defined as a two- dimensional function, f(x,y), where x.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Asking the USER for values to use in a software 1 Input.
Working with Arrays in MATLAB
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.
>> x = [ ]; y = 2*x y = Arrays x and y are one dimensional arrays called vectors. In MATLAB all variables are arrays. They allow functions.
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.
ENG College of Engineering Engineering Education Innovation Center 1 Basic For Loops in MATLAB Programming in MATLAB / Chapter 6 Topics Covered:
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 MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
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.
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)
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.
CS100A, Fall 1998, Lecture 191 CS100A, Fall 1998 Lecture 19, Thursday Nov 05 Matlab Concepts: Matlab arrays Matlab subscripting Matlab plotting.
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
Precalculus Section 14.1 Add and subtract matrices Often a set of data is arranged in a table form A matrix is a rectangular.
To add, subtract, multiply, and divide, absolutely follow the mathematical rules. 1. All the rules 2. The element-per-element operator 3. Ex1: graphing.
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
ECE 1304 Introduction to Electrical and Computer Engineering
EEE 244 Numerical Methods In Electrical Engineering
MATH 493 Introduction to MATLAB
Vectors and Matrices I.
Communication and Coding Theory Lab(CS491)
Arrays and Matrices in MATLAB
Array Creation ENGR 1181 MATLAB 02.
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.
EECS Introduction to Computing for the Physical Sciences
Presentation transcript:

Creating scalars, vectors, matrices Ex1 & 2. Dot Product & Cross Product Ex3. Plotting Graphs Ex4. Conversion Table Ex5. Plotting functions Finishing Ex4. Ex6 and Ex7. Use of matrices in real world Creating Arrays 11

1. Creating scalars Assign a value to a variable (i.e. Hardcode) pressure = 10; %pascals temperature = 298; %kelvin Store the result of an equation pressure = density*R*temperature; Save the return-value of the input() command age = input(‘Enter your age: ’); 22

2. Creating vectors There are LOTS of ways to create vectors, based on three simple ideas: The values in the vector are pre-defined. For example: [ ] 33

2. Creating vectors There are LOTS of ways to create vectors, based on three simple ideas: The values in the vector are pre-defined. For example: [ ] The values have a pattern (addition only). For example: [10, 20, 30,…100] or [ ] 44

2. Creating vectors There are LOTS of ways to create vectors, based on three simple ideas: The values in the vector are pre-defined. For example: [ ] The values have a pattern (addition only). For example: [10, 20, 30,…100] or [ ] Finally, the total amount of values is known. For example: 25 points evenly spaced from 0 to

2.1. Pre-defined values 66

Pre-defined values, cont.

88

99 What else are semi-colons used for? 2.1. Pre-defined values, cont.

10 What else are semi-colons used for? They create rows AND suppress output! 2.1. Pre-defined values, cont.

11 What else are semi-colons used for? They create rows AND suppress output! The apostrophe allows to transpose a vector. Rows become columns. Columns become rows Pre-defined values, cont.

12 What else are semi-colons used for? They create rows AND suppress output! The apostrophe allows to transpose a vector. Rows become columns. Columns become rows. What dimension will speeds have? _______________________________ 2.1. Pre-defined values, cont.

Ex1. Dot product Remember the DOT product? (maybe/maybe not) 13 Credits to: ogs2010/cmc/chapters/Hebbi an/ten5.gif ogs2010/cmc/chapters/Hebbi an/ten5.gif The DOT product…

Ex1. Dot product Remember the DOT product? (maybe/maybe not) 14 Credits to: ogs2010/cmc/chapters/Hebbi an/ten5.gif ogs2010/cmc/chapters/Hebbi an/ten5.gif In Matlab The DOT product…

*** * * * Ex2. Cross product How about the CROSS product? (maybe/maybe not) 15 Source: /readings/crossprodex/ /readings/crossprodex/ Source: Wikipedia The CROSS product…

Cross product, cont. 16 In Matlab

Ex3. Plotting graphs In order to plot, Matlab needs data points: 17 x y x y

Ex3. Plotting graphs In order to plot, Matlab needs data points: 18 x y x y

Ex3. Plotting graphs In order to plot, Matlab needs data points: 19 x y x y Matlab connects the dots!

Ex3. Plotting graphs In order to plot, Matlab needs data points: Well… x is an array of data points x = [ ] y is another array of data points y = [ ] …for the curious ones, to plot: plot(x,y) 20 x y x y

2.2. Patterns (addition only) 21 The range operator Numbers are separated by +1

22 The range operator Numbers are separated by +1 An additional value in the middle specifies the increment >32  2.2. Patterns, cont.

23 The range operator Numbers are separated by +1 An additional value in the middle specifies the increment >32  < 3  Go reverse by using a negative increment! CAUTION: the beginning number must be > the end number. Here 10>3. (This also shows it works with decimals.) 2.2. Patterns, cont.

24 The range operator Numbers are separated by +1 An additional value in the middle specifies the increment >32  < 3  To use the apostrophe and create a column vector, absolutely place brackets first! … else… Patterns, cont.

25 The range operator Numbers are separated by +1 An additional value in the middle specifies the increment >32  < 3  To use the apostrophe and create a column vector, absolutely place brackets first! … else…. Only the scalar -10 gets transposed: but a scalar transposed remains the same scalar! 2.2. Patterns, cont.

Ex4. Conversion table % create celsius data points celsius = 0:10:100; %0 to 100 by +10 increment % calculate Fahrenheit fahrenheit = celsius * 9/5 + 32; % show table 26

2.3. Specific amount of data points A built-in function called linspace() spaces elements linearly in an array. What does this mean? The distance between each consecutive data point is equal. There are two ways to use it, as Matlab ‘hints’ when the command typed is unfinished: 27 Either provide 2 arguments, or provide 3 arguments.

2.3. linspace(), cont. 28 The third argument indicates the ________________________.

29 The third argument indicates the ________________________. When Matlab cannot display all the elements on one line, it simply indicates the column-number per line linspace(), cont.

30 The third argument indicates the ________________________. When Matlab cannot display all the elements on one line, it simply indicates the column-number per line linspace(), cont.

31 ?????? %no third argument Omit the third argument uses a default of _______ data points! 2.3. linspace(), cont.

Ex5. Plotting graphs Suppose a function that relates each x to its y-coordinate is known: y = f(x) = x 2.  Plot y vs. x. 32

Ex5. Plotting graphs Suppose a function that relates each x to its y-coordinate is known: y = f(x) = x 2.  Plot y vs. x. In this case, it is tedious work to hard-code each x and y array. Are 4 data-points sufficient, like in example 3? 33 x y x y

Ex5. Plotting f(x) = x^2, cont. Remember: which built-in function influences the number of data-points in an array?____________________ In this case: %array x of 20 data points %calculate array of y’s. %plot command And the result is… 34

Ex5. Plotting f(x) = x^2, cont. Remember: which built-in function influences the number of data-points in an array?____________________ In this case: %array x of 20 data points x = linspace(-10,10,20); %calculate array of y’s. y = x.^2; %(The dot will be explained next time…) %plot command plot(x,y) And the result is… 35

Ex5. Plotting f(x) = x^2, cont. 36 Does this represent f(x) = x 2 ? Yes Or No Yes, but it took 20 points!!

Ex5. Plotting f(x) = x^2, cont. The use of linspace() in this example is crucial! Why do all 20 data point need to be linearly spaced? What would happen otherwise? 37 Still 20 points!!.. but the first 19 are before -5,.. and the last one is 10. Not f(x) = x 2..

3. Creating Matrices Simply a combination of all symbols introduced with vectors! Square brackets [ ] Spaces or commas,, Semi-colons ; Apostrophes ’ 38

3.1. Matrices: hard-coding 39 Use semi-colons to create new rows. ONLY rectangular matrices:  The number of columns MUST match for each row, and vice-versa.

40 Use semi-colons to create new rows. ONLY rectangular matrices:  The number of columns MUST match for each row, and vice- versa. Use previous matrices to actually create new matrices. This example transposes the matrix variable a Reusing Previous matrices

41 Use semi-colons to create new rows. ONLY rectangular matrices:  The number of columns MUST match for each row, and vice- versa. You can use previous matrices to actually create new matrices. This example transposes the variable a. Combine any previous methods, AS LONG AS the matrix remains rectangular Using Colons

3.4. “Concatenating” 42 Use semi-colons to create new rows. ONLY rectangular matrices:  The number of columns MUST match for each row, and vice- versa. You can use previous matrices to actually create new matrices. This example transposes the variable a. You can combine any previous methods, AS LONG AS the matrix remains rectangular. Finally, create arrays by combining previous variables! This is called CONCATENATING.

43 Use semi-colons to create new rows. ONLY rectangular matrices:  The number of columns MUST match for each row, and vice- versa. You can use previous matrices to actually create new matrices. This example transposes the variable a. You can combine any previous methods, AS LONG AS the matrix remains rectangular. When the array becomes too big, the numbers no longer display Using the command window

Ex4. Conversion table, end! % create celsius data points celsius = 0:10:100; %0 to 100 by +10 increment % calculate Fahrenheit fahrenheit = celsius * 9/5 + 32; % show table [celsius’ fahrenheit’] 44

Ex6. Sling Thermometer 45 A method to read relative-humidity.

Ex7. Images 46 Each row and column have a pixel value stored.

Wrapping Up Know by heart each way to create a row/column vector. Hard-code each data point Separate each data-point by comma or spaces for row vector Separate each data-point by semicolon for a column vector Shortcut when there is an addition pattern (colon) Shortcut when a specific amount of data points are linearly spaced ( linspace() ) 47

Wrapping Up Know by heart each way to create a row/column vector. Hard-code each data point Separate each data-point by comma or spaces for row vector Separate each data-point by semicolon for a column vector Shortcut when there is an addition pattern (colon) Shortcut when a specific amount of data points are linearly spaced ( linspace() ) Realize that creating matrices only requires combining all of the above, while respecting one crucial rule: A matrix must remain rectangular at all times (i.e. no holes within the matrix) 48

Wrapping Up Know by heart each way to create a row/column vector. Hard-code each data point Separate each data-point by comma or spaces for row vector Separate each data-point by semicolon for a column vector Shortcut when there is an addition pattern (colon) Shortcut when a specific amount of data points are linearly spaced ( linspace() ) Realize that creating matrices only requires combining all of the above, while respecting one crucial rule: A matrix must remain rectangular at all times (i.e. no holes within the matrix) What does the apostrophe do? 49

Wrapping Up Know by heart each way to create a row/column vector. Hard-code each data point Separate each data-point by comma or spaces for row vector Separate each data-point by semicolon for a column vector Shortcut when there is an addition pattern (colon) Shortcut when a specific amount of data points are linearly spaced ( linspace() ) Realize that creating matrices only requires combining all of the above, while respecting one crucial rule: A matrix must remain rectangular at all times (i.e. no holes within the matrix) What does the apostrophe do? Restate some examples of vector operations and matrix operations. 50