Engr 0012 (04-1) LecNotes 05-01 script/function comparison scriptsfunctions Show program logic answer “what” questions Show program details answer “how”

Slides:



Advertisements
Similar presentations
A number of MATLAB statements that allow us to control the order in which statements are executed in a program. There are two broad categories of control.
Advertisements

Lecture 5.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 19P. 1Winter Quarter MATLAB: Script and.
Introduction to Matlab. I use Matlab for: Data analysis Data plotting Image Analysis Also – Simulations (solving odes/pdes/finite element methods) – Minimisations,
Functions.
General Computer Science for Engineers CISC 106 Lecture 21 Dr. John Cavazos Computer and Information Sciences 04/10/2009.
1 Outline 13.1Introduction 13.2A Simple Program: Printing a Line of Text in a Web Page 13.3Another JavaScript Program: Adding Integers 13.4Memory Concepts.
Division Example 2x - 3y + 4z = 10 x + 6y - 3z = 4 -5x + y + 2z = 3 A*X = B where A = B = >> X = A\B X =
Matrix Mathematics in MATLAB and Excel
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
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.
Programming For Nuclear Engineers Lecture 12 MATLAB (3) 1.
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
Lecture 1: Introduction Lecture series based on the text: Essential MATLAB for Engineers and Scientists By Hahn & Valentine
MATLAB File Management. MATLAB User File Management Matlab provides a group of commands to manage user files. For more information, type help iofun. pwd.
Functions General Example (+1return values, +1 parameters) 1. The client's wish 2. Creating the function 1. Function's name, Parameter list, Return-info,
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
1 Chapter 1 MATLAB Primer This introductory chapter is relatively short and has as its main objective the introduction of MATLAB ® to the reader. This.
Programming.
Lecture 4 MATLAB Windows Arithmetic Operators Maintenance Functions
IC3003 B ASIC S CIENTIFIC C OMPUTING Lecture 1 Monday 08:30-11:30 U204a.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
Chapter 5 Using Data and COBOL Operators. Initializing Variables When you define a variable in WORKING- STORAGE, you also can assign it an initial value.
Introduction to MATLAB ENGR 1181 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Introduction to Engineering MATLAB – 6 Script Files - 1 Agenda Script files.
Plotting in MATLAB Rachel Davies Brittany Earnest Greg Fannon Nicholas Millan Khurram Najeeb.
Copyright © The McGraw-Hill Companies, Inc. Introduction to MATLAB for Engineers, Third Edition William J. Palm III Chapter 1 An Overview of MATLAB.
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
Chapter 1: Getting Started with MATLAB MATLAB for Scientist and Engineers Using Symbolic Toolbox.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Computers and Scientific Thinking David Reed, Creighton University Functions and Libraries 1.
CMPS 1371 Introduction to Computing for Engineers MatLab.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
Introduction to Programming with RAPTOR
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.
MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Getting Started with MATLAB (part 3) 1. Algebra, 2. Trig 3. The keyword ans 4. Clean up and suppress output: finalizing the software’s presentation 1.
Introduction to MATLAB 7 MATLAB Programming for Engineer Hassan Migdadi Spring 2013.
 2000 Deitel & Associates, Inc. All rights reserved. Outline 8.1Introduction 8.2A Simple Program: Printing a Line of Text in a Web Page 8.3Another JavaScript.
EGR 115 Introduction to Computing for Engineers Introduction to MATLAB Friday 29 August 2014 EGR 115 Introduction to Computing for Engineers.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
Engr 0012 (04-1) LecNotes script organization General organization for scripts 1. Header 3. Constant definitions 4. Input data/independent variable/parameter.
A simple classification problem Extract attributes Pattern Pattern recognition decision x C1 C2.
Basics of Matlab UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative.
Introduction to MATLAB Section2, statistics course Third year biomedical dept. Dina El Kholy, Ahmed Dalal.
Laboratory 2. LABORATORY OBJECTIVES This lab work is intended to give the students more insights on the Matlab environment and how to work more efficiently.
Structured Programming II: If Statements By the end of this class you should be able to: implement branching in a program describe and use an “if” statement.
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Engr 0012 (04-1) LecNotes Engineering 0012 Introduction to Engineering Computing Dr. Patzer B68D Benedum Hall Office:
Introduction to Matlab Patrice Koehl Department of Biological Sciences National University of Singapore
Interduction to MATLAB (part 2) Manal Alotaibi Mathematics department College of science King saud university.
Extending MATLAB Write your own scripts and/or functions Scripts and functions are plain text files with extension.m (m-files) To execute commands contained.
ENG College of Engineering Engineering Education Innovation Center 1 Functions 1 in MATLAB Topics Covered: 1.Uses of Functions Organizational Tool.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Introduction to Programming on MATLAB Ecological Modeling Course Sep 11th, 2006.
Engr 0012 (04-1) LecNotes Engr 0012 (04-1) LecNotes Contrasting MATLAB with C MATLABC language Workspace - interactive computation No real.
Lecture: MATLAB Chapter 1 Introduction
Use of Mathematics using Technology (Maltlab)
Writing functions in MATLAB
Review Make sure current directory is set properly Create a diary
Communication and Coding Theory Lab(CS491)
Matlab.
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Using Script Files and Managing Data
Programming with Matlab
Presentation transcript:

Engr 0012 (04-1) LecNotes script/function comparison scriptsfunctions Show program logic answer “what” questions Show program details answer “how” questions Multipurpose, e.g., get data, computation, display results Single purpose, e.g., get data only Solve a “whole” problem One step in solving a “whole” problem

Engr 0012 (04-1) LecNotes scripts and workspace m-files copied from get\get12\matlab directory to c:\temp directory MATLAB started, c:\temp current directory » who » help ca05a Class Activity 05a SCRIPT: running scripts affects the workspace » ca05a » who Your variables are: a b » a,b a = 4 b = 7 executing ca05a just added variables to your workspace!!

Engr 0012 (04-1) LecNotes scripts and workspace » help ca05b Class Activity 05b SCRIPT: running scripts AFFECTS the workspace!!! » ca05b » who Your variables are: a b c d executing ca05b just added more variables to your workspace!! » a,b,c,d a = 1234 b = c = 1 d = 2 executing ca05b changed the values of variables in your workspace!!

Engr 0012 (04-1) LecNotes script/function comparison scriptsfunctions Show program logic answer “what” questions Show program details answer “how” questions Multipurpose, e.g., get data, computation, display results Single purpose, e.g., get data only Solve a “whole” problemOne step in solving a “whole” problem Can add variables to workspace Can change values of variables in workspace

Engr 0012 (04-1) LecNotes functions and workspace » help ca05c Class Activity 05c FUNCTION: functions do not affect workspace » ca05c what did ca05c do??? » who Your variables are: a b c d ca05c did not add variables to workspace » a,b,c,d a = 1234 b = c = 1 d = 2 ca05c did not change values in workspace

Engr 0012 (04-1) LecNotes script/function comparison scriptsfunctions Show program logic answer “what” questions Show program details answer “how” questions Multipurpose, e.g., get data, computation, display results Single purpose, e.g., get data only Solve a “whole” problemOne step in solving a “whole” problem Can add variables to workspace Can change variable values in workspace Do not add variables to workspace Do not change variable values in workspace “Good” paper“Scrap” paper

Engr 0012 (04-1) LecNotes calling scripts and functions » ca05a “call” or execute script by name alone » a = ca05a ??? Attempt to execute SCRIPT ca05a as a function. cannot use script name on rhs of = » help ca05d Class Activity 05d FUNCTION: functions can return values » ca05d ans = i » a = ca05d a = i functions that return a single value can be used like any variable name

Engr 0012 (04-1) LecNotes calling scripts and functions » clear » help ca05e Class Activity 05e FUNCTION: functions can display in command window » ca05e return1 = return2 = ans = calculations in functions will display if not suppressed by a semicolon » who Your variables are: ans even though displayed, function variables are not added to work space MATLAB will capture the first value returned in a default variable “ ans ”

Engr 0012 (04-1) LecNotes calling scripts and functions » clear » [a,b] = ca05e return1 = return2 = a = b = » who Your variables are: a b capture of returned values is done by using square braces, [ ], that enclose the variable list names in the function and the workspace (script) need not be the same one-to-one relationship in order values assigned

Engr 0012 (04-1) LecNotes calling scripts and functions » [a,b] = ca05e; return1 = return2 = semicolon suppression is local

Engr 0012 (04-1) LecNotes calling scripts and functions » help ca05f Class Activity 05e FUNCTION: function parameters » [c,d] = ca05f ??? Input argument 'in1' is undefined. Error in ==> C:\temp\ca05f.m On line 21 ==> return1 = in1; functions that have inputs (needs) require an input list in ( ) after the function name when called functions that have no inputs (needs) do not use ( ) after the function name when called

Engr 0012 (04-1) LecNotes calling scripts and functions » clear » [a,b] = ca05f(2,3) a = 2 b = inputs are values (numbers)!!! values are returned » [c,d] = ca05f(a,b) c = 2 d = values can be represented by a variable name

Engr 0012 (04-1) LecNotes calling scripts and functions » [e,f] = ca05f(2*a,3*b-3) e = 4 f = values can be represented by an arithmetic expression » [g,h] = ca05f(pi,sin(3*b)) g = h = values can be represented by a function call

Engr 0012 (04-1) LecNotes script/function comparison scriptsfunctions Show program logic answer “what” questions Show program details answer “how” questions Multipurpose, e.g., get data, computation, display results Single purpose, e.g., get data only Solve a “whole” problemOne step in solving a “whole” problem Can add variables to workspace Can change variable values in workspace Do not add variables to workspace Do not change variable values in workspace “Good” paper“Scrap” paper “Called” by name alone “Call” depends on function Cannot be on rhs of = Can be on rhs of =

Engr 0012 (04-1) LecNotes script design strategy 1. Understand problem / requirements what information will result if successful? what information do you need to get the result? can you work a simple version by hand? 2. Write a problem statement identifying what will result and what is required 3. Outline the steps you would take to solve the problem (what would you do) focus on major tasks needed to get solution don’t worry about the details of how yet i.e., no equations needed at this time

Engr 0012 (04-1) LecNotes Class Activity 05 open ca05_e12(04-1).pdf in the get\get12 directory there are two problems turn in the requested outline for each problem