Introduction to MATLAB 7 for Engineers

Slides:



Advertisements
Similar presentations
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
Advertisements

1 Chapter 2 Basic Elements of Fortran Programming.
Welcome to EGR 106 Foundations of Engineering II Course information Today’s specific topics: – Computation and algorithms – M ATLAB Basics Demonstrations.
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 7
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.
Introduction to MATLAB
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.
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
BRIAN D. HAHN AND DANIEL T. VALENTINE THIRD EDITION Essential MATLAB® for Engineers and Scientists.
EGR 106 Intro to Engineering II Engineering problem solving using MATLAB Text: Amos Gilat, MATLAB An Introduction with Applications, Wiley 2004 ISBN
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.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (2): MATLAB Environment (Chapter 1)
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
MATLAB for Engineers Chapter 1 An Overview Of MATLAB.
Structured Computer Programming EE 201 Introduction to MATLAB 7 for Engineers بسم الله الرحمن الرحيم King Abdulaziz University College of Engineering Dept.
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.
ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB is a powerful program for numerical computations, plotting and programming.
Introduction to MATLAB ENGR 1181 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Introduction to Engineering MATLAB – 1 Introduction to MATLAB Agenda Introduction Arithmetic Operations MATLAB Windows Command Window Defining Variables.
Chapter 1 An Overview Of MATLAB. The default MATLAB Desktop. Figure 1.1–1 1-2 More? See pages 6-7.
Copyright © The McGraw-Hill Companies, Inc. Introduction to MATLAB for Engineers, Third Edition William J. Palm III Chapter 1 An Overview of MATLAB.
Introduction to Matlab Module #1 Page 1 Introduction to Matlab Module #1 – Getting Started with Matlab Topics 1.Starting a session 2.Entering commands.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
A Brief introduction to MatLAB ($50 - $99 for students)
Chapter 1 An Overview Of MATLAB. The default MATLAB Desktop. Figure 1.1–1 1-2 More? See pages 6-7.
Introduction to Matlab Module #2 Page 1 Introduction to Matlab Module #2 – Arrays Topics 1.Numeric arrays (creation, addressing, sizes) 2.Element-by-Element.
26 - 3/20/2000AME 150L1 M ATLAB ® /20/2000AME 150L2 M ATLAB ® vs. Fortran Fortran Positives –First Compiler –Legacy Codes –Efficient Numerically.
Introduction to Engineering MATLAB – 2 Introduction to MATLAB - 2 Agenda Defining Variables MATLAB Windows.
Winter Semester 2014/2015 College of Engineering.
Introduction to MATLAB ENGR 1181 MATLAB 1. Opening MATLAB  Students, please open MATLAB now.  CLICK on the shortcut icon → Alternatively, select… start/All.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
1 Lecture 1 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.
ENG 1181 First-Year Engineering Program College of Engineering Engineering Education Innovation Center First-Year Engineering Program MAT - Introduction.
Fundamentals of Programming 20-ENFD-112 Sections 001 to 007 Instructor: Prof. Dieter Schmidt Lecture: Monday, Wednesday 3:00-3:50 Web page
Today we will learn MATLAB Click Start  All programm  Class Software  Matlab This command window will be seen with a prompt sign >> Any command can.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology Taxila.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
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.
Copyright © The McGraw-Hill Companies, Inc. This work is only for non-profit use by instructors in courses for which this textbook has been adopted.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
1 MATLAB 입문 An Overview of MATLAB. An Overview of MATLAB 2 Starting Matlab The default MATLAB Desktop.
MATLAB The name of MATLAB stands for matrix laboratory. Starting a MATLAB Session -On Microsoft® Windows® platforms, start the MATLAB program by double-clicking.
מטלב וניתוח נתונים ממערכות עצביות היכרות עם MATLAB
ECE 1304 Introduction to Electrical and Computer Engineering
Arithmetic Operations
ECE 1304 Introduction to Electrical and Computer Engineering
Introduction to MATLAB for Engineers, Third Edition
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Introduction to MATLAB 7
Simulation And Modelling
Experiment No. (1) - an introduction to MATLAB
CS 111 Introduction to Computing in Engineering and Science
MatLab Program Used to Calculate Interactive
Electrical and Computer Engineering Department SUNY – New Paltz
Presentation transcript:

Introduction to MATLAB 7 for Engineers بسم الله الرحمن الرحيم King Abdulaziz University College of Engineering Dept of Electrical & Computer Engineering Structured Computer Programming EE 201 Introduction to MATLAB 7 for Engineers

Course Syllabus Instructor: Eng. Ghassan R. Alnwaimi   Instructor: Eng. Ghassan R. Alnwaimi Web Site: http://engg.kau.edu.sa/~galnwaimi Office Room: 317B, Tel Ext. 68156. Office Hours: Saturday to Wednesday : 10-12 p.m. Textbook: William J. Palm III, Introduction to MatLab 7 for Engineers, McGraw-Hill International Edition, 2005 King Abdulaziz University EE 201 Eng. Ghassan R. Alnwaimi

The Default MATLAB Desktop Chapter 1 The Default MATLAB Desktop King Abdulaziz University EE 201 Eng. Ghassan R. Alnwaimi

Entering Commands & Expressions MATLAB retains your previous keystrokes. Use the up-arrow key to scroll back through the commands. Press the key once to see the previous entry, and so on. Use the down-arrow key to scroll forward. Edit a line using the left-and right-arrow keys the Back space key, and the Delete key. Press the Enter key to execute the command. King Abdulaziz University EE 201 Eng. Ghassan R. Alnwaimi

Example: >> 8/10 ans= 0.8000 >> 5*ans 4 >> r=8/10 King Abdulaziz University EE 201 Eng. Ghassan R. Alnwaimi

Scalar Arithmetic Operations Symbol Operation MATLAB form ^ exponentiation: a^b * multiplication: ab a*b / right division: a/b a/b \ left division: b/a a\b + addition: a + b a + b - subtraction: a –b a -b King Abdulaziz University EE 201 Eng. Ghassan R. Alnwaimi

Order of Precedence First  Parentheses, evaluated starting with the innermost pair. Second  Exponentiation, evaluated from left to right. Third  Multiplication and division with equal precedence, evaluated from left to right. Fourth  Addition and subtraction with equal precedence, evaluated from left to right. King Abdulaziz University EE 201 Eng. Ghassan R. Alnwaimi

Examples >> 8 + 3*5 ans= 23 >> 8 + (3*5) >>(8 + 3)*5 55 >>4^2-12- 8/4*2 >>4^2-12- 8/(4*2) 3 King Abdulaziz University EE 201 Eng. Ghassan R. Alnwaimi

Examples >> 3*4^2 + 5 ans= 53 >>(3*4)^2 + 5 149 >>27^(1/3) + 32^(0.2) 5 >>27^(1/3) + 32^0.2 >>27^1/3 + 32^0.2 11 King Abdulaziz University EE 201 Eng. Ghassan R. Alnwaimi

The Assignment Operator = Typing x = 3 assigns the value 3 to the variable x. We can then type x = x + 2 This assigns the value 3 + 2 = 5 to x. But in algebra this implies that 0 = 2. In algebra we can write x + 2 = 20, but in MATLAB but in MATLAB we cannot. In MATLAB the left side of the = operator must be a single variable. The right side must be a computable value. King Abdulaziz University EE 201 Eng. Ghassan R. Alnwaimi

Commands for managing the work session Command  Description clc Clears the Command window. clear Removes all variables from memory. clear v1 v2 Removes the variables v1and v2from memory. exist (‘var’) Determines if a file or variable exists having the name ‘var’. Quit Stops MATLAB. King Abdulaziz University EE 201 Eng. Ghassan R. Alnwaimi

Commands for managing the work session Who Lists the variables currently in memory. Whos Lists the current variables and sizes, and indicates if they have imaginary parts. : Colon; generates an array having regularly spaced elements. , Comma; separates elements of an array. ; Semicolon; suppresses screen printing; also denotes a new row in an array. .. Ellipsis; continues a line. King Abdulaziz University EE 201 Eng. Ghassan R. Alnwaimi

Special Variables and Constants Command Description Ans Temporary variable containing the most recent answer. Eps Specifies the accuracy of floating point precision. i,j The imaginary unit √−1. Inf Infinity. NaN Indicates an undefined numerical result. Pi The number π. King Abdulaziz University EE 201 Eng. Ghassan R. Alnwaimi

Complex Number Operations The number c1= 1 –2i is entered as follows: c1 = 1-2i An asterisk is not needed between i or j and a number, although it is required with a variable, such as c2 = 5 - i*c1 Be careful. The expressions y = 7/2*i and x = 7/2i give two different results: y = (7/2)i = 3.5i and x = 7/(2i) = –3.5i. King Abdulaziz University EE 201 Eng. Ghassan R. Alnwaimi

Numeric Display Formats Command Description and Example format short Four decimal digits (the default); 13.6745. format long 16 digits; 17.27484029463547. format short e Five digits (four decimals) plus exponent; 6.3792e+03. format long e 16 digits (15 decimals) plus exponent; 6.379243784781294e–04. King Abdulaziz University EE 201 Eng. Ghassan R. Alnwaimi

Arrays The numbers 0, 0.1, 0.2, …, 10 can be assigned to the variable u by typing u = [0:0.1:10]. To compute w= 5 sin u for u= 0, 0.1, 0.2, …, 10, the session is; >>u = [0:0.1:10]; >>w = 5*sin (u); The single line, w = 5*sin (u), computed the formula w= 5 sin u101 times. King Abdulaziz University EE 201 Eng. Ghassan R. Alnwaimi

Array Index >>u(7) ans= 0.6000 >>w(7) 2.8232 Use the length function to determine how many values are in an array. >>m = length (w) m = 101 King Abdulaziz University EE 201 Eng. Ghassan R. Alnwaimi

Polynomial Roots To find the roots of x3–7x2+ 40x–34 = 0, the session is >>a = [1,-7,40,-34]; >>roots(a) ans= 3.0000 + 5.000i 3.0000 -5.000i 1.0000 The roots are x= 1 and x= 3 ± 5i. King Abdulaziz University EE 201 Eng. Ghassan R. Alnwaimi

Some Commonly Used Mathematical Function MATLAB syntax1 e exp(x) √x sqrt(x) lnx log(x) log10x log10(x) cosx cos(x) Sin x sin(x) tan x tan(x) cos x acos(x) sin x asin(x) tan x atan(x) x -1 -1 -1 King Abdulaziz University EE 201 Eng. Ghassan R. Alnwaimi

When you type problem1 MATLAB first checks to see if problem1 is a variable and if so, displays its value. 2. If not, MATLAB then checks to see if problem1 is one of its own commands, and executes it if it is. 3. If not, MATLAB then looks in the current directory for a file named problem1.m and executes problem1if it finds it. 4. If not, MATLAB then searches the directories in its search path, in order, for problem1.m and then executes it if found. King Abdulaziz University EE 201 Eng. Ghassan R. Alnwaimi

System, Directory, and File Commands Command Description addpath dirname Adds the directory dirnameto the search path. cd dirname Changes the current directory to dirname. dir Lists all files in the current directory. dir dirname Lists all the files in the directory dirname. Path Displays the MATLAB search path. Pathtool Starts the Set Path tool. King Abdulaziz University EE 201 Eng. Ghassan R. Alnwaimi

System, Directory, and File Commands Command Description Pwd Displays the current directory. Rmpath dirname Removes the directory dirnamefrom the search path. What Lists the MATLAB-specificfiles found in the current working directory. Most data files and other non-MATLAB files are not listed. Use dir to get a list of all files. what dirname Lists the MATLAB-specific files in directory dirname. King Abdulaziz University EE 201 Eng. Ghassan R. Alnwaimi