EGR 106 – Week 5 – Functions Function concept and an example Rules for functions Local and global variables More examples Errors Application: zeroes and.

Slides:



Advertisements
Similar presentations
Lecture 14 User-defined functions Function: concept, syntax, and examples © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
Advertisements

Functions in MatLab Create a new folder on your Z:drive called MatLab_Class24 Start MatLab and change your current directory to MatLab_Class24 Topics:
Using Formulae We use formulae all the time. The algebraic equation just lets us put in numbers as we find them. Formulae such as; A = πr 2 (area of a.
Functions.
Functions MATLAB’s power comes from functions Functions allow projects to be partitioned into manageable, testable, reusable modules.
Week 6 - Programming I So far, we’ve looked at simple programming via “scripts” = programs of sequentially evaluated commands Today, extend features to:
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
EGR 106 – Week 7 – Functions Function concept and an example Rules for functions Local and global variables More examples Errors Application: zeroes and.
Division Example 2x - 3y + 4z = 10 x + 6y - 3z = 4 -5x + y + 2z = 3 A*X = B where A = B = >> X = A\B X =
EGR 106 – Week 8 Data Files & Functions Interacting with Data Files Functions – Concept – Examples and applications Textbook chapter ,
User-defined Functions Selim Aksoy Bilkent University Department of Computer Engineering
BPC.1 Basic Programming Concepts
ME457 Mechatronic System Modeling MICHIGAN STATE UNIVERSITY Matlab® refresher Your objective: to dominate! My objective: to help you dominate!
Applications of Consecutive Integers
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Introduction to programming in MATLAB MATLAB can be thought of as an super-powerful graphing calculator Remember the TI-83 from calculus? With many more.
1 -Defined Functions 1. Goals of this Chapter 2. General Concept 3. Advantages 4. How it works Programmer.
Chapter 13 Section 3 Radian Measure.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
Chapter 2 Sections 5-6 Problem Solving and Formulas.
ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB is a powerful program for numerical computations, plotting and programming.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
2.6 Formulas A literal equation – an equation involving two or more variables. Formulas are special types of literal equations. To transform a literal.
Advanced Topics- Functions Introduction to MATLAB 7 Engineering 161.
COMP 116: Introduction to Scientific Programming Lecture 11: Functions.
EGR 106 – Functions Functions – Concept – Examples and applications Textbook chapter p15-165, 6.11(p 178)
7.8 Applications of Quadratic Equations 8.1 Basic Properties and Reducing to Lowest Terms.
JavaScript III Functions and Abstraction. 2 JavaScript so far statements assignment function calls data types numeric string boolean expressions variables.
Pseudocode Algorithms Using Sequence, Selection, and Repetition Simple Program Design Third Edition A Step-by-Step Approach 6.
Getting Started with MATLAB (part2) 1. Basic Data manipulation 2. Basic Data Understanding 1. The Binary System 2. The ASCII Table 3. Creating Good Variables.
Activity 1.6 Depreciation. In your groups… Read page 51 Complete exercises 1 and 2 in your groups Don’t forget –Average rate of change is –UNITS!!!!!!!!!!!!!!!!!!!!!!!!!
Lecture 5 1.What is a variable 2.What types of information are stored in a variable 3.Getting user input from the keyboard 1.
READING AND WRITING FILES. READING AND WRITING FILES SEQUENTIALLY  Two ways to read and write files  Sequentially and RA (Random Access  Sequential.
10/5Special Assembly Anti-Bullying Presentation in Performing Arts Center (PAC)
User-Defined Functions II TK1914: C++ Programming.
Account Balances and Terminology. Account Balances To calculate the balance of a t- account: 1. Add the two sides of the account separately 2. Write the.
Week 7 : String and photo processing. Today’s Tasks  Practice list and string  Convert Decimal to any radix base number  Between Binary and Hexadecimal.
Week 19 day 4 6 A school increases the width of its rectangular playground from 25 meters to 40 meters and the length from 45 meters to 60 meters. By.
Perimeters and Areas of Similar Figures. You will use the ratio of two similar figures to find their perimeter and area.
Dale Roberts CSCI N305 Functions Declarations Department of Computer and Information Science, School of Science, IUPUI.
Chapter 02 (Part II) Introduction to C++ Programming.
Solving Quadratic Functions by Factoring. Factoring Review.
Chapter 3 Fractions.
Functions and relations
Objective The learner will solve problems using formulas
Chapter 9 Recursion.
Lesson 11-7 Ratios of Areas (page 456)
Introduction to Programming for Mechanical Engineers
©2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
User-Defined Functions
Functions and relations
Functions Declarations CSCI 230
Language Basics.
Writing functions in MATLAB
Engineering Computation with MATLAB
Relations vs. Functions Function Notation, & Evaluation
AP Statistics Day 5 Objective: Students will be able to understand and calculate variances and standard deviations.
Evaluating Logarithms
Exponential and Logarithmic Forms
Summary (Week 1) Categorical vs. Quantitative Variables
Chapter 6 Section 5.
7.2 Antidifferentiation by Substitution
Functions and Tables.
Brent M. Dingle Texas A&M University Chapter 5 – Section 2-3
Your objective: to dominate! My objective: to help you dominate!
IST256 : Applications Programming for Information Systems
Regression and Correlation of Data
Formalizing Relations and Functions
Introduction to Matlab
Presentation transcript:

EGR 106 – Week 5 – Functions Function concept and an example Rules for functions Local and global variables More examples Errors Application: zeroes and minima of equations Textbook chapter 6, pages

Function concept So far: – Have used Matlab’s built-in functions – Have written scripts Function ≡ reusable script – Sometimes called a subprogram – Building block for larger programs Example: converting degrees to radians

Example Function: DEG2RAD

Rules for Functions First line of the file must be of the form: function [outputs] = name(inputs) Identifies a function file List of function result variables List of any variables that the function needs Name of the function and the file (name.m)

Variables: Local vs Global Usually, once created, variables are available in the workspace until cleared Functions create their own workspace with their own local variables distinct from those in the original workspace – Functions cannot change variables within the original workspace – except through outputs – Exception – global variables can span both workspaces and be manipulated in both

Example Functions function a = tri_area(b,h) % TRI_AREA area of a right triangle % TRI_AREA(B,H) returns the area of % a right triangle with base B and height H a = 0.5*b.*h;

function [a,p] = triangle(b,h) % TRIANGLE area/perimeter calculation %[A,P] =TRIANGLE(B,H) returns the % area (A) and perimeter (P) of a % right triangle with base B %and height H a = 0.5*b.*h; p = b + h + sqrt(b.^2+h.^2);

Typical Errors Too few inputs

Too many inputs Too many outputs Wrong input type – funny result