Chapter 9: MuPAD Programming II Procedures MATLAB for Scientist and Engineers Using Symbolic Toolbox.

Slides:



Advertisements
Similar presentations
A MATLAB function is a special type of M-file that runs in its own independent workspace. It receives input data through an input argument list, and returns.
Advertisements

Chapter 11: Symbolic Computing for Calculus
Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
Chapter 6: MuPAD Objects II Sequence, List, Set, Function MATLAB for Scientist and Engineers Using Symbolic Toolbox.
Lecture 16 Subroutine Calls and Parameter Passing Semantics Dragon: Sec. 7.5 Fischer: Sec Procedure declaration procedure p( a, b : integer, f :
Debugging What can debuggers do? Run programs Make the program stops on specified places or on specified conditions Give information about current variables’
The Web Warrior Guide to Web Design Technologies
 2005 Pearson Education, Inc. All rights reserved Introduction.
Example 2.
Lecture 7 Sept 17 Goals: Complete Chapter 4 Chapters 5 and 6.
COMP 14 Introduction to Programming Miguel A. Otaduy May 25, 2004.
Overview creating your own functions calling your own functions.
Collaboration Diagrams. Example Building Collaboration Diagrams.
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 8, 2005.
Division Example 2x - 3y + 4z = 10 x + 6y - 3z = 4 -5x + y + 2z = 3 A*X = B where A = B = >> X = A\B X =
Promoting Code Reuse Often in programming, multiple procedures will perform the same operation IN OTHER WORDS – the same piece of code will do the same.
1 Gentle Introduction to Programming Tirgul 2: Scala “hands on” in the lab.
Chapter 6: Function. Scope of Variable A scope is a region of the program and broadly speaking there are three places, where variables can be declared:
CMPE-013/L: “C” Programming Gabriel Hugh Elkaim – Spring 2012 CMPE-013/L Functions Gabriel Hugh Elkaim Spring 2012.
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.
Programming For Nuclear Engineers Lecture 12 MATLAB (3) 1.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Subroutines in Computer Programming Svetlin Nakov Telerik Corporation
Reusable parts of Code Doncho Minkov Telerik Software Academy academy.telerik.com Technical Trainer
1 Web-Enabled Decision Support Systems Objects and Procedures Don McLaughlin IE 423 Design of Decision Support Systems (304)
Chapter 3: Formatting MuPAD Documents MATLAB for Scientist and Engineers Using Symbolic Toolbox.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
Project 1 Due Date: September 25 th Quiz 4 is due September 28 th Quiz 5 is due October2th 1.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
Programming Languages Meeting 6 September 30, 2014 October 1, 2014.
Chapter 2: First Steps in MuPAD MATLAB for Scientist and Engineers Using Symbolic Toolbox.
SUNY-New Paltz Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz “Lecture 6”
Functions, Procedures, and Abstraction Dr. José M. Reyes Álamo.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (there is an audio component to this eLesson) © Dr.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Allegro CL Certification Program Lisp Programming Series Level I Session Basic Lisp Development in the IDE.
Python Functions.
Covenant College November 27, Laura Broussard, Ph.D. Professor COS 131: Computing for Engineers Chapter 5: Functions.
Recap Saving Plots Summary of Chapter 5 Introduction of Chapter 6.
Chapter 8: MuPAD Programming I Conditional Control and Loops MATLAB for Scientist and Engineers Using Symbolic Toolbox.
1 Chapter 6 Methods. 2 Motivation Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively.
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python Karsten Hokamp, PhD Genetics TCD, 03/11/2015.
Chapter Functions 6. Modular Programming 6.1 Modular Programming Modular programming: breaking a program up into smaller, manageable functions or modules.
1 Variable Declarations Global and special variables – (defvar …) – (defparameter …) – (defconstant …) – (setq var2 (list 4 5)) – (setf …) Local variables.
By Mr. Muhammad Pervez Akhtar
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 3: Chapter 3: Slide 1 Unit 3 Formatting Chapter 3 Input, Variables, Constants,
ECE 103 Engineering Programming Chapter 31 C Scopes Herbert G. Mayer, PSU CS Status 8/1/2015 Initial content copied verbatim from ECE 103 material developed.
C# Programming Methods.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Programming Fundamentals Enumerations and Functions.
FUNCTIONS (C) KHAERONI, M.SI. OBJECTIVE After this topic, students will be able to understand basic concept of user defined function in C++ to declare.
Creating a script create new blank document. Editor options Docking and undocking tabs.
CSC 1010 Programming for All Lecture 5 Functions Some material based on material from Marty Stepp, Instructor, University of Washington.
Unit 10 Code Reuse. Key Concepts Abstraction Header files Implementation files Storage classes Exit function Conditional compilation Command-line arguments.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 4.
The Selection Structure
Organization of Programming Languages
Basic operations in Matlab
Functions CIS 40 – Introduction to Programming in Python
Functions.
Scripts & Functions Scripts and functions are contained in .m-files
Microsoft Access Illustrated
User Defined Functions
Chapter 5 - Functions Outline 5.1 Introduction
Predefined Functions Revisited
Corresponds with Chapter 5
Presentation transcript:

Chapter 9: MuPAD Programming II Procedures MATLAB for Scientist and Engineers Using Symbolic Toolbox

You are going to See that MuPAD provides built-in editor for programming Implement simple MuPAD procedures Use local variables inside the procedures Handle variable number of arguments to procedures 2

Using MuPAD Editor Invoking MuPAD Editor Auto-indentation: TAB Comments: //, /*.. */ 3

Bookmarks Add Bookmarks Go to the Bookmark Delete all Bookmarks 4

Creating a Procedure proc - procedure 5 Name of the procedure Body Suppress the procedure definition message or just end factorial.mu

Using the Procedure Read-in the MuPAD file. 6 factorial.mu

Return Value By default, a procedure returns the result of the last executed command. Use the return command for other results. 7

Returning Multiple Results Any MuPAD object can be returned. 8

Exercise Implement a procedure maximum(a, b) returning the maximum value of two arguments. 9

Local Variables You can declare an arbitrary number of local variables by specifying a sequence of identifiers after local keyword. If you don't use local keyword for a variable, it becomes global variable. 10 Local Variable DO NOT FORGET to initialize all the local variables! DO NOT FORGET to initialize all the local variables!

Global Variables Do not use Global Variables! If you must, save it first. 11 To use more decimal digits inside the procedure. To use more decimal digits inside the procedure.

Default Values for Arguments You can give a default value for an argument. 12 default value with argument without argument

error Function 13 Aborts with the message.

Sub-procedure Local procedure inside a procedure 14 g() is visible only inside this procedure. g() is visible only inside this procedure.

Type Declaration Specify the type of input argument 15 Accepts only non-negative integers.

Variable Number of Arguments System function max Accessing arguments 16

Simulating System Function max 17

Var. No. of Args : More Examples You may use both formal parameters and accesses via args in a procedure: Returns itself symbolically. 18

Exercise Write a short procedure date that takes three integers month, day, year as input and prints the date in the usual way. For example, the call date(5, 3, 1990) should yield the screen output 5/3/

Exercise We define the function f : N → N by The “ (3 x + 1) problem” asks whether for an arbitrary initial value x 0 ∈ N, the sequence recursively defined by x i +1 := f(x i ) contains the value 1. Write a program that on input x 0 returns the smallest index i with x i = 1. 20

option noExpose You can hide your code and publish it. 21

Start Debugging Menu  Notebook  Debug Command 22

Debug Control 23 Step Over Step Into Step Out Continue Toggle Breakpoint Watch Evaluate

Modifying Source File  New Editor … Re-read the file or Copy & Paste to the Notebook. 24

Key Takeaways Now, you are able to use MuPAD editor for writing your procedures, implement simple procedures and specify return values deal with the variable number of arguments perform type checking on the input arguments. and debug your procedures. 25

Notes 26

Notes 27

Notes 28