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.

Slides:



Advertisements
Similar presentations
Lecture 5.
Advertisements

Introduction to M ATLAB Programming Ian Brooks Institute for Climate & Atmospheric Science School of Earth & Environment
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 10.
Lecture 4.
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
Introduction to FX Equation 4. The Basic Idea FX Equation is DIFFERENT. Most equation editors use a point and click interface that has you searching for.
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.
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/22/2003.
Lecture 2 MATLAB fundamentals Variables, Naming Rules, Arrays (numbers, scalars, vectors, matrices), Arithmetical Operations, Defining and manipulating.
Introduction to MATLAB
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.
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
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.
Creating scalars, vectors, matrices Ex1 & 2. Dot Product & Cross Product Ex3. Plotting Graphs Ex4. Conversion Table Ex5. Plotting functions Finishing Ex4.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
MATLAB Lecture One Monday 4 July Matlab Melvyn Sim Department of Decision Sciences NUS Business School
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 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,
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
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.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
Introduction to Matlab Module #2 Page 1 Introduction to Matlab Module #2 – Arrays Topics 1.Numeric arrays (creation, addressing, sizes) 2.Element-by-Element.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
1 Week 1: Variables, assignment, expressions READING: 1.2 – 1.4.
INTRODUCTION TO MATLAB MATLAB is a software package for computation in engineering, science, and applied mathemat-ics. It offers a powerful programming.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
A L I MAM M OHAMMAD B IN S AUD I SLAMIC U NIVERSITY C OLLEGE OF S CIENCES D EPARTMENT OF M ATHEMATICS MATLAB 251 : MATH SOFTWARE Introduction to MATLAB.
>> x = [ ]; y = 2*x y = Arrays x and y are one dimensional arrays called vectors. In MATLAB all variables are arrays. They allow functions.
Structured Programming I – Relational & Logical Operators Objectives: By the end of this class you should be able to: Change graph interactively in EXCEL.
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 =
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
The Hong Kong Polytechnic University Industrial Centre MatLAB Lesson 1 : Overview & Environment Edward Cheung Room W311g.
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.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 1: Variables & Arrays Wednesday 03 Sept 2014 EGR 115 Introduction to Computing for Engineers.
BRIAN D. HAHN AND DANIEL T. VALENTINE THIRD EDITION Essential MATLAB® for Engineers and Scientists.
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.
BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology Taxila.
An Introduction to Programming in Matlab Emily Blumenthal
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
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
Lecture: MATLAB Chapter 1 Introduction
MATLAB DENC 2533 ECADD LAB 9.
Use of Mathematics using Technology (Maltlab)
Lecture 2 Introduction to MATLAB
Communication and Coding Theory Lab(CS491)
Presentation transcript:

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 differ from the use of the colon : operator? Readings: Matlab by Pratap Chapter 3

3 1) engineering visualization and computation software 2-D contour, histogram, line, mesh, polar, polygon and scatter plots. 3-D line, mesh, polygon, scatter and wire frame plots. 2) The “interactive environment” is user friendly. 3)MATLAB provides its own high-level language in which users can extend the capabilities of MATLAB. C-like programming language Many user defined functions

1-4 MATLAB is interactive, if you type (without ; ) >> The system responds with ans = 5 “ans” is a built-in variable that contains the results of the last evaluated expression that has not been assigned to another variable. e.g. if we type >> 3 * 3 ans = 9

1-5 To suppress the screen output use a semicolon: >> 5 ^ 2; (“ ^ ” is the power operator, 5 raised to the second power in this example) >> ( no response from matlab) To examine the current value of ans type >> ans ans = 25

1-6 All variables are created as array variables. For example, >> x = 1.5; (this is called an “assignment statement”) creates a (1 x 1) array of type real and assigns the value 1.5 to x. Variables only change values when you assign values to them using an assignment statement. To see the value of x type, >> x x = Variable names must begin with a character and are case sensitive. 1.5 x RAM

1-7 The variable to be “assigned” a value must be on the left hand side of the assignment statement… >> 1.5 = x; (illegal “assignment statement”) The above is illegal because “1.5” does not specify a legal address in memory. An assignment statement is not a “math” equation. For example, the following sequence is legal in Matlab: >> x = 2.0; >> x = x x =

1-8 The current environment for our computing session is called the workspace. We can have many variables and functions in our workspace. To see what variables we have, type >> who ans x For this session (up to now) the workspace contains two variables ans and x. To see the size (number of rows and columns) of these variables, type >> whos Name SizeBytesClass(Both x and ans are 1 x 1 arrays) ans 1x1 8double (we call these scalars) x1x1 8double (double refers to double precision)

9 (see p. 12 in Pratap for a list of these Matlab commands) … (extend a command that doesn’t fit on one line) >> save lab3 (saves all the workspace variables to the file lab3.mat) >> load lab3 (loads the lab3.mat file from the Unix pwd) >> save (uses default file matlab.mat) >> load (uses the default file matlab.m at from the Unix pwd)

1-10 (see p. 12 in Pratap for a list of these Matlab commands) >> clc % clears the command window >> clf % clears the figure window >> clear var1 var2 % clears only the variables var1 var2 >> clear % clears(deletes) all variables in the workspace >> exit % exit Matlab >> quit % same as exit >> what % lists Matlab files

1-11 format options (controls how numeric output is displayed) (see p. 9 in Pratap for a list of these Matlab commands) Examples-- two of the options are shown below: >> x = x = >> format short >> x x = >> format long e >> x x = e+01

12 In Matlab (for CS101) all data will be stored in arrays. An array can represent a: vector - size 1 x n (row vector with 1 row and n columns) or n x 1 (column vector with n rows and 1 column) matrix - any size m x n ( a table of m rows and n columns). Conventions Two arrays are defined to be equal if they are of the same size and at each position, they have the same value. The values in an array are called components or elements.

1-13 Some examples of vector quantities that occur frequently in science and engineering problems are velocity acceleration force electric, magnetic, gravitational fields surface normal For example, the three-dimensional components of a force vector can be represented in Cartesian coordinates as P = (x, y) The xy coordinates in the plane correspond to a two- dimensional "vector" F = (Fx, Fy, Fz)

1-14 We can represent a vector either as a row vector or as a column vector, depending on the application. E.g.,

1-15 To create vector arrays in MATLAB type the following: >> F1 = [ ]; >> F2 = [-1.75, 2.75, 1.0e-1]; >> F3 = [1 2 ]; >> whos F1 F2 F3 Name SizeBytesClass F11x3 24double F21x3 24double F31x2 16double F1 and F2 are 1 row x 3 column arrays and F3 is a 1 row x 2 column array. To display their values type the variable name: >> F1 F1 = (The use of the “, ” operator is optional)

1-16 To create column-vector arrays in MATLAB either use the semi-colon operator ; or use the transpose operator ‘ >> F1 = [1 ; 2.5; 3.5]; ( ; means... append to next row) >> F2 = [-1.75, 2.75, 1.0e-1] ‘ ; (transpose changes row vector to column vector and vice-versa ) >> F3 = [ ]; (empty vector) >> whos F1 F2 F3 Name SizeBytesClass F13x1 24double F23x1 24double F30x0 0double >> F1 F1 =

1-17 The “ : ” (colon) operator is important in construction of arrays >> x = 1:100; (creates a 1x100 row vector with values 1,2,3,4, … 100) >> y = (-1 : 0.1 : 1)’; (creates a column vector with starting value -1 and increments by 0.1 until 1 is reached but not exceeded) >> z = 0 : 0.3 : 1 z = >> z = 5 : -1 : 2 z = 5432

1-18 Use (parenthesis) to select a subset of the elements of an array. >> x = [ ]; >> y = [3; 4; 5]; >> z = x(2) (note the use of parenthesis and not the brackets) z = 9(subscripting x does not change x) >> z = x(1:3) (note the use the colon operator) z = 1098 >> x = x(2:3) (now x has changed) x = 98 >> z = y(1:2) z = 3 4

1-19 Use the end function to obtain the last element in a vector. Example: >> x = [ ]; >> y = [3; 4; 5]; >> z = x(end) z = 7 >> z = y(2:end) z = 4 5

1-20 Use subscripting to change the value of a vecor. Example: >> x = [ ]; >> y = [3; 4; 5]; >> x([2, 3]) = 5 x = >> y(2:end) = [ 6 7] % y(2:end) = [6 ; 7] works too y = 3 6 7

1-21 The built-in Matlab function linspace (see p. 72)works in a similar manner to the colon operator “ : ”. linspace(a,b,N) creates a row vector of N equally spaced values starting at a and ending at b. This is equivalent to a : (b-a)/(N-1) : b Example: Create a row vector named vec1 of 4 elements starting at -1 and ending at +1. >> vec1 = linspace(-1,1,4) vec1 =

1-22 Example: Create a row vector named vec2 of 4 elements each equal to 7. >> vec2 = linspace(7,7,4) vec2 = 7777 Example: Create a row vector named vec3 with the values 5,4,3,2. >> vec3 = linspace(5,2,4) vec3 = 5432

1-23 (dot form) Rules for the valid operations(see p 57,58). If A and B are vectors then it is not always true that >>A op B is defined when op is one of the operations in the table above. A and B are called operands. The size of an vector is its number of rows and columns. When multiple operators are used in an expression, use the rules of precedence. *, /, \, ^ have “special” meaning as we will consider... add sub mult right div left div power + - * / \ ^.*./.\.^

1-24 >> A = [2 3 4] ; >> B = 3; >> A + B ans= 567 A and B must be of the same size or a scalar. >> B = [1 2 3] ; >> A + B ans= 357

1-25 F 1 =(Fx 1, Fy 1 ) F = F 1 + F 2 = (Fx 1 + Fx 2, Fy 1 + Fy 2 ) In Matlab: F = resultant of two forces applied to an object. >> F1 = [1, -1.5]; >> F2 = [-1.75, 1.0e-1] ; >> F = F1 + F2 F = F 2 =(Fx 2, Fy 2 )

1-26 >> A = [2 3 4] ; >> B = 3; >> A - B ans= -101 A and B must be of the same size or a scalar. >> B = [1 2 3] ; >> A - B ans= 111

1-27 In Cartesian coordinates, we can express the dot or scalar product of two vectors as a matrix multiplication: Physical Example: Work done by a force F acting through a displacement s F s >> s = [1, 1, 1] ‘ ; >> F1 = [ ]; >> F1 * s (dot or scalar product) ans = 7 surface

1-28 >> A = [2 3 4] ; >> B = [1 ; 2 ; 3] ; >> A * B ans= 20 In order for the scalar product of vectors A * B to be defined, the number of columns in the row vector A must equal the number of rows in the column vector B.

1-29 >> A = [2 3 4] ; >> B = [1 2 3] ; >> A.* B ans= 2612 Note: the result is the product of the individual elements of the vectors. The size of A and B must be the same or either could be a scalar. For the other operators in the table on slide , try to determine what the operator does and the sizes for which A op B is valid. We will consider the “ \ “ operator in the future. (see section in book)

To obtain help in using Matlab make sure the Help window is open. To do this, click “Help” then “Product Help”

If you know the name of a Matlab function or command, click on the Search box and type in the name of the function.

If you want to obtain a list of functions by category, first, click “By Category”,