1 / 10

Functions 2

Functions 2. ENGR 1181 MATLAB 15. User-defined Functions in Real Life.

alka
Download Presentation

Functions 2

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. Functions 2 ENGR 1181 MATLAB 15

  2. User-defined Functions in Real Life User-defined functions are found in almost any programmed device. For example, a smart phone app developed by GM allows Cadillac owners to lock or unlock their car, heat or cool their car, or even check the tire pressure. Programs that allow these actions are packed full of user-defined functions.

  3. Today's Learning Objectives • After today’s class, students will be able to: • Integrate user-written functions into the same file with the main program. • Identify good function conventions, (e.g., the importance of placing functions at the end.

  4. Anonymous Function • Definition: A one line function that can be used to identify a reusable equation. SYNTAX: function_name = @(arglist) math equation >> Total(3,4) ans = 7 >> Total = @(a,b) a+b Total = @(a,b)a+b

  5. Function Main MATLAB does not allow you to include multiple line functions within a script file. Instead of collecting an entire directory of files, MATLAB allows you to list all functions in one file.

  6. Function Main Example function main % script file commands ... function[output] = name_1(input) ... function[output] = name_2(input) ...

  7. Programming Insight • You can now use save and run. This will run the top level script file (function main) and call each included function when that line of the script file is reached. • ALL functions in a file will only be understood inside that file, not in other files. • Because of this, general purpose functions should be as separate files in a user library.

  8. Important Takeaways • Anonymous Functions can be helpful to create one line functions for reusable equations. • Function main is useful for combining files into one self sufficient document.

  9. Preview of Next Class • Modeling and Simulation • We will work on an in-class MATLAB assignment that utilizes more advanced MATLAB programming to solve a problem. • MAT-16 combines linear and non-linear equations, curve fitting, and graphing in MATLAB.

  10. What’s Next? • Review today’s Quiz #15 • Open the in-class activity from the EEIC website and we will go through it together. • Then, start working on MAT-15 homework. • Prepare for next class by reading MATLAB Modeling and Simulation preparation material. • Submit Problem Solving Notebook on Carmen Dropbox and bring hard copy to class.

More Related