Functions - Intro to Functions Creating Functions How...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Intro to Functions Creating Functions How Functions Work Examples Functions T. Mercker Aerospace Engineering and Engineering Mechanics The University of Texas at Austin ASE 201: Introduction to Computer Programming March 27 / 30, 2009 T. Mercker Functions
Background image of page 1

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

View Full DocumentRight Arrow Icon
Intro to Functions Creating Functions How Functions Work Examples Outline Intro to Functions Creating Functions How Functions Work Examples T. Mercker Functions
Background image of page 2
Intro to Functions Creating Functions How Functions Work Examples Intro to Functions I In programming, a single “program” consists of multiple sub-tasks I These sub-tasks can be thought of as smaller programs that operate within the main program I For example, in our distance minimization example, there were 3 main sub-tasks 1. Entering the x and y coordinates of each point 2. Searching a grid of points to find the minimum 3. Displaying and plotting the results I To this point, you have been restricted by the fact that all the code of every sub-task has to be in the main program I MATLAB overcomes the restriction by allowing the implementation of “functions” T. Mercker Functions
Background image of page 3

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

View Full DocumentRight Arrow Icon
Intro to Functions Creating Functions How Functions Work Examples I Why have you been restricted by writing a single (long) script? 1. You cannot independently test (debug) each of the sub-tasks to make sure that they work before running the main program 2. Your code is not re-usable with other programs since the variables you chose are specific to the program you are working on 3. Individual sub-tasks have access to variables that they do not need 4. Every variable used is stored in the main (command window) workspace I So what is a “function” and why is it better? I “a MATLAB function is a special type of M-file that runs in its own independent workspace . It receives input data through an input argument list , and returns results to the caller through an output argument list .” T. Mercker Functions
Background image of page 4
Intro to Functions Creating Functions How Functions Work Examples I Accordingly, functions can be viewed as a “black box”
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 17

Functions - Intro to Functions Creating Functions How...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online