Presentation is loading. Please wait.

Presentation is loading. Please wait.

Spring 2004ENGR 111A1 MATLAB – Palm Chapter 3, Part 2 Function Files Class 6.1 Chapter 3: Section 2.

Similar presentations


Presentation on theme: "Spring 2004ENGR 111A1 MATLAB – Palm Chapter 3, Part 2 Function Files Class 6.1 Chapter 3: Section 2."— Presentation transcript:

1 Spring 2004ENGR 111A1 MATLAB – Palm Chapter 3, Part 2 Function Files Class 6.1 Chapter 3: Section 2

2 Spring 2004ENGR 111A2 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) Study power point presentations and homework assignments

3 Spring 2004ENGR 111A3 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!

4 Spring 2004ENGR 111A4 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. Solution Diary File for RAT 6.1 SolutionDiary File for RAT 6.1

5 Spring 2004ENGR 111A5 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.

6 Spring 2004ENGR 111A6 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_name MUST 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.

7 Spring 2004ENGR 111A7 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

8 Spring 2004ENGR 111A8 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.

9 Spring 2004ENGR 111A9 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

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

11 Spring 2004ENGR 111A11 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

12 Spring 2004ENGR 111A12 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.

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


Download ppt "Spring 2004ENGR 111A1 MATLAB – Palm Chapter 3, Part 2 Function Files Class 6.1 Chapter 3: Section 2."

Similar presentations


Ads by Google