E7_Lecture6_Su10+posted

# E7_Lecture6_Su10+posted - The concept of a function 1 A...

This preview shows pages 1–9. Sign up to view the full content.

E7 L6 1 The concept of a function A rule that assigns to each value of the input , a corresponding output value. Symbolically: { } { } 1 2 1 2 , ,..., ( , ,..., ) n m y y y x x x = FUNCTION input output

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
E7 L6 2 The concept of a function Pictorially: Input/output data can be of various types, e.g., numbers, strings, arrays, etc. x 1 x 2 x n y 1 y 2 y m FUNCTION . . . .
E7 L6 3 FUNCTIONS in programming FUNCTIONS in programming A set of commands that execute a “task” that can be reuse in several instances. These commands are written as a function Functions are use to break down a large task into a collection of smaller tasks. Functions are also called subroutines, methods , etc.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
E7 L6 4 MATLAB functions MATLAB contains a number of useful functions, Simple mathematical functions (e.g., sin, atan, log, exp, sqrt, abs, floor ) Array functions (e.g., size, sort, sum, max ) String functions (e.g., strmatch, upper ) Polynomial functions (e.g., polyval, roots )
E7 L6 5 MATLAB functions MATLAB functions Existing MATLAB functions are distinguished into two categories: Built-in functions implemented in a programming language other than Matlab (C or assembly language). Matlab-programmed functions Written as m-files The type command displays the content of an m-file.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
E7 L6 6 Examples of type outputs Examples of type outputs Built-in function: Matlab-programmed functions >> type sin sin is a built-in function. >> type linspace function y = linspace(d1, d2, n) % LINSPACE Linearly spaced vector. % LINSPACE(X1, X2) generates a row vector…
E7 L6 7 User-defined functions in MATLAB One of the most powerful features in MATLAB is the ability to create user-defined functions. Important rules: Functions are stored in files with the extension .m Functions can call other functions! Variables created within a function are local and disposable Stored in the function’s workspace but not recognized in the command window Disappear when the function is completed

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
E7 L6 8 A user-defined function example –
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 08/14/2010 for the course E 7 taught by Professor Patzek during the Summer '08 term at Berkeley.

### Page1 / 21

E7_Lecture6_Su10+posted - The concept of a function 1 A...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online