Chapter 6 User-Defined Functions. dr.dcd.h CS 101 /SJC 5th Edition 1

Size: px
Start display at page:

Download "Chapter 6 User-Defined Functions. dr.dcd.h CS 101 /SJC 5th Edition 1"

Transcription

1 Chapter 6 User-Defined Functions dr.dcd.h CS 101 /SJC 5th Edition 1

2 MATLAB Functions M-files are collections of MATLAB statements that stored in a file, called a script file. Script files share the command window s workspace, so any variables created by the script files remain in the workspace after the script file finishes executing. A script file has no input arguments returns no results, but they communicate through the data left behind in the workspace. dr.dcd.h CS 101 Spring

3 MATLAB Functions 2 A MATLAB function is a special type of M- file that runs in its own independent workspace. A MATLAB function receives input data through an input argument list and returns results to the caller through an output argument list. A MATLAB function should be placed in a file with the same name as the function with an extension of.m. dr.dcd.h CS 101 Spring

4 MATLAB Functions 3 A function consists of three components For example: a = cos(x) output argument function name input argument All functions, whether they are build-in or user-defined functions, are available for any M-file programs dr.dcd.h CS 101 Spring

5 Syntax The general form of a function as function [outarg1, outarg2, ] = funcname(inarg1, inarg2, ) % H1 % other comments Function statements (return/end) The function keyword marks the beginning of the function. If there are only one output argument, the brackets can be dropped. Input arguments are placeholders for values. dr.dcd.h CS 101 Spring

6 Syntax 2 The comments block following the function statement is called the help block. The first line of it is called the H1. It should contain a one-line summary of the purpose of the function. H1 will be searched and displaced by lookfor, while the whole help block will be displaced if the command help keyword is used. Execution begins at the top and ends when either a return, an end, or the end of the function is reached. dr.dcd.h CS 101 Spring

7 Syntax 3 For debugging purpose, it may be useful to print intermediate results to the command window. However, once you complete your debugging make sure that all your output is suppressed. If you don t, you ll see extraneous information in the command window. It means that you should use ; at the end of every statement. dr.dcd.h CS 101 Spring

8 Pass-by-Value When a function is called, MATLAB makes a copy of the actual arguments and passes them to the workspace of the function. If the passed arguments are modified, it won t affect the original data in the caller. Command window s workspace x = 5; a = abc(x) cw.x abc.x Function abc s workspace function out=abc(in) abc.in abc.x dr.dcd.h CS 101 Spring

9 Local Variables Variables defined in an M-file function, only have meaning inside that program. The only way to communicate between functions and the workspace, is through the function input and output arguments. dr.dcd.h CS 101 Spring

10 Example 1: dist2(x 1,y 1,x 2,y 2 ) The distance between two points (x 1, y 1 ) and (x 2, y 2 ) can be defined as dr.dcd.h CS 101 Spring

11 H1 & Help Block After applying help and lookfor, function dist2 provides the following results. dr.dcd.h CS 101 Spring

12 Example 2: [x,y]=polar2rect(r,q) Convert polar coordinates (r,q) to rectangular form (x,y). dr.dcd.h CS 101 Spring

13 Example 3: [r,q]=rect2polar(x,y) Convert rectangular coordinates (x,y) to polar form (r,q). dr.dcd.h CS 101 Spring

14 Example 4: Selection Sort State the problem. Sort the data into ascending or descending order using the selection sort algorithm. Define the input/output. The inputs are typed by the user, and the outputs are the sorted data written to the command window. Describe the algorithm. - Input an array of n values; - Set the index i equals to1; - Scan and locate the i-th minimum value; - Swap the i-th minimum with the i-th element; - repeat n-1 times. dr.dcd.h CS 101 Spring

15 Example 4: Selection Sort 2 dr.dcd.h CS 101 Spring

16 Optional Arguments Some function may support arbitrary numbers of arguments. For example: plot(x, y); plot(x, y, :ok ); Plot(x, y, :ok, MarkerSize, 3); Functions that can be used to furnish optional arguments nargin, nargout, nargchk varargin, varargout error, warning inputname dr.dcd.h CS 101 Spring

17 Optional Arguments 2 nargin: the number of actual input arguments. nargout: the number of actual output arguments. nargchk: this function returns an error message if too few or too many arguments are used. - syntax: nargchk(min, max, nargin) varargin: the list of variables for actual input arguments. varargout: the list of variables for actual output arguments. dr.dcd.h CS 101 Spring

18 Optional Arguments 3 error: display an error message and abort if a fatal error was caught when a function is called. If its input argument is an empty string, then it does nothing. warning: display a warning message and resume the execution of a function. inputname: this function returns the actual name of the dummy argument. dr.dcd.h CS 101 Spring

19 Optional Arguments 4 dr.dcd.h CS 101 Spring

20 Homework Assignment #12 Quiz 6.1 Page 251: 6, 7 This assignment is due by the next week. Late submission will be penalized. dr.dcd.h CS 101 Spring

21 Global Memory MATLAB functions can also exchange data with each other with the base workspace through global memory. Global memory is a specifal type of memory that can be accessed from any workspace. A global variable is declared as global variable The default value for a global variable is empty, so an initialization is required. dr.dcd.h CS 101 Spring

22 Global Memory 2 An example: To count how many time a function is called. An alternative example: Two functions are used to modify a global counter. dr.dcd.h CS 101 Spring

23 Global Memory 3 dr.dcd.h CS 101 Spring

24 Random Number Generator It is important to know that the real world does not provide perfect measurements. So the ideal simulated data needs to add some random noise. The simulated noise is usually created by a random number generator. The build-in random number generator function rand generates values in the range of [0.0, 1.0). Then the generated noise values can be scaled and leveled. dr.dcd.h CS 101 Spring

25 Random Number Generator 2 The random numbers are in fact generated by a deterministic function; i.e. the sequence of numbers are fixed. The function returns a different and apparently random number each time it is called. It is because the function has started at a different starting point internally each time it is called. The starting point is called a seed and it is set as a global valable. dr.dcd.h CS 101 Spring

26 Random Number Generator 3 Example: two set of random numbers in the range of [-0.5, 0.5]. dr.dcd.h CS 101 Spring

27 Example 6.4: User Defined Random Number Generator A simple random number generator can be defined by the following equation: n 1 = a random seed n i+1 = mod(8121*n i , ) ran i = n i where is the total highest number in the sequence and each new n i+1 is set as the next seed. dr.dcd.h CS 101 Spring

28 Example 6.4: User Defined Random Number Generator 2 dr.dcd.h CS 101 Spring

29 Example 6.4: User Defined Random Number Generator 3 dr.dcd.h CS 101 Spring

30 Persistent Memory When a function finishes executing, the workspace created for that function is destroyed, so all local variables within that workspace will disappear. The next time the same function is called, a new workspace will be created. Sometimes, it is necessary to preserve local variables between calls to a function. dr.dcd.h CS 101 Spring

31 Persistent Memory 2 Persistent memory is a special mechanism to allow local variables to be preserved between calls to a function. Syntax: persistent variable dr.dcd.h CS 101 Spring

32 Persistent Memory 3 To rewrite a previous example: To count how many time a function is called. dr.dcd.h CS 101 Spring

33 Persistent Memory 4 How to reset the associated counter? dr.dcd.h CS 101 Spring

34 Homework Assignment # Exercises Page 268: 6.6, 6.7, 6.14 This homework is for your reference. dr.dcd.h CS 101 Spring

Example: A Four-Node Network

Example: A Four-Node Network Node Network Flows Flow of material, energy, money, information, etc., from one place to another arc 6 Node Node arc 6 Node Node 5 Node 6 8 Goal: Ship All of the Over the Network to Meet All of the 6 6

More information

9/4/2018. Chapter 2 (Part 1) MATLAB Basics. Arrays. Arrays 2. Arrays 3. Variables 2. Variables

9/4/2018. Chapter 2 (Part 1) MATLAB Basics. Arrays. Arrays 2. Arrays 3. Variables 2. Variables Chapter 2 (Part 1) MATLAB Basics Arrays The fundamental unit of data in MATLAB is the array. An array is a collection of data values organized into rows and columns and is known by a specified name. Individual

More information

Chapters 6-7. User-Defined Functions

Chapters 6-7. User-Defined Functions Chapters 6-7 User-Defined Functions User-Defined Functions, Iteration, and Debugging Strategies Learning objectives: 1. Write simple program modules to implement single numerical methods and algorithms

More information

User Defined Functions

User Defined Functions User Defined Functions 120 90 1 0.8 60 Chapter 6 150 0.6 0.4 30 0.2 180 0 210 330 240 270 300 Objectives Create and use MATLAB functions with both single and multiple inputs and outputs Learn how to store

More information

Introduction. Like other programming languages, MATLAB has means for modifying the flow of a program

Introduction. Like other programming languages, MATLAB has means for modifying the flow of a program Flow control 1 Introduction Like other programming languages, MATLAB has means for modying the flow of a program All common constructs are implemented in MATLAB: for while then else switch try 2 FOR loops.

More information

22-Functions Part 1 text: Chapter ECEGR 101 Engineering Problem Solving with Matlab Professor Henry Louie

22-Functions Part 1 text: Chapter ECEGR 101 Engineering Problem Solving with Matlab Professor Henry Louie 22-Functions Part 1 text: Chapter 7.1-7.5 ECEGR 101 Engineering Problem Solving with Matlab Professor Henry Louie Overview Function Syntax Help Line Saving Functions Using Functions Dr. Henry Louie 2 Function

More information

Chapter 2 (Part 2) MATLAB Basics. dr.dcd.h CS 101 /SJC 5th Edition 1

Chapter 2 (Part 2) MATLAB Basics. dr.dcd.h CS 101 /SJC 5th Edition 1 Chapter 2 (Part 2) MATLAB Basics dr.dcd.h CS 101 /SJC 5th Edition 1 Display Format In the command window, integers are always displayed as integers Characters are always displayed as strings Other values

More information

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices Introduction to Interactive Calculations Matlab is interactive, no need to declare variables >> 2+3*4/2 >> V = 50 >> V + 2 >> V Ans = 52 >> a=5e-3; b=1; a+b Most elementary functions and constants are

More information

SECTION 2: PROGRAMMING WITH MATLAB. MAE 4020/5020 Numerical Methods with MATLAB

SECTION 2: PROGRAMMING WITH MATLAB. MAE 4020/5020 Numerical Methods with MATLAB SECTION 2: PROGRAMMING WITH MATLAB MAE 4020/5020 Numerical Methods with MATLAB 2 Functions and M Files M Files 3 Script file so called due to.m filename extension Contains a series of MATLAB commands The

More information

W1005 Intro to CS and Programming in MATLAB. Data Structures. Fall 2014 Instructor: Ilia Vovsha. hep://

W1005 Intro to CS and Programming in MATLAB. Data Structures. Fall 2014 Instructor: Ilia Vovsha. hep:// W1005 Intro to CS and Programming in MATLAB Data Structures Fall 2014 Instructor: Ilia Vovsha hep://www.cs.columbia.edu/~vovsha/w1005 Outline Cell arrays FuncNons with variable arguments Structure arrays

More information

What is a Function? EF102 - Spring, A&S Lecture 4 Matlab Functions

What is a Function? EF102 - Spring, A&S Lecture 4 Matlab Functions What is a Function? EF102 - Spring, 2002 A&S Lecture 4 Matlab Functions What is a M-file? Matlab Building Blocks Matlab commands Built-in commands (if, for, ) Built-in functions sin, cos, max, min Matlab

More information

User-defined Functions

User-defined Functions User-defined Functions >> x = 19; >> y = sqrt (x); sqrt is a built-in function Somewhere there is a file called sqrt.m that contains all the code to compute sine It would be a pain to write that yourself

More information

Scientific Computing with MATLAB

Scientific Computing with MATLAB Scientific Computing with MATLAB Dra. K.-Y. Daisy Fan Department of Computer Science Cornell University Ithaca, NY, USA UNAM IIM 2012 2 Focus on computing using MATLAB Computer Science Computational Science

More information

Matlab Advanced Programming. Matt Wyant University of Washington

Matlab Advanced Programming. Matt Wyant University of Washington Matlab Advanced Programming Matt Wyant University of Washington Matlab as a programming Language Strengths (as compared to C/C++/Fortran) Fast to write -no type declarations needed Memory allocation/deallocation

More information

1 >> Lecture 3 2 >> 3 >> -- Functions 4 >> Zheng-Liang Lu 169 / 221

1 >> Lecture 3 2 >> 3 >> -- Functions 4 >> Zheng-Liang Lu 169 / 221 1 >> Lecture 3 2 >> 3 >> -- Functions 4 >> Zheng-Liang Lu 169 / 221 Functions Recall that an algorithm is a feasible solution to the specific problem. 1 A function is a piece of computer code that accepts

More information

Computational Methods of Scientific Programming

Computational Methods of Scientific Programming 12.010 Computational Methods of Scientific Programming Lecturers Thomas A Herring, Jim Elliot, Chris Hill, Summary of Today s class We will look at Matlab: History Getting help Variable definitions and

More information

APPM 2460 Matlab Basics

APPM 2460 Matlab Basics APPM 2460 Matlab Basics 1 Introduction In this lab we ll get acquainted with the basics of Matlab. This will be review if you ve done any sort of programming before; the goal here is to get everyone on

More information

INTRODUCTION TO MATLAB Part2 - Programming UNIVERSITY OF SHEFFIELD. July 2018

INTRODUCTION TO MATLAB Part2 - Programming UNIVERSITY OF SHEFFIELD. July 2018 INTRODUCTION TO MATLAB Part2 - Programming UNIVERSITY OF SHEFFIELD CiCS DEPARTMENT Deniz Savas & Mike Griffiths July 2018 Outline MATLAB Scripts Relational Operations Program Control Statements Writing

More information

Lecture 6 MATLAB programming (4) Dr.Qi Ying

Lecture 6 MATLAB programming (4) Dr.Qi Ying Lecture 6 MATLAB programming (4) Dr.Qi Ying Objectives User-defined Functions Anonymous Functions Function name as an input argument Subfunctions and nested functions Arguments persistent variable Anonymous

More information

FUNCTIONS ( WEEK 5 ) DR. USMAN ULLAH SHEIKH DR. MUSA MOHD MOKJI DR. MICHAEL TAN LONG PENG DR. AMIRJAN NAWABJAN DR. MOHD ADIB SARIJARI

FUNCTIONS ( WEEK 5 ) DR. USMAN ULLAH SHEIKH DR. MUSA MOHD MOKJI DR. MICHAEL TAN LONG PENG DR. AMIRJAN NAWABJAN DR. MOHD ADIB SARIJARI FUNCTIONS SKEE1022 SCIENTIFIC PROGRAMMING ( WEEK 5 ) DR. USMAN ULLAH SHEIKH DR. MUSA MOHD MOKJI DR. MICHAEL TAN LONG PENG DR. AMIRJAN NAWABJAN DR. MOHD ADIB SARIJARI OBJECTIVES Create Function 1) Create

More information

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY What is MATLAB? MATLAB (MATrix LABoratory) developed by The Mathworks, Inc. (http://www.mathworks.com) Key Features: High-level language for numerical

More information

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah)

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah) Introduction ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah) MATLAB is a powerful mathematical language that is used in most engineering companies today. Its strength lies

More information

Tentative Course Schedule, CRN INTRODUCTION TO SCIENTIFIC & ENGINEERING COMPUTING BIL 108E, CRN24023 LECTURE # 5 INLINE FUNCTIONS

Tentative Course Schedule, CRN INTRODUCTION TO SCIENTIFIC & ENGINEERING COMPUTING BIL 108E, CRN24023 LECTURE # 5 INLINE FUNCTIONS Tentative Course Schedule, CRN 24023 INTRODUCTION TO SCIENTIFIC & ENGINEERING COMPUTING BIL 108E, CRN24023 Dr. S. Gökhan Technical University of Istanbul Week Date Topics 1 Feb. 08 Computing 2 Feb. 15

More information

Flow Control and Functions

Flow Control and Functions Flow Control and Functions Script files If's and For's Basics of writing functions Checking input arguments Variable input arguments Output arguments Documenting functions Profiling and Debugging Introduction

More information

Quiz 1: Functions and Procedures

Quiz 1: Functions and Procedures Quiz 1: Functions and Procedures Outline Basics Control Flow While Loops Expressions and Statements Functions Primitive Data Types 3 simple data types: number, string, boolean Numbers store numerical data

More information

COMS 3101 Programming Languages: MATLAB. Lecture 2

COMS 3101 Programming Languages: MATLAB. Lecture 2 COMS 3101 Programming Languages: MATLAB Lecture 2 Fall 2013 Instructor: Ilia Vovsha hbp://www.cs.columbia.edu/~vovsha/coms3101/matlab Lecture Outline Quick review of array manipulanon Control flow Simple

More information

More on Arrays CS 16: Solving Problems with Computers I Lecture #13

More on Arrays CS 16: Solving Problems with Computers I Lecture #13 More on Arrays CS 16: Solving Problems with Computers I Lecture #13 Ziad Matni Dept. of Computer Science, UCSB Announcements Homework #12 due today No homework assigned today!! Lab #7 is due on Monday,

More information

MATLAB Demo. Preliminaries and Getting Started with Matlab

MATLAB Demo. Preliminaries and Getting Started with Matlab Math 250C Sakai submission Matlab Demo 1 Created by G. M. Wilson, revised 12/23/2015 Revised 09/05/2016 Revised 01/07/2017 MATLAB Demo In this lab, we will learn how to use the basic features of Matlab

More information

Algorithms for Arrays Vectors Pointers CS 16: Solving Problems with Computers I Lecture #14

Algorithms for Arrays Vectors Pointers CS 16: Solving Problems with Computers I Lecture #14 Algorithms for Arrays Vectors Pointers CS 16: Solving Problems with Computers I Lecture #14 Ziad Matni Dept. of Computer Science, UCSB Administra:ve Turn in Homework #12 Homework #13 is due Tuesday Lab

More information

Introduction to Programming in MATLAB

Introduction to Programming in MATLAB Introduction to Programming in MATLAB User-defined Functions Functions look exactly like scripts, but for ONE difference Functions must have a function declaration Help file Function declaration Outputs

More information

MATLAB Project: Getting Started with MATLAB

MATLAB Project: Getting Started with MATLAB Name Purpose: To learn to create matrices and use various MATLAB commands for reference later MATLAB built-in functions used: [ ] : ; + - * ^, size, help, format, eye, zeros, ones, diag, rand, round, cos,

More information

COGS 119/219 MATLAB for Experimental Research. Fall Functions

COGS 119/219 MATLAB for Experimental Research. Fall Functions COGS 119/219 MATLAB for Experimental Research Fall 2016 - Functions User-defined Functions A user-defined function is a MATLAB program that is created by a user, saved as a function file, and then can

More information

Question Points Score Total 100

Question Points Score Total 100 Name Signature General instructions: You may not ask questions during the test. If you believe that there is something wrong with a question, write down what you think the question is trying to ask and

More information

1 >> Lecture 3 2 >> 3 >> -- Functions 4 >> Zheng-Liang Lu 172 / 225

1 >> Lecture 3 2 >> 3 >> -- Functions 4 >> Zheng-Liang Lu 172 / 225 1 >> Lecture 3 2 >> 3 >> -- Functions 4 >> Zheng-Liang Lu 172 / 225 Functions The first thing of the design of algorithms is to divide and conquer. A large and complex problem would be solved by couples

More information

ME313 Homework #5. Matlab- Functions

ME313 Homework #5. Matlab- Functions 1 ME1 Homework #5 Matlab- Functions Last Updated February 9 2012. Assignment: Read and complete the suggested commands. After completing the exercise, copy the contents of the command window into Word

More information

To start using Matlab, you only need be concerned with the command window for now.

To start using Matlab, you only need be concerned with the command window for now. Getting Started Current folder window Atop the current folder window, you can see the address field which tells you where you are currently located. In programming, think of it as your current directory,

More information

Matlab- Command Window Operations, Scalars and Arrays

Matlab- Command Window Operations, Scalars and Arrays 1 ME313 Homework #1 Matlab- Command Window Operations, Scalars and Arrays Last Updated August 17 2012. Assignment: Read and complete the suggested commands. After completing the exercise, copy the contents

More information

Lecture 8 Programmer-Defined Functions in MATLAB

Lecture 8 Programmer-Defined Functions in MATLAB Lecture 8 Programmer-Defined Functions in MATLAB Outline Why programmer-defined functions? Simple Custom Functions Script vs Function Modular Programming Why programmer-defined functions? % Calculate x!/y!

More information

Informal Reference Manual for X

Informal Reference Manual for X 1 contents of Reference Manual for X Whitespace Comments Names Types, Constants and Expressions Assignment, Input and Output Statements Programs Variables, Implicit Name Introduction Control: Selection

More information

CS1132 Fall 2009 Assignment 1. 1 The Monty Hall Dillemma. 1.1 Programming the game

CS1132 Fall 2009 Assignment 1. 1 The Monty Hall Dillemma. 1.1 Programming the game CS1132 Fall 2009 Assignment 1 Adhere to the Code of Academic Integrity. You may discuss background issues and general solution strategies with others and seek help from course staff, but the homework you

More information

1 Introduction to Matlab

1 Introduction to Matlab 1 Introduction to Matlab 1. What is Matlab? Matlab is a computer program designed to do mathematics. You might think of it as a super-calculator. That is, once Matlab has been started, you can enter computations,

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab Weichung Wang 2003 NCTS-NSF Workshop on Differential Equations, Surface Theory, and Mathematical Visualization NCTS, Hsinchu, February 13, 2003 DE, ST, MV Workshop Matlab 1 Main

More information

EL2310 Scientific Programming

EL2310 Scientific Programming Lecture 4: Programming in Matlab Yasemin Bekiroglu (yaseminb@kth.se) Florian Pokorny(fpokorny@kth.se) Overview Overview Lecture 4: Programming in Matlab Wrap Up More on Scripts and Functions Wrap Up Last

More information

Assignment 2 in Simulation of Telesystems Laboratory exercise: Introduction to Simulink and Communications Blockset

Assignment 2 in Simulation of Telesystems Laboratory exercise: Introduction to Simulink and Communications Blockset Mid Sweden University Revised: 2013-11-12 Magnus Eriksson Assignment 2 in Simulation of Telesystems Laboratory exercise: Introduction to Simulink and Communications Blockset You are expected to conclude

More information

C++ Programming. Arrays and Vectors. Chapter 6. Objectives. Chiou. This chapter introduces the important topic of data structures collections

C++ Programming. Arrays and Vectors. Chapter 6. Objectives. Chiou. This chapter introduces the important topic of data structures collections C++ Programming Chapter 6 Arrays and Vectors Yih-Peng Chiou Room 617, BL Building (02) 3366-3603 3603 ypchiou@cc.ee.ntu.edu.tw Photonic Modeling and Design Lab. Graduate Institute of Photonics and Optoelectronics

More information

CS 113: Introduction to

CS 113: Introduction to CS 113: Introduction to Course information MWF 12:20-1:10pm 1/21-2/15, 306 Hollister Hall Add/drop deadline: 1/28 C Instructor: David Crandall See website for office hours and contact information Prerequisites

More information

Lecture 4: Complex Numbers Functions, and Data Input

Lecture 4: Complex Numbers Functions, and Data Input Lecture 4: Complex Numbers Functions, and Data Input Dr. Mohammed Hawa Electrical Engineering Department University of Jordan EE201: Computer Applications. See Textbook Chapter 3. What is a Function? A

More information

Homework 5. Due Friday, March 1 at 5:00 PM

Homework 5. Due Friday, March 1 at 5:00 PM WRITTEN PROBLEMS Homework 5 Due Friday, March at 5:00 PM I think we can all agree that junior high is filled with embarrassing and awkward and downright humiliating moments, right? - Lizzie McGuire Handing

More information

Finding, Starting and Using Matlab

Finding, Starting and Using Matlab Variables and Arrays Finding, Starting and Using Matlab CSC March 6 &, 9 Array: A collection of data values organized into rows and columns, and known by a single name. arr(,) Row Row Row Row 4 Col Col

More information

Variables are used to store data (numbers, letters, etc) in MATLAB. There are a few rules that must be followed when creating variables in MATLAB:

Variables are used to store data (numbers, letters, etc) in MATLAB. There are a few rules that must be followed when creating variables in MATLAB: Contents VARIABLES... 1 Storing Numerical Data... 2 Limits on Numerical Data... 6 Storing Character Strings... 8 Logical Variables... 9 MATLAB S BUILT-IN VARIABLES AND FUNCTIONS... 9 GETTING HELP IN MATLAB...

More information

Excel Formulas & Functions I CS101

Excel Formulas & Functions I CS101 Excel Formulas & Functions I CS101 Topics Covered Use statistical functions Use cell references Use AutoFill Write formulas Use the RANK.EQ function Calculation in Excel Click the cell where you want to

More information

CS : Programming for Non-Majors, Fall 2018 Programming Project #5: Big Statistics Due by 10:20am Wednesday November

CS : Programming for Non-Majors, Fall 2018 Programming Project #5: Big Statistics Due by 10:20am Wednesday November CS 1313 010: Programming for Non-Majors, Fall 2018 Programming Project #5: Big Statistics Due by 10:20am Wednesday November 7 2018 This fifth programming project will give you experience writing programs

More information

MATLAB Project: Getting Started with MATLAB

MATLAB Project: Getting Started with MATLAB Name Purpose: To learn to create matrices and use various MATLAB commands for reference later MATLAB functions used: [ ] : ; + - * ^, size, help, format, eye, zeros, ones, diag, rand, round, cos, sin,

More information

PROGRAMMING WITH MATLAB DR. AHMET AKBULUT

PROGRAMMING WITH MATLAB DR. AHMET AKBULUT PROGRAMMING WITH MATLAB DR. AHMET AKBULUT OVERVIEW WEEK 1 What is MATLAB? A powerful software tool: Scientific and engineering computations Signal processing Data analysis and visualization Physical system

More information

Homeworks on FFT Instr. and Meas. for Communication Systems- Gianfranco Miele. Name Surname

Homeworks on FFT Instr. and Meas. for Communication Systems- Gianfranco Miele. Name Surname Homeworks on FFT 90822- Instr. and Meas. for Communication Systems- Gianfranco Miele Name Surname October 15, 2014 1 Name Surname 90822 (Gianfranco Miele): Homeworks on FFT Contents Exercise 1 (Solution)............................................

More information

Introduction to MATLAB

Introduction to MATLAB Chapter 1 Introduction to MATLAB 1.1 Software Philosophy Matrix-based numeric computation MATrix LABoratory built-in support for standard matrix and vector operations High-level programming language Programming

More information

Lesson 2 Characteristics of Good Code Writing (* acknowledgements to Dr. G. Spinelli, New Mexico Tech, for a substantial portion of this lesson)

Lesson 2 Characteristics of Good Code Writing (* acknowledgements to Dr. G. Spinelli, New Mexico Tech, for a substantial portion of this lesson) T-01-13-2009 GLY 6932/6862 Numerical Methods in Earth Sciences Spring 2009 Lesson 2 Characteristics of Good Code Writing (* acknowledgements to Dr. G. Spinelli, New Mexico Tech, for a substantial portion

More information

Ph3 Mathematica Homework: Week 1

Ph3 Mathematica Homework: Week 1 Ph3 Mathematica Homework: Week 1 Eric D. Black California Institute of Technology v1.1 1 Obtaining, installing, and starting Mathematica Exercise 1: If you don t already have Mathematica, download it and

More information

C Functions. CS 2060 Week 4. Prof. Jonathan Ventura

C Functions. CS 2060 Week 4. Prof. Jonathan Ventura CS 2060 Week 4 1 Modularizing Programs Modularizing programs in C Writing custom functions Header files 2 Function Call Stack The function call stack Stack frames 3 Pass-by-value Pass-by-value and pass-by-reference

More information

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial 1 Matlab Tutorial 2 Lecture Learning Objectives Each student should be able to: Describe the Matlab desktop Explain the basic use of Matlab variables Explain the basic use of Matlab scripts Explain the

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display Facilities Flow Control Using of M-File Writing User

More information

Objectives of This Chapter

Objectives of This Chapter Chapter 6 C Arrays Objectives of This Chapter Array data structures to represent the set of values. Defining and initializing arrays. Defining symbolic constant in a program. Using arrays to store, list,

More information

} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2.

} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2. Class #10: Understanding Primitives and Assignments Software Design I (CS 120): M. Allen, 19 Sep. 18 Java Arithmetic } Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = 2 + 5 / 2; 3.

More information

CS129: Introduction to Matlab (Code)

CS129: Introduction to Matlab (Code) CS129: Introduction to Matlab (Code) intro.m Introduction to Matlab (adapted from http://www.stanford.edu/class/cs223b/matlabintro.html) Stefan Roth , 09/08/2003 Stolen

More information

This wouldn t work without the previous declaration of X. This wouldn t work without the previous declaration of y

This wouldn t work without the previous declaration of X. This wouldn t work without the previous declaration of y Friends We want to explicitly grant access to a function that isn t a member of the current class/struct. This is accomplished by declaring that function (or an entire other struct) as friend inside the

More information

INTRODUCTION TO MATLAB

INTRODUCTION TO MATLAB INTRODUCTION TO MATLAB Cells, structs, strings and functions Dario Cuevas and Vahid Rahmati Dresden, November 19, 2014 01 Cells and structures Cells: They are similar to arrays, but each element can have

More information

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG 1 Notice Reading Assignment Chapter 1: Introduction to Java Programming Homework 1 It is due this coming Sunday

More information

10 M-File Programming

10 M-File Programming MATLAB Programming: A Quick Start Files that contain MATLAB language code are called M-files. M-files can be functions that accept arguments and produce output, or they can be scripts that execute a series

More information

Spring 2010 Instructor: Michele Merler.

Spring 2010 Instructor: Michele Merler. Spring 2010 Instructor: Michele Merler http://www1.cs.columbia.edu/~mmerler/comsw3101-2.html Type from command line: matlab -nodisplay r command Tells MATLAB not to initialize the visual interface NOTE:

More information

LAB 2: Linear Equations and Matrix Algebra. Preliminaries

LAB 2: Linear Equations and Matrix Algebra. Preliminaries Math 250C, Section C2 Hard copy submission Matlab # 2 1 Revised 07/13/2016 LAB 2: Linear Equations and Matrix Algebra In this lab you will use Matlab to study the following topics: Solving a system of

More information

You just told Matlab to create two strings of letters 'I have no idea what I m doing' and to name those strings str1 and str2.

You just told Matlab to create two strings of letters 'I have no idea what I m doing' and to name those strings str1 and str2. Chapter 2: Strings and Vectors str1 = 'this is all new to me' str2='i have no clue what I am doing' str1 = this is all new to me str2 = I have no clue what I am doing You just told Matlab to create two

More information

CSC 121: Computer Science for Statistics

CSC 121: Computer Science for Statistics CSC 121: Computer Science for Statistics Radford M. Neal, University of Toronto, 2017 http://www.cs.utoronto.ca/ radford/csc121/ Week 3 Making Functions Do Different Things, Using if When you call a function

More information

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved. Java How to Program, 10/e Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved. Data structures Collections of related data items. Discussed in depth in Chapters 16 21. Array objects Data

More information

The Mathcad Workspace 7

The Mathcad Workspace 7 For information on system requirements and how to install Mathcad on your computer, refer to Chapter 1, Welcome to Mathcad. When you start Mathcad, you ll see a window like that shown in Figure 2-1. By

More information

Lecture 4. Defining Functions

Lecture 4. Defining Functions Lecture 4 Defining Functions Academic Integrity Quiz Remember: quiz about the course AI policy Have posted grades for completed quizes Right now, missing ~90 enrolled students If did not receive perfect,

More information

1 Overview of the standard Matlab syntax

1 Overview of the standard Matlab syntax 1 Overview of the standard Matlab syntax Matlab is based on computations with matrices. All variables are matrices. Matrices are indexed from 1 (and NOT from 0 as in C!). Avoid using variable names i and

More information

Chemical Engineering 541

Chemical Engineering 541 Chemical Engineering 541 Computer Aided Design Methods Matlab Tutorial 1 Overview 2 Matlab is a programming language suited to numerical analysis and problems involving vectors and matricies. Matlab =

More information

Table of contents. HTML5 Data Bindings Repeater DMXzone

Table of contents. HTML5 Data Bindings Repeater DMXzone Table of contents Table of contents... 1 About HTML5 Data Bindings Extended Repeater... 2 Features in Detail... 3 The Basics: Client Side Pagination... 14 Advanced: Sorting Data of a Repeat Region... 36

More information

Introduction to MATLAB

Introduction to MATLAB to MATLAB Spring 2019 to MATLAB Spring 2019 1 / 39 The Basics What is MATLAB? MATLAB Short for Matrix Laboratory matrix data structures are at the heart of programming in MATLAB We will consider arrays

More information

The Dynamic Typing Interlude

The Dynamic Typing Interlude CHAPTER 6 The Dynamic Typing Interlude In the prior chapter, we began exploring Python s core object types in depth with a look at Python numbers. We ll resume our object type tour in the next chapter,

More information

Reset-able and Enable-able Registers

Reset-able and Enable-able Registers VERILOG II Reset-able and Enable-able Registers Sometimes it is convenient or necessary to have flip flops with special inputs like reset and enable When designing flip flops/registers, it is ok (possibly

More information

University of Alberta

University of Alberta A Brief Introduction to MATLAB University of Alberta M.G. Lipsett 2008 MATLAB is an interactive program for numerical computation and data visualization, used extensively by engineers for analysis of systems.

More information

CS1132 Spring 2016 Assignment 2 Due Apr 20th

CS1132 Spring 2016 Assignment 2 Due Apr 20th CS1132 Spring 2016 Assignment 2 Due Apr 20th Adhere to the Code of Academic Integrity. You may discuss background issues and general strategies with others and seek help from course staff, but the implementations

More information

Lecture 20 Transactions

Lecture 20 Transactions CMSC 461, Database Management Systems Spring 2018 Lecture 20 Transactions These slides are based on Database System Concepts 6 th edition book (whereas some quotes and figures are used from the book) and

More information

Introduction to Bottom-Up Parsing

Introduction to Bottom-Up Parsing Introduction to Bottom-Up Parsing Lecture 11 CS 536 Spring 2001 1 Outline he strategy: shift-reduce parsing Ambiguity and precedence declarations Next lecture: bottom-up parsing algorithms CS 536 Spring

More information

Strings(2) CS 201 String. String Constants. Characters. Strings(1) Initializing and Declaring String. Debzani Deb

Strings(2) CS 201 String. String Constants. Characters. Strings(1) Initializing and Declaring String. Debzani Deb CS 201 String Debzani Deb Strings(2) Two interpretations of String Arrays whose elements are characters. Pointer pointing to characters. Strings are always terminated with a NULL characters( \0 ). C needs

More information

Functions and text files

Functions and text files Functions and text files Francesco Vespignani DiSCoF Università degli Studi di Trento. francesco.vespignani@gmail.com December 3, 2009 Today Functions and Scripts Latex Strings Text Files Practice Function

More information

Lecture 3: C Programm

Lecture 3: C Programm 0 3 E CS 1 Lecture 3: C Programm ing Reading Quiz Note the intimidating red border! 2 A variable is: A. an area in memory that is reserved at run time to hold a value of particular type B. an area in memory

More information

11/3/71 SYS BREAK (II)

11/3/71 SYS BREAK (II) 11/3/71 SYS BREAK (II) break -- set program break SYNOPSIS sys break; addr / break = 17. break sets the system s idea of the highest location used by the program to addr. Locations greater than addr and

More information

Transactions. CS 475, Spring 2018 Concurrent & Distributed Systems

Transactions. CS 475, Spring 2018 Concurrent & Distributed Systems Transactions CS 475, Spring 2018 Concurrent & Distributed Systems Review: Transactions boolean transfermoney(person from, Person to, float amount){ if(from.balance >= amount) { from.balance = from.balance

More information

Working with the Soft Properties Manager

Working with the Soft Properties Manager CHAPTER 3 These topics describe the Soft Properties Manager working environment and how to access Soft Properties Manager tools. In addition, it describes the process from creating to publishing a soft

More information

Lab 1 Introduction to MATLAB and Scripts

Lab 1 Introduction to MATLAB and Scripts Lab 1 Introduction to MATLAB and Scripts EE 235: Continuous-Time Linear Systems Department of Electrical Engineering University of Washington The development of these labs was originally supported by the

More information

Review: Classes and Object Instances. Review: Creating an Object. Using Multiple Objects. DrawingGizmo pencil; pencil = new DrawingGizmo();

Review: Classes and Object Instances. Review: Creating an Object. Using Multiple Objects. DrawingGizmo pencil; pencil = new DrawingGizmo(); Review: Classes and Object Instances ; = new (); Class #05: Objects, Memory, & Program Traces Software Engineering I (CS 120): M. Allen, 12/13 Sept. 17 We are working with both a class () and an object

More information

Getting started with MATLAB

Getting started with MATLAB Getting started with MATLAB You can work through this tutorial in the computer classes over the first 2 weeks, or in your own time. The Farber and Goldfarb computer classrooms have working Matlab, but

More information

Lab 8: Conditional Statements with Multiple Branches (please develop programs individually)

Lab 8: Conditional Statements with Multiple Branches (please develop programs individually) ENGR 128 Computer Lab Lab 8: Conditional Statements with Multiple Branches (please develop programs individually) I. Background: Multiple Branching and the if/if/ structure Many times we need more than

More information

ENGR 105: Introduction to Scientific Computing. Dr. Graham. E. Wabiszewski

ENGR 105: Introduction to Scientific Computing. Dr. Graham. E. Wabiszewski ENGR 105: Introduction to Scientific Computing Machine Model, Matlab Interface, Built-in Functions, and Arrays Dr. Graham. E. Wabiszewski ENGR 105 Lecture 02 Answers to questions from last lecture Office

More information

Chapter 5 Errors. Bjarne Stroustrup

Chapter 5 Errors. Bjarne Stroustrup Chapter 5 Errors Bjarne Stroustrup www.stroustrup.com/programming Abstract When we program, we have to deal with errors. Our most basic aim is correctness, but we must deal with incomplete problem specifications,

More information

S206E Lecture 19, 5/24/2016, Python an overview

S206E Lecture 19, 5/24/2016, Python an overview S206E057 Spring 2016 Copyright 2016, Chiu-Shui Chan. All Rights Reserved. Global and local variables: differences between the two Global variable is usually declared at the start of the program, their

More information

EW7 Assignment: (FCN) Functions

EW7 Assignment: (FCN) Functions EW7 Assignment: (FCN) Functions The purpose of this assignment is to introduce the concepts and syntax of writing functions in MATLAB. Note: Use the template provided (FCN Template.m) in the assignment

More information

Master of Science in Engineering 29 September 2004 University of Uppsala 29 September Wanda for MATLAB

Master of Science in Engineering 29 September 2004 University of Uppsala 29 September Wanda for MATLAB UPTEC IT0422 Thesis Report Examensarbete 20 p Master of Science in Engineering 29 September 2004 University of Uppsala 29 September 2004 Wanda for MATLAB Methods and Tools for Statistical Handling of Poisson

More information