{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Functions

# Functions - Intro to Functions Creating Functions How...

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

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

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

View Full Document
Intro to Functions Creating Functions How Functions Work Examples Outline Intro to Functions Creating Functions How Functions Work Examples T. Mercker Functions
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

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

View Full Document
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
Intro to Functions Creating Functions How Functions Work Examples I

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern