{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Functions - Intro to Functions Creating Functions How...

Info icon This 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
Image of page 1

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

View Full Document Right Arrow Icon
Intro to Functions Creating Functions How Functions Work Examples Outline Intro to Functions Creating Functions How Functions Work Examples T. Mercker Functions
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
Image of page 3

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

View Full Document Right 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
Image of page 4
Intro to Functions Creating Functions How Functions Work Examples I
Image of page 5

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern