10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.

Slides:



Advertisements
Similar presentations
Introduction to Matlab
Advertisements

Introduction to Applications & Basic Features. What is MATLAB®? MATLAB® /Simulink® is a powerful software tool for: Performing mathematical computations.
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
MATLAB ME1107 Y Yan Reference: MATLAB for Engineers by Holly Moore (Pearson Prentice Hall)
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
Introduction to MATLAB 3 November Instructor: Andy Newman Office Hours: Stop by room 306 (main building) whenever
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 =
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.
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
Lecture 1: Introduction Lecture series based on the text: Essential MATLAB for Engineers and Scientists By Hahn & Valentine
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.
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.
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.
Recap Graphic Window Edit Window Start Button Matrices in MATLAB Scalar Operations Order of Operations Array Operations Matrix Addition Matrix Multiplication.
1 Functions 1 Parameter, 1 Return-Value 1. The problem 2. Recall the layout 3. Create the definition 4. "Flow" of data 5. Testing 6. Projects 1 and 2.
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.
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.
MATLAB An Introduction to MATLAB (Matrix Laboratory) 1.
Introduction to Engineering MATLAB – 6 Script Files - 1 Agenda Script files.
INTRODUCTION TO MATLAB LAB# 01
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
Chapter 1: Getting Started with MATLAB MATLAB for Scientist and Engineers Using Symbolic Toolbox.
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
A Brief introduction to MatLAB ($50 - $99 for students)
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
Introduction to Engineering MATLAB – 2 Introduction to MATLAB - 2 Agenda Defining Variables MATLAB Windows.
CMPS 1371 Introduction to Computing for Engineers MatLab.
Advanced Topics- Functions Introduction to MATLAB 7 Engineering 161.
MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
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.
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 &
1 DKT 211 Basic Communication Engineering LAB # 1A : (Lecture 1) Introduction to Matlab  Basic Features  Scientific features  Array Operations  Script.
Chapter 6 Review: User Defined Functions Introduction to MATLAB 7 Engineering 161.
Introduction to MATLAB 7 MATLAB Programming for Engineer Hassan Migdadi Spring 2013.
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”
1 Lecture 1 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
EGR 115 Introduction to Computing for Engineers Introduction to MATLAB Friday 29 August 2014 EGR 115 Introduction to Computing for Engineers.
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.
ENG 1181 First-Year Engineering Program College of Engineering Engineering Education Innovation Center First-Year Engineering Program MAT - Introduction.
Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2012.
The Hong Kong Polytechnic University Industrial Centre MatLAB Lesson 1 : Overview & Environment Edward Cheung Room W311g.
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
Matlab for Engineers Matlab Environment Chapter 2.
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.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
ECE 1304 Introduction to Electrical and Computer Engineering
Release Numbers MATLAB is updated regularly
MATLAB DENC 2533 ECADD LAB 9.
Matlab Workshop 9/22/2018.
StatLab Matlab Workshop
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
Experiment No. (1) - an introduction to MATLAB
MATLAB Introduction MATLAB can be thought of as a powerful graphing calculator but with a lot more buttons! It is also a programming language, commands.
Chapter 2 MATLAB Environment
Presentation transcript:

10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161

10/24/20152 Review Topics MATLAB variables Working with Matrices Scalar Operations Precedence of Arithmetic Operations Array Operations Saving your work Script M-files

MATLAB Windows I Command Window- similar to a scratch pad Command History Window- records all commands entered for future reference Workspace Window- keeps track of your variables and their current values Current Directory Window- points to your current open directory of MATLAB files Document Window- lets you edit data values easily (also called the array editor) Graphics Window- this window appears automatically whenever you do plotting Edit Window- lets you compose and edit programs (M-files) 10/24/20153

MATLAB Windows II As you use MATLAB you will become very familiar with all these resources and be able to move back and forth easily. Once you enter MATLAB you rarely have to leave it, compose program, run programs, edit programs, review results, save programs all within the MATLAB framework. 10/24/20154

5 MATLAB Variables Variable names must start with a letter, may contain only letters, numbers and the underscore. Variable names are case sensitive, “time”, “Time”, and “TIME” are all different variable names. Variable names can be up to 63 characters long.

10/24/20156 MATLAB Variables II Stay away from using MATLAB key words as variable names, “pi”, “i” or “j”, and MATLAB function names like “sqrt”, “sin”, “mean”, “max”, etc. Use the built in functions “isvarname”, “iskeyword”, and “which” if in doubt.

MATLAB Variables III Hint: Use variable names that mean something relevant to the problem. For example, use time rather than t or use distance rather than d and so on. It’s a good idea to self document your problem helping you to remember what the program does. 10/24/20157

8 Working with Matrices MATLAB’s versatility and power come from its ability to work with matrices. Engineering problems can be set up using matrix notation MATLAB simplifies matrix manipulations and hence simplifies writing programs to solve engineering problems.

10/24/20159 Working with Matrices II Matrices can be Row vectors, [ 1, 2, 6, 15, 3, 6] Rectangular matrices, n rows and m columns Column vectors, [1; 5; 7; 11] Matrices can be assigned variable names, x = [1, 2, 7, 3] “ ' ” is the transpose operator in MATLAB

10/24/ Working with Matrices III Observation At first, working with matrices and formulating problems this way will seem unnatural, but soon you will catch on and it will become second nature for you.

10/24/ Scalar Operations Although matrices are key, we will continue to need to work with scalars and particularly with scalars and matrices together. Scalar operations Addition and Subtraction( + and - ) Multiplication and division( * and / ) Exponentiation( ^, 3^2 = 9 )

10/24/ Scalar Operations II Some examples of scalar operations a = 3 b = a + 1 c = 2 * b d = a/c + 5 x = 1 x = x + 1 ' = ' is called the assignment operator. The right_hand_side is evaluated and its value is assigned to the left_hand_side

10/24/ Precedence of Arithmetic Operations MATLAB evaluates expressions from left to right in the following operator order or precedence Precedence Operation 1 Parentheses, innermost first 2 Exponentiation, left to right 3 Multiplication and division, l to r 4 Addition and subtraction, l to r

10/24/ Precedence of Arithmetic Operations II Look at the following ( a=1, b=2, c=4, d=5 ) a + b/c + d evaluates to 6.50 (a + b)/c + d5.75 (a + b)/(c+d)0.333 a + b/(c+d)1.222

10/24/ Precedence of Arithmetic Operations III All four expressions are valid and correct depending upon the problem you are solving. Observation To avoid confusion when entering long expressions, break them up into smaller statements and then combine the results. If in doubt use parentheses to enforce your ordering.

10/24/ Array Operation MATLAB defines the operators (.*,./, and.^ ) to perform “element by element” operations on matrices, row or column vectors. For example, x = [1, 5, 2, 8] y = [2, 1, 3, 2] x.* y yields the result [ 2, 5, 6, 16 ] x./ y yields the result [.5, 5,.666, 4 ] x.^ y yields the result [ 1, 5, 8, 64 ]

10/24/ Array Operations II The colon operator : is used to generate row vectors, column vectors and matrices. B = 0 : 4results inB = [ 0, 1, 2, 3, 4 ] A = 1 : 0.5 : 3A = [ 1, 1.5, 2, 2.5, 3 ] The linspace function can also be used to generate row vectors. time = linspace (1, 10, 10) yields time = [1,2,3,4,5,6,7,8,9,10] The logspace function e = logspace(1,3,3) would generate the vector e = [10, 100, 1000].

10/24/ Array Operations III Operations between scalars and matrices, and between scalars and row and column vectors also makes sense, let A be a row vector. A + 5 adds 5 to each element of A A - 3 similarly subtracts 3 from each element of A pi* A multiples each element of A by pi A / 2 divides each element of A by 2

10/24/ Array Operations IV Consider our problem of calculating the distance of a free falling body for a number of values of t, t = time in seconds. d = ½ * g * t 2 >>g = 9.8;% acceleration due to gravity >>t = 0 : 1 : 10;% create t vector with times >>d = 0.5 * g * t.^2;% find d for all values of t >>[t', d']% output table of t and d

Supressing Echoes Note on the previous slide, each line except the last one is followed by a semi-colon. MATLAB will echo the result of each line in the Command Window unless you request to suppress it. Use the semi-colon to suppress the output except for the results that you specifically want to have output. 10/24/201520

Display Formats I MATLAB provides a number of ways to format results that are listed in Table 2.2 on page 40. In all cases, MATLAB uses double precision (64 bits) floating point numbers in calculations. Enter a couple numbers and try the different formats to see what happens. 10/24/201521

Display Formats II Scientific notation is a useful way to enter very large and very small numbers. For example x = x is entered as x = 6.023e-6, all on one line. Note that spaces generally allowed in MATLAB are not permitted when using scientific notation. 10/24/201522

10/24/ Saving your Work At times you may want to save all or some of the variables and their values that you’ve created during a session. Later when you return, you would like to return the Workspace Window to its previous values and continue your work. To do this you would use the MATLAB “save” and “load” commands in the Command Window.

10/24/ Saving your Work II First you need to have created a folder in blank or blank or blank for all your MATLAB work. I call it MyMatlabfiles. Then browse and set the Current Directory to point to this folder. Then use “save file_name” command to save your Workspace in the MyMatlabfiles folder Use “load file_name” to return the Workspace. file_name needs to be a legal MATLAB name

10/24/ Saving your Work III Rather than save all your variables and their values, you can selectively save and restore by >> save file_name A B C to save only the variables A, B, and C. >> load file_name will restore the variables and values A, B, and C to the Workspace Window

10/24/ Script M-files An M-file is an ASCII text file containing MATLAB statements in the form of a program or function. You use the MATLAB editor to create, modify, and save your programs in your MyMatlabfiles folder with file name file_name. M-files support MATLAB’s programming environment

10/24/ Script M-files II Once you have completed writing and saving your program, you can run it in the Command Window by simply entering the name of the file where it is stored following the Command Window prompt. >> file_name cause your program to be run and the results generated. (You can also run programs directly from the Edit Window.)

10/24/ Script M-files III Use the MATLAB “what” command to get a listing of all your MATLAB M-files Use % followed by a comment generously to document your program Comments at the beginning of your program are echoed in response to the command >> help file_name

Cell Mode using the Editor This utility lets you divide a MATLAB program into cells, you can then execute each cell individually or together with all the cells. Use %_ (_ means space) to identify the beginning of each cell. Usually following %_ is the cell name. Highlight the cell by moving the cursor to the cell. Click on Cell in the Editor tool bar to select a cell to perform a function. Cell Mode is useful when debugging larger programs. 10/24/201529

Problem 2.13(b): radians to degrees conversion table % Convert radians to degrees between 0 and pi % angle_radians = 0:0.1*pi:pi; % angle_degrees = angle_radians * 180/pi; % table = [angle_radians', angle_degrees'] 10/24/201530

10/24/ Final Observation Chapter 2 introduces us to a number of MATLAB concepts. The assignments 2.9, 2.11, 2.13, and 2.17/2.18 This give us some practice with these concepts. Don’t be afraid to try things to see what happens. When you discover some good stuff, send a note to me for our Hints and Help folder on our website.