Lab17 DUE NOW Deliverable 2 Quizzes continue next Lab. on Functions. 1.

Slides:



Advertisements
Similar presentations
Introduction to File I/O How to read & write data to a disk file...
Advertisements

Bison Management Suppose you take over the management of a certain Bison population. The population dynamics are similar to those of the population we.
Lecture 14 User-defined functions Function: concept, syntax, and examples © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
Matlab tutorial course Lesson 1: The Basics: variables, scripts and functions Dr Michael Berks
Please close your laptops
Programming Basics Aims of Programming: –The aim of programming is to write programs to accomplish complex tasks Programming method: –functional decompositional.
Alice Variables Pepper. Set to Java look Edit / preferences restart.
 Monday, 9/30/02, Slide #1 CS106 Introduction to CS1 Monday, 9/30/02  QUESTIONS (on HW02, etc.)??  Today: Libraries, program design  More on Functions!
Introduction to TouchDevelop
CMSC 104, Version 8/061L18Functions1.ppt Functions, Part 1 of 4 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function.
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.
EPSII 59:006 Spring Topics Using TextPad If Statements Relational Operators Nested If Statements Else and Elseif Clauses Logical Functions For Loops.
Programmer Defined Functions Matthew Verleger. Windows It’s estimated that Window’s XP contains 45 million lines of code (and it’s over 10 years old).
Add to your agenda! Discovery Day. Wednesday, April 3 rd – all day – Poster Presentation (Cafeteria) & Slide presentations (COA Atrium). For example: “Formula.
Any questions on today’s homework? (Sections 1.6/1.7) Reminder: You should be doing this homework without using a calculator, because calculators can’t.
Functions 1 parameter, 2 return-values "Conversion of time format" One problem. 5 steps to solve it. 1.
REPETITION STRUCTURES. Topics Introduction to Repetition Structures The while Loop: a Condition- Controlled Loop The for Loop: a Count-Controlled Loop.
Matlab tutorial course Exercises 1:. Exercises Go back to my webpage, download the file ‘startup.m’ and save it in your MATLAB home folder – Must be directly.
Functions General Example (+1return values, +1 parameters) 1. The client's wish 2. Creating the function 1. Function's name, Parameter list, Return-info,
1 Functions Advantages Name, parameters, return info Flow of the data when running functions Menus Functions Applying Functions to Real Projects.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
Functions 1 ENGR 1181 MATLAB 14.
Annoucements Discovery Day ( sent this morning) – Wednesday, April 3 rd : Poster Presentation (Cafeteria) & Slide presentations (COA Atrium). For.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
1 Functions 1 Parameter, 1 Return-Value 1. The problem 2. Recall the layout 3. Create the definition 4. "Flow" of data 5. Testing 6. Projects 1 and 2.
Introduction to Arrays. definitions and things to consider… This presentation is designed to give a simple demonstration of array and object visualizations.
A Look Inside Some NetLogo Simulations Bruce Edmonds Centre for Policy Modelling Manchester Metropolitan University.
Numerical Computation Lecture 2: Introduction to Matlab Programming United International College.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Functions.
1 Lab of COMP 319 Lab tutor : Yao Zhang, Shenghua ZHONG Lab 4: Nov 30, 2011 Final Project: Image Compression.
Top Five Web Application Vulnerabilities Vebjørn Moen Selmersenteret/NoWires.org Norsk Kryptoseminar Trondheim
Functions Introduction to Programming By Engr. Bilal Ahmad 1ITP by Engr. Bilal Ahmad.
ISU Basic SAS commands Laboratory No. 1 Computer Techniques for Biological Research Animal Science 500 Ken Stalder, Professor Department of Animal Science.
Advanced Topics- Functions Introduction to MATLAB 7 Engineering 161.
Synthesis ENGR 1181 MATLAB 11. Topics  No new material  Covers topics that will be on the Midterm 2 Exam MATLAB 01 – Program Design MATLAB 02 – Introduction.
CS 4720 Dynamic Web Applications CS 4720 – Web & Mobile Systems.
Scientific Computing Introduction to Matlab Programming.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Covenant College November 27, Laura Broussard, Ph.D. Professor COS 131: Computing for Engineers Chapter 5: Functions.
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.
Recap Saving Plots Summary of Chapter 5 Introduction of Chapter 6.
CS1109 L AB 3 July 3rd. R OAD M AP Homework submission Review How to use function and scripts While-end Finish last exercise Lab 2 Challenge questions.
1. FINISHING FUNCTIONS 2. INTRODUCING PLOTTING 1.
Programmer-Defined Functions Advantages vs. Disadvantage 1.Definition and general Idea 2.Many Advantages 3.1 Disadvantage 1.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Repetition Structures.
-Defined Functions 1. Goals of this Chapter 2. General Concept 3. Advantages 4. Vocabulary 5. Examples 6. General Template – Applications 1. Definitions,
Introduction to MATLAB Section2, statistics course Third year biomedical dept. Dina El Kholy, Ahmed Dalal.
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Moodle Quizes Staff Guide. Creating Quizzes Click Add an Activity or Resource With the course in editing mode...
Introduction to Matlab Module #10 Page 1 Introduction to Matlab Module #10 – Creating Graphical User Interfaces Topics 1.Overview of GUI Development using.
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
CPSC 233 Tutorial 5 February 9 th /10 th, Java Classes Each Java class contains a set of instance variables and methods Instance Variables: Type.
Chapter 18 Introduction to Custom Templates C++ How to Program, 9/e ©2016 by Pearson Education, Inc., Hoboken, NJ. All Rights Reserved. Instructor Note:
JavaScript and Ajax (JavaScript Functions) Week 5 Web site:
Option Sheets Presentation Course Selection. Input your course selections online Using any computer and internet browser go to: student.hwdsb.on.ca Click.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Henrik Kjems-Nielsen ICES Secretariat InterCatch – the screen guide.
Introduction to Programming
Software Development Expansion of topics page 28 in Zelle
CS005 Introduction to Programming
Topics Introduction to Repetition Structures
Introduction to Programming for Mechanical Engineers
Lecture 1: Introduction
CS005 Introduction to Programming
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
Welcome back to Software Development!
Option Sheets Presentation
Lecture 20 – Practice Exercises 4
Lecture 20 – Practice Exercises 4
Presentation transcript:

Lab17 DUE NOW Deliverable 2 Quizzes continue next Lab. on Functions. 1

QUIZ TIME! Close all notes and MATLAB. Blackboard, under 2.Labs/HW/Solutions Lab17_QuizFunctions (5 minutes - timed) password required 1 attempt 2

Functions! 1.Remember it’s a completely separate.m file. 2.You’ll need an actual script file (other file) to make it fully operational. You should of course test in the cwd (Command Window) first. 3.The main script file communicates to the definition files through what is called the “function call” (which is 1 line of code). What is crucial is the order of the return-values and arguments. 4.What does “collecting return values” mean? 3

THE ORDER MATTERS When calling a function (whether built-in or programmer-defined):  The order matters on the argument list (the right side) a.fprintf(age, ‘name: %s age: %d\n’, name); b.fprintf(‘name: %s age: %d\n’, name, age); c.fprintf(‘name: %s age: %d\n’, age, name); d.fprintf(age, name, ‘name: %s age: %d\n’);  The order matters when “collecting return-values” (the left side) a.[x y z] = xlsread(‘data.xlsx’, ‘Sheet1’); b.[raw, txt, nbs] = xlsread(‘data.xlsx’, ‘Sheet1’); c.[nbs, txt, raw] = xlsread(‘data.xlsx’, ‘Sheet1’); d.[txt, ~, nbs] = xlsread(‘data.xlsx’, ‘Sheet1’); 4 NEW SLIDE

MATLAB can help you start.. File> New> Function This is THE MOST GENERALIZED form SIMPLIFY IT – some things are useless – delete the [ ] when there is only 1 return value – NEVER INCLUDE THE end keyword (no matter who tells you to) This would be way out of “introduction to programming”, let the file end peacefully when there is no more lines of code! 5 ✗ ✗ ✗

Some examples from last semester’s projects 6 example with no parameters

examples, cont. 7 example with no return-info

examples, cont. 8 PS: improve comments…! both return-values & parameters

Remember GUIDE? 9 The figure drawn, with all buttons and boxes (etc..) generates a function file. Here is my main script file, 7 lines. Note: returning values from a GUIDE function file requires a bit of research…

Try it #1: 5 minutes Translate this to a function. Show you tested: Create a function which receives 1 argument (weight of a satellite) and calculates and returns the weight of the final payload. (All units are Newtons). The client also gives the following data: Create a script file to see if the new keyword works! 10 Weight of Payload = W_structure + W_telemetry + W_power + W_guidance Where: W_structure = 2.16 * W_satellite W_telemetry = 0.78 * W_satellite W_power = 1.24 * W_satellite W_guidance = 1.21 * W_satellite both problems due at end of class.

Try it #2: timeleft/2 minutes The goal for this task is to write a function to shuffle a deck of cards, or more generically to mix up any vector it is given. The basic algorithm for this is as follows: – Select 2 positions at random – Swap the contents of those 2 positions. (Note, swapping requires a third temporary spot to copy one of the two values being swapped). – Repeat this process for a large number of times (generally, looping 20 times the number of items should be sufficient). Your function should accept a single vector as an input argument and return a vector containing all those items randomly rearranged. 11 problem by Dr. Verleger

Sample Output Sample Output: >> MyCards = 1:10 MyCards = >> MyShuffledCards = ShuffleDeck( MyCards ) MyShuffledCards =