Recap Graphic Window Edit Window Start Button Matrices in MATLAB Scalar Operations Order of Operations Array Operations Matrix Addition Matrix Multiplication.

Slides:



Advertisements
Similar presentations
E ngineering College of San Jose State University Engr.10 1 JKA & KY.
Advertisements

Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Lecture 6 MATLAB functions Basics of Built-in Functions, Help Feature, Elementary Functions (e.g., Polynomials, Trigonometric Functions), Data Analysis,
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.
Introduction to programming in MATLAB MATLAB can be thought of as an super-powerful graphing calculator Remember the TI-83 from calculus? With many more.
Programming For Nuclear Engineers Lecture 12 MATLAB (3) 1.
4. Week 04.March Use of M-File Editor/Debugger: text editor, debugger; editor works with file types in addition to.m (MATLAB “m-files”)
INTRO TO PROGRAMMING Chapter 2. M-files While commands can be entered directly to the command window, MATLAB also allows you to put commands in text files.
Functions 1 parameter, 2 return-values "Conversion of time format" One problem. 5 steps to solve it. 1.
Python Programming Fundamentals
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.
Fortran 1- Basics Chapters 1-2 in your Fortran book.
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.
A First Book of ANSI C Fourth Edition
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
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.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Input, Output, and Processing
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
MATLAB Basics. The following screen will appear when you start up Matlab. All of the commands that will be discussed should be typed at the >> prompt.
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
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.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
Recap Script M-file Editor/Debugger Window Cell Mode Chapter 3 “Built in MATLAB Function” Using Built-in Functions Using the HELP Feature Window HELP.
Introduction to Programming with RAPTOR
MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Recap Sum and Product Functions Matrix Size Function Variance and Standard Deviation Random Numbers Complex Numbers.
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 &
Chapter 6 Review: User Defined Functions Introduction to MATLAB 7 Engineering 161.
Lec-10 Manipulations of Matlab Matrices. Built-in functions The chapter will be covered quickly There are quite a few built-in functions in MATLAB – If.
Recap Saving Plots Summary of Chapter 5 Introduction of Chapter 6.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
ENG 1181 First-Year Engineering Program College of Engineering Engineering Education Innovation Center First-Year Engineering Program MAT - Introduction.
By max guerrero,bryan hernandez,caleb Portales  Spreadsheets are set up like tables with information running across rows and down columns. You could.
MATLAB for Engineers, by Holly Moore. ISBN © 2007 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is.
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.
Introduction to Programming Python Lab 3: Arithmetic 22 January PythonLab3 lecture slides.ppt Ping Brennan
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)
SCRIPTS AND FUNCTIONS DAVID COOPER SUMMER Extensions MATLAB has two main extension types.m for functions and scripts and.mat for variable save files.
ENG College of Engineering Engineering Education Innovation Center 1 Functions 1 in MATLAB Topics Covered: 1.Uses of Functions Organizational Tool.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
 The term “spreadsheet” covers a wide variety of elements useful for quantitative analysis of all kinds. Essentially, a spreadsheet is a simple tool.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
Introduction to Programming
ECE 1304 Introduction to Electrical and Computer Engineering
Arithmetic Operations
Built-in MATLAB Functions Chapter 3
Matlab Training Session 4: Control, Flow and Functions
Lecture 25.
User-Defined Functions
MATLAB DENC 2533 ECADD LAB 9.
Use of Mathematics using Technology (Maltlab)
Introduction to Programming
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Introduction to Matlab
Introduction to Programming
Presentation transcript:

Recap Graphic Window Edit Window Start Button Matrices in MATLAB Scalar Operations Order of Operations Array Operations Matrix Addition Matrix Multiplication Number Display (Scientific Notation) Script M-Files

Types of M-files Two types Script Function

Script M-file The script can use any variables that have been defined in the workspace, and any variables created in the script are added to the workspace when the script executes A script created in the MATLAB edit window can be executed by selecting the Save and Run icon from the menu bar A script can be executed by typing a file name or by using the run command from the command window No matter how you do it, you can only run an M-file if it is in the current folder

Editor/Debugger Window

Cell Mode It is a utility that allows the user to divide M-files into sections, or cells, that can be executed one at a time This feature is particularly useful as develop MATLAB ® programs are developed To activate the cell mode, select Cell -> Enable Cell Mode from the menu bar in the edit window Once the cell mode has been enabled, the cell toolbar appears To divide M-file program into cells, create cell dividers by using a double percentage sign followed by a space To name the cell, just add a name on the same line as the cell divider: % Cell Name

Continued…. It’s important to include the space after the double percentage sign (%). If don’t, the line is recognized as a comment, not a cell divider Once the cell dividers are in place, if cursor is positioned anywhere inside the cell, the entire cell turns pale yellow Now use the evaluation icons on the cell toolbar to evaluate a single section, evaluate the current section and move on to the next section, or evaluate the entire file Also on the cell toolbar is an icon that lists all the cell titles in the M-file

Continued…. By dividing the program into cells, it was possible to work on each problem separately Be sure to save any M-files developed this way by selecting Save or Save As from the file menu: File -> Save or File -> Save As The reason for using these commands is that in cell mode, the program is not automatically saved every time when it is run

Summary of Chapter

Chapter 3 Built in MATLAB Function

Using Built-in Functions Many of the names for MATLAB’s built-in functions are the same as those defined not only in the C programming language, but in Fortran and Java as well For example: to take the square root of the variable x, we type b = sqrt(x) A big advantage of MATLAB is that function arguments can generally be either scalars or matrices In our example, if x is a scalar, a scalar result is returned Thus, the statement x = 9; b = sqrt(x) returns a scalar: b = 3

Continued…. However, the square-root function, sqrt, can also accept matrices as input In this case, the square root of each element is calculated, so x = [4, 9, 16]; b = sqrt(x) returns b = All functions can be thought of as having three components: a name, input, and output In the preceding example, the name of the function is sqrt, the required input goes inside the parentheses and can be a scalar or a matrix, and the output is a calculated value or values In this example, the output was assigned the variable name b.

Continued…. Some functions require multiple inputs For example: the remainder function, rem, requires two inputs: a dividend and a divisor. We represent this as rem(x,y), so rem(10,3) calculates the remainder of 10 divided by 3: ans = 1 The size function is an example of a function that returns two outputs, which are stored in a single array. It determines the number of rows and columns in a matrix. Thus, d = [1, 2, 3; 4, 5, 6]; f = size(d) returns the 1 X 2 result matrix f = 2 3 You can also assign variable names to each of the answers by representing the left-hand side of the assignment statement as a matrix For example: [rows,cols] = size(d) gives rows =2 cols =3

Continued…. A useful feature of the more recent versions of MATLAB is the adaptive help capability As a function name is typed, a screen tip appears showing the correct function format It also includes a link to the function’s help page. A more complicated expressions can be created by nesting functions For instance: g = sqrt(sin(x)) finds the square root of the sine of whatever values are stored in the matrix named x If x is assigned a value of 2, x = 2; the result is g = Nesting functions can result in some complicated MATLAB code

Using the HELP Feature MATLAB includes extensive help tools, which are especially useful in understanding how to use functions There are two ways to get help from within MATLAB A command-line help function An HTML-based set of documentation available by selecting Help from the menu bar, selecting the help icon or by using the F1 function key There is also an online help set of documentation, available through the Start button or the Help icon on the menu bar However, the online help usually just reflects the HTML-based documentation Both help options should be used, since they provide different information and insights into how to use a specific function

Continued…. To use the command-line help function, type help in the command window help A list of help topics will appear: HELP topics: MATLAB\general – General-purpose commands MATLAB\ops – Operators and special characters MATLAB\lang – Programming language constructs MATLAB\elmat – Elementary matrices and matrix manipulation MATLAB\elfun – Elementary math functions MATLAB\specfun – Specialized math functions and so on To get help on a particular topic, type help

Example to get help on the tangent function, type help tan The following should be displayed: TAN Tangent of argument in radians. TAN(X) is the tangent of the elements of X See also atan, tand, atan2

Window HELP Screen To use the windowed help screen, select Help -> Product Help from the menu bar You can the navigate to the appropriate topic To access this version of the help utility directly from the command window, type doc Thus, to access the windowed help for tangent, type doc tan

MATLAB Help Window

Elementary Math Functions Elementary math functions include Logarithms Exponentials absolute value rounding functions, functions used in discrete mathematics

Common Computations

Rounding Functions

Example

Discrete Mathematics

rats Function MATLAB includes the rats function, which expresses a floating-point number as a rational number— that is, a fraction Discrete mathematics is the mathematics of whole numbers This is a additional function in MATLAB Factoring, calculating common denominators, and finding least common multiples are procedures usually covered in intermediate algebra courses

factorial Function A factorial is the product of all the positive integers from 1 to a given value Thus 3 factorial (indicated as 3!) is 3x2x1=6 Many problems involving probability can be solved with factorials For example: the number of ways that five cards can be arranged is 5x4x3x2 x1=5!=120. When you select the first card, you have five choices; when you select the second card, you have only four choices remaining, then three, two, and one. This approach is called combinatorial mathematics, or combinatorics To calculate a factorial in MATLAB use the factorial function Thus factorial(5) ans =120 gives the same result as 5*4*3*2*1 ans =120

Continued…. The value of a factorial quickly becomes very large Ten factorial is 3,628,800 MATLAB can handle up to 170! Anything larger gives Inf for an answer, because the maximum value for a real number is exceeded factorial(170) ans =7.2574e+306 factorial(171) ans =Inf Factorials are used to calculate the number of permutations and combinations of possible outcomes A permutation is the number of subgroups that can be formed when sampling from a larger group, when the order matters

Trigonometric Functions

Continued….

Data Analysis Function Analyzing data statistically in MATLAB is particularly easy, because Whole data sets can be represented by a single matrix The large number of built-in data analysis functions

Maximum and Minimum

Mean and Median There are several ways to find the “average” value in a data set In statistics, the mean of a group of values is call the average The mean is the sum of all the values, divided by the total number of values Another kind of average is the median, or the middle value There are an equal number of values both larger and smaller than the median The mode is the value that appears most often in a data set MATLAB provides functions for finding the mean, median, and the mode All of these functions are column dominant and will return an answer for each column in a two-dimensional matrix

Sums and Products