1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)

Slides:



Advertisements
Similar presentations
Introduction to Matlab
Advertisements

Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
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.
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.
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.
Introduction to MATLAB MECH 300H Spring Starting of MATLAB.
EGR 106 – Week 3 – More on Arrays Brief review of last week Additional ideas: – Special arrays – Changing an array – Some array operators – Character arrays.
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.
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.
Lecture 13: M/O/F/ for Engineering Applications - Part 1 BJ Furman 26NOV2012.
Chapter 10 Review: Matrix Algebra
Creating scalars, vectors, matrices Ex1 & 2. Dot Product & Cross Product Ex3. Plotting Graphs Ex4. Conversion Table Ex5. Plotting functions Finishing Ex4.
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
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.
Nonparametric Econometrics1 Intro to Matlab for Data Analysis and Statistical Modeling.
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,
MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU.
1 Chapter 1 MATLAB Primer This introductory chapter is relatively short and has as its main objective the introduction of MATLAB ® to the reader. This.
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,
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
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.
Introduction to Engineering MATLAB – 1 Introduction to MATLAB Agenda Introduction Arithmetic Operations MATLAB Windows Command Window Defining Variables.
MATLAB An Introduction to MATLAB (Matrix Laboratory) 1.
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.
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.
Matlab 14.html Cost: $100 Available in labs on Windows and Unix machines.
ES 240: Scientific and Engineering Computation. Chapter 2 Chapter 2: MATLAB Fundamentals Uchechukwu Ofoegbu Temple University.
Working with Arrays in MATLAB
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
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.
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.
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
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
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.
1 Lecture 3 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Matlab for Engineers Matlab Environment Chapter 2.
CMPS 1371 Introduction to Computing for Engineers VECTORS.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
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.
Lecture 12: M/O/F/ for Engineering Applications B Burlingame 27 April 2016.
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.
LAB 2 Vectors and Matrices Dr.Abdel Fattah FARES.
ECE 1304 Introduction to Electrical and Computer Engineering
EEE 244 Numerical Methods In Electrical Engineering
Part 1 Chapter 2 MATLAB Fundamentals
Part 1 Chapter 2 MATLAB Fundamentals
Presentation transcript:

1 Faculty Name Prof. A. A. Saati

2

MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)  CHAPTER 3: Programming with MATLAB (p.48)

THE MATLAB ENVIRONMENT 4 1.MATLAB uses three primary windows:  Command window. Used to enter commands and data.  Graphics window. Used to display plots and graphs.  Edit window. Used to create and edit M-files.

THE MATLAB ENVIRONMENT 5 1.MATLAB uses three primary windows:  Command window. Used to enter commands and data.  Graphics window. Used to display plots and graphs. o o After starting MATLAB, the command window will open with the command prompt being displayed >> o The calculator mode of MATLAB >> MATLAB will display the result1 ans = 39 >> ans + 11 with the result ans = 50

THE MATLAB ENVIRONMENT 6  ASSIGNMENT o Scalars >> a = 4 Note how the assignment echo prints to confirm what you have done: a = 4 >> x = 2+i*4 x = i There are several predefined variables, for example, pi. >> pi ans = Notice how MATLAB displays four decimal places. If you desire additional precision, enter the following: >> format long Now when pi is entered the result is displayed to 15 significant figures: >> pi ans = To return to the four decimal version, type >> format short

THE MATLAB ENVIRONMENT 7  ASSIGNMENT o Arrays, Vectors and Matrices An array is a collection of values that are represented by a single variable name. One-dimensional arrays are called vectors and two-dimensional arrays are called matrices. For example, a row vector can be assigned as follows : >> a = [ ] a =

THE MATLAB ENVIRONMENT 8  ASSIGNMENT o Arrays, Vectors and Matrices A column vector can be entered in several ways. Try them. >> b = [2;4;6;8;10] or >> b = [ ] or, by transposing a row vector with the ' operator, >> b = [ ]' The result in all three cases will be b =

THE MATLAB ENVIRONMENT 9  ASSIGNMENT o A matrix of values can be assigned as follows: >> A = [1 2 3; 4 5 6; 7 8 9] A = In addition, the Enter key (carriage return) can be used to separate the rows. For example: >> A = [ ] Finally, we could construct the same matrix by the vectors representing each column: >> A = [[1 4 7]' [2 5 8]' [3 6 9]']

THE MATLAB ENVIRONMENT 10  ASSIGNMENT o At any point in a session, a list of all current variables can be obtained by entering the who command: >> who Your variables are: A a ans b x o or, with more detail, enter the whos command: >> whos Name Size Bytes Class A 3x3 72 double array a 1x5 40 double array ans 1x1 8 double array b 5x1 40 double array x 1x1 16 double array (complex) Grand total is 21 elements using 176 bytes

THE MATLAB ENVIRONMENT 11  ASSIGNMENT o To access an individual element of an array. For example, the fourth element of the column vector b can be displayed as >> b(4) ans = 8 o For an array, A(m,n) selects the element in mth row and the nth column. For example, >> A(2,3) ans = 6 o To create a 2 × 3 matrix of zeros: >> E = zeros(2,3) E = o Similarly, the ones function can be used to create a row vector of ones: >> u = ones(1,3) u = 1 1 1

THE MATLAB ENVIRONMENT 12  The Colon Operator o The colon operator is a powerful tool for creating and manipulating arrays. If a colon is used to separate two numbers, MATLAB generates the numbers between them using an increment of one: >> t = 1:5 t = If colons are used to separate three numbers, MATLAB generates the numbers between the first and third numbers using an increment equal to the second number: >> t = 1:0.5:3 t = o Note that negative increments can also be used >> t = 10:-1:5 t =

THE MATLAB ENVIRONMENT 13  The Colon Operator o The colon can also be used as a wildcard to select the individual rows and columns of a matrix o For example, the second row of the matrix A can be selected as in >> A(2,:) ans = o We can also use the colon notation to selectively extract a series of elements from within an array. o For example, based on the previous definition of the vector t: >> t(2:4) ans = o Thus, the second through the fourth elements are returned.

THE MATLAB ENVIRONMENT 14  The linspace and logspace Functions o The linspace and logspace functions provide other handy tools to generate vectors of spaced points. o The linspace function generates a row vector of equally spaced points. It has the form linspace(x1, x2, n) o which generates n points between x1 and x2 o For example >> linspace(0,1,6) ans = o If the n is omitted, the function automatically generates 100 points. o o The logspace function generates a row vector that is logarithmically equally spaced. It has the form logspace(x1, x2, n) o which generates n logarithmically equally spaced points between decades 10x1 and 10x2. >> logspace(-1,2,4) ans = o If n is omitted, it automatically generates 50 points.

THE MATLAB ENVIRONMENT 15  Character Strings o Aside from numbers, alphanumeric information or character strings can be represented by enclosing the strings within single quotation marks. o For example, >> f = 'Miles '; >> s = 'Davis'; o Each character in a string is one element in an array. Thus, we can concatenate (i.e., paste together) strings as in >> x = [f s] x = Miles Davis o Note that very long lines can be continued by placing an ellipsis (three consecutive periods) at the end of the line to be continued. For example, a row vector could be entered as >> a = [ ] a =

MATHEMATICAL OPERATIONS 16 o Operations with scalar quantities are handled in a straightforward manner, similar to other computer languages. o The common operators, in order of priority, are ^ Exponentiation – Negation * / Multiplication and division \ Left division2 + – Addition and subtraction o o These operators will work in calculator fashion. >> 2*pi ans = o Also, scalar real variables can be included: >> y = pi/4; >> y ^ 2.45 ans =

MATHEMATICAL OPERATIONS 17 o Results of calculations can be assigned to a variable. o As with other computer calculation, the priority order can be take priority over with parentheses. For example: >> y = -4 ^ 2 y = -16 o >> y = (-4) ^ 2 y = 16 o Calculations can also involve complex quantities. o examples that use the values of x (2 + 4i) and y (16) defined previously: >> 3 * x ans = i >> x ^ 2 ans = i

MATHEMATICAL OPERATIONS 18 >> x + y ans = i o o The real power of MATLAB is illustrated in its ability to carry out vector- matrix calculations. For example: o The inner product of two vectors (dot product) can be calculated using the * operator, Let : a = [ ] & b = [ ]' >> a * b ans = 110 o and likewise, the outer product >> b * a ans =

MATHEMATICAL OPERATIONS 19 Let : A =, a = [1 2 3] & b = [4 5 6]'; o Now, try >> a * A ans = or >> A * b ans = o Matrices cannot be multiplied if the inner dimensions are unequal o Try >> A * a MATLAB automatically displays the error message: ??? Error using ==> mtimes Inner matrix dimensions must agree.

MATHEMATICAL OPERATIONS 20 Let : A =, a = [1 2 3] & b = [4 5 6]'; o Matrix-matrix multiplication is carried out in likewise fashion: >> A * A or >> A^2 ans = o Mixed operations with scalars are also possible: >> A/pi ans =

MATHEMATICAL OPERATIONS 21 Let : A =, a = [1 2 3] & b = [4 5 6]'; o What if you want to square each element of A? That can be done with >> A. ^A ans = The MATLAB manual calls these array operations. They are also often referred to as element-by-element operations

USE OF BUILT-IN FUNCTIONS 22 o MATLAB and its Toolboxes have a rich collection of built-in functions. o You can use online help to find out more about them. o For example, if you want to learn about the log function, type in o >> help log o LOG Natural logarithm. LOG(X) is the natural logarithm of the elements of X. Complex results are produced if X is not positive. See also LOG2, LOG10, EXP, LOGM o For a list of all the elementary functions, type >> help elfun o One of their important properties of MATLAB’s built-in functions is that they will operate directly on vector and matrix quantities. For example, try >> log(A) ans = o and you will see that the natural logarithm function is applied in array style, element by element, to the matrix A.

23 THE END

24 THE END Part 1 - Introduction to Computational methods