1 / 13

MATLAB – Palm Chapter 3, Part 2 Function Files

MATLAB – Palm Chapter 3, Part 2 Function Files. Class 6.1 Chapter 3: Section 2. EXAM 1. Wednesday, October 6 th , from 6:30 to 8:00 pm. Bright 124. No Makeup for Unexcused Absence! Covers material through both lectures last week (through lecture 5.2)

Download Presentation

MATLAB – Palm Chapter 3, Part 2 Function Files

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. MATLAB – Palm Chapter 3, Part 2Function Files Class 6.1 Chapter 3: Section 2 ENGR 111A

  2. EXAM 1 • Wednesday, October 6th, from 6:30 to 8:00 pm. • Bright 124. • No Makeup for Unexcused Absence! • Covers material through both lectures last week (through lecture 5.2) • Study power point presentations and homework assignments ENGR 111A

  3. RAT 6.1 • Take out a piece of paper, write your name, team#, today’s date and RAT 6.1. • You are going to have to write a function file on paper. In the interest of time, you do not have to include any comments. For your homework, however, comments are REQUIRED! ENGR 111A

  4. RAT 6.1 (Continued) • In 2-minutes, Individually, write a function file to compute the area of a square given the dimension of a side. You will receive BONUS points if the function also outputs the perimeter. Test your algorithm using hand calculations for a square with side dimension of 4. • Within 30-seconds submit your papers to your GANT or Peer Teacher. • SolutionDiary File for RAT 6.1 ENGR 111A

  5. Learning Objectives • Students should be able to: • Create user-defined functions (script) *.m files and run them from the command window. • Know how to declare and use global variables. • Know how to use the commands fzero(), fminbnd() & fiminsearch() with user-defined functions. ENGR 111A

  6. 3.5 User Defined Functions • User Defined Functions are a special kind of Script File defined by its syntax. function [output] = function_name(input) • function_nameMUST be the same as the file name. • Make everything including the file name lower case. • Good examples are in the table on p. 151. • Hint: make the names short and lowercase. ENGR 111A

  7. 3.5 Continued • Take a few minutes to study the table and the text on p. 151 • Pay attention to the “;” and the output names. • Work the example at top of p. 152. DO NOT SUBMIT FOR GRADING. Sample Function File Diary File ENGR 111A

  8. Local & Global Variables • Local variables defined inside the function are local to that file. • That makes functions “portable” from one program to another. • Global variable can “be seen” by all parts of the program. • CAREFULLY study pp. 153-155. ENGR 111A

  9. In-Class Assignment 6.1 • Work Example 3.2-1 (p. 154) during the next 15-minutes. • Remember to include good comments! • You may be asked to demonstrate that your file will actually run. • Solution (diary file) • .M Function File Ideal • .M Function File vd_Waals ENGR 111A

  10. Applications of User Defined-Functions • Find the Zeros of a Function • Spend 3-minutes studying fzero() on p.156 • .M Function FileDiary File • Minimizing a Function of One Variable • Spend 3-minutes studying fminbnd() on p.157-158 • .M Function FileDiary File • Minimizing a Function with Several Variables • Spend 3-minutes studying fminsearch() on p.159-160 • .M Function FileDiary File • Table 3.2-1 (p.160) contains the minimizing and root finding functions ENGR 111A

  11. Example 3.2-2 & T3.2-1, 2 & 3 • Take 5 minutes to study Example 3.2-2, p. 161-162. • TYU T3.2-1, 2 & 3 ( p. 162) for credit; submit as part of Assignment 6.1. Submit your .M files for your function and your .M file with your diary. • .M Function File for 3.2-1 • Diary File for 3.2-1 • .M Function File for 3.2-2 • Diary File for 3.2-2 • .M Function File for 3.2-3 • Diary File for 3.2-3 ENGR 111A

  12. Assessment • Take out a sheet of paper and Individually, write a briefly description of the MatLab topic that is the “muddiest” to you so far this semester. • Then, as a team and agree on a topic you would like for GANT/Peer Teacher to cover in help sessions. Write this on a sheet of paper along with your Team # and give this paper to either of them as you leave. ENGR 111A

  13. Assignment 6.1 • INDIVIDUAL ASSIGNMENT • Due: One week from today. • Chapter 3: #8, 11, 12 & 14 ENGR 111A

More Related