1 / 13

General Computer Science for Engineers CISC 106 Lecture 03

General Computer Science for Engineers CISC 106 Lecture 03. Dr. John Cavazos Computer and Information Sciences 2/16/2009. Lecture Overview. More on Functions -    Overview -    Calling functions from another function M-files -    Scripts versus functions. Functions.

keeney
Télécharger la présentation

General Computer Science for Engineers CISC 106 Lecture 03

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. General Computer Science for EngineersCISC 106Lecture 03 Dr. John Cavazos Computer and Information Sciences 2/16/2009

  2. Lecture Overview • More on Functions-    Overview -    Calling functions from another functionM-files-    Scripts versus functions

  3. Functions • Analogous to mathematical functions • f(x) = x + 1 • Independent of the other code • Each function is like a mini-program within the larger program itself • Key to breaking problems down

  4. Functions • In MATLAB, the first line of a function takes the following form: function <return value> = <name>(<arguments>)

  5. Functions cont. • The first line of a function: function <return value> = <name>(<arguments>) • The return value can be a number, a string, a matrix, etc. • Arguments • Can be a list of zero or more variables • Can also be numbers, strings, matrices

  6. Functions • Functions can call other functions • Your program is the main function, calling smaller functions to solve subproblems • Like in class on Friday: function outputValue = ringArea(rad_1, rad_2) outputValue = circleArea(rad_1) - circleArea(rad_2);

  7. Functions • In this class you will have to design programs to solve problems • These problems will be best solved (most easily and cleanly) by breaking down into smaller subproblems • The subproblems will be solved using functions • How big/small should a function be? • No more than one page or screen of text

  8. Problem Solving • Examples of big problems and how we might break them down • Scheduling (next slide) • Facebook • user login, ways to store user info, recommend friends • MP3 player • Store song lists, store playlists, import/export songs, shuffle play, repeat play, etc.

  9. Problem solving • Let’s think about some example problems and how we might break them down • How to automatically generate a schedule for an airline/business/school etc.

  10. Course Scheduling Software • What are inputs and outputs? • Inputs: Resources (teachers, students, office staff, classes ) • Output: Schedule of where and when everything and everyone needs to be

  11. Course Scheduling example • What functions might we need? • How many classrooms available? • How much demand is there for each room? • Course requirements? • Break it down even more?

  12. M-files • An m-file is also called a script file • Store commands in • Running a script file (m-file) • A function file • Special type of m-file • Contains a function name, arguments, etc., and implementation

  13. Scripts vs. functions • Functions have input and output parameters • Scripts cannot • Functions are more flexible • Function files have one function per file

More Related