12.010 Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room 54-618, Chris Hill, Room 54-1511,

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Introduction to C Programming
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Matlab Intro Simple introduction to some basic Matlab syntax. Declaration of a variable [ ] Matrices or vectors Some special (useful) syntax. Control statements.
C Language.
ARDUINO CLUB Session 1: C & An Introduction to Linux.
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.
Programming and Data Structure
Engineering EG167C - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect M1 P. 1Winter Quarter Midterm I Review.
Single Variable and a Lot of Variables The declaration int k; float f; reserve one single integer variable called k and one single floating point variable.
Lecture 2 Introduction to C Programming
Introduction to C Programming
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 19P. 1Winter Quarter MATLAB: Script and.
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/29/2003.
Fall 2006AE6382 Design Computing1 Matlab File & Directory Management Learning Objectives Define file input and output terminology Compare high and low.
Guide To UNIX Using Linux Third Edition
Chapter 8 Arrays and Strings
Guide To UNIX Using Linux Third Edition
Introduction to C Programming
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
Functions UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative Commons.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
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.
MATLAB Lecture One Monday 4 July Matlab Melvyn Sim Department of Decision Sciences NUS Business School
IE 212: Computational Methods for Industrial Engineering
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
C Programming Tutorial – Part I CS Introduction to Operating Systems.
Chapter 8 Arrays and Strings
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
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.
Introduction to MATLAB Session 3 Simopekka Vänskä, THL Department of Mathematics and Statistics University of Helsinki 2011.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room , Chris Hill, Room ,
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
Advanced Topics- Functions Introduction to MATLAB 7 Engineering 161.
COMP 116: Introduction to Scientific Programming Lecture 11: Functions.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Chapter 6 Review: User Defined Functions Introduction to MATLAB 7 Engineering 161.
Covenant College November 27, Laura Broussard, Ph.D. Professor COS 131: Computing for Engineers Chapter 5: Functions.
1 CS161 Introduction to Computer Science Topic #9.
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
COMP 116: Introduction to Scientific Programming Lecture 29: File I/O.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Digital Image Processing Lecture 6: Introduction to M- function Programming.
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Lecture 15: Course Review BJ Furman ME 30 16MAY2011.
Higher Computing Science 2016 Prelim Revision. Topics to revise Computational Constructs parameter passing (value and reference, formal and actual) sub-programs/routines,
Introduction to Literate Programming in Matlab 2WN50 – Week programming-in-matlab.pptx?dl=0.
Scott Marino MSMIS Kean University MSAS5104 Programming with Data Structures and Algorithms Week 1 Scott Marino.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
Introduction to CMex E177 April 25, Copyright 2005, Andy Packard. This work is licensed under the Creative.
ENG College of Engineering Engineering Education Innovation Center 1 Functions 2 in MATLAB Topics Covered: 1.Functions in Script Files Inline Functions.
Array and Pointers An Introduction Unit Unit Introduction This unit covers the usage of pointers and arrays in C++
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
User-Written Functions
Matlab Training Session 4: Control, Flow and Functions
Lecture: MATLAB Chapter 1 Introduction
Scripts & Functions Scripts and functions are contained in .m-files
User Defined Functions
Computational Methods of Scientific Programming
Functions In Matlab.
File I/O in C Lecture 7 Narrator: Lecture 7: File I/O in C.
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Introduction to C Programming
Presentation transcript:

Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room , Chris Hill, Room , Web page 10/28/ Lec 15

10/28/ Lec 152 Summary of Introduction to Matlab Looked at the basic features of Matlab: –Getting help –Variable definitions and usage –Math operators –Control statements: Syntax is available through the online help –M-files: Script and function types Variable number of input and output arguments

10/28/ Lec 153 Today’s Lecture Continue examining Matlab operations path and addpath commands Variables and constants IO using fopen, scanf etc. Formats Dialog boxes

10/28/ Lec 154 Multidimensional cells and structures Cell arrays are similar to multidimensional arrays except that the all the cells do not need to be same e.g., a{1,1} = [ 1 2 ; 4 5]; a{1,2} = ‘Name’; a{2,1} = 2-4i; Structure arrays also exist and are accessed and created similar to C (i.e., elements are referred to by. construction patient.name = ‘John Doe’; patient.age = 32; These are recent features added to Matlab and can be useful in many applications but we will not discuss further.

10/28/ Lec 155 Program Layout Matlab can be run interactively; with script M-files as we have been doing; and/or function M-files It is possible to execute C-compiled routines called MEX files (for speed) but we will not cover this (system dependent) PC Matlab supports Word Notebooks but not available on Unix or Mac. helpwin on all systems invokes the help system tour and demo give a tour and demo of Matlab

10/28/ Lec 156 Function M-files Function M-files can have multiple inputs and outputs The generic construction is (in an M-file whose name is that of the function.m) function y = flipud(x) % FLIPUD Flip a matrix up/down % Comments about function.. Actual code Name must begin with a letter First line is function declaration line First set of contiguous comment lines are for help First comment (H1 line) is searched with the lookfor command

10/28/ Lec 157 Function M-files 02 Usually name is capitalized in H1 line Functions can invoke M-file scripts (executed in function workspace) M-file can contain multiple functions that are sub- functions of main function in mfile Functions can have zero inputs and outputs nargin tells number of arguments passed in call nargout tells how many outputs given Normally input variables are not copied to function workspace but made readable. However, if there values are changed then they are copied

10/28/ Lec 158 Function M-files 03 Functions can accept variable and unlimited numbers of input variables by using varargin as the last argument Functions can have variable numbers of outputs used varargout. Use the command global to have variables shared between base workspace and function workspace (must be declared global in both places). Matlab lets you reach another workspace with the evalin function You can also use assignin to assign values in a workspace (not recommended)

10/28/ Lec 159 Path controls Matlab uses a path structure to tell it where to look for M-files In simple cases, all the m-file needed are in the directory from which Matlab runs but in more complex cases this is not possible The path command lists the current path The addpath command adds a new directory to the path (the current directory is always seached first) The pwd command can be used in the addpath command e.g., addpath(pwd) M-files can contain multiple functions but additional functions in M-file are available only to the main function of the M-file. In complex systems of analysis, where functions are put in M-files should be carefully considered.

10/28/ Lec 1510 Variables and constants In Matlab variables are passed into functions by address unless the values are changed, in which case they are copied in to the function workspace. Although most variables are stored as double precision in Matlab, they can be referred to as different types e.g., complex, logical. To create non-double precession array, the data type can be specificed in the ones, zeros functions e.g. IA=zeros(20,’int8’) whos shows the type of variable all, any, find implement logical expressions in array indexing. (See ops for more details) logical can be used to select elements from an array

10/28/ Lec 1511 IO: fopen, scanf, printf fopen opens a file and returns a file ID number (FID): Syntax is [fid,message]= fopen(‘filename’,’permissions’) If the open is not successful, fid returns as -1 Lec02_01_file.m gives a simple example of reading and plotting a data file. Data files used here are MIT GPS data processing. Example allows a number different features in Matlab to be explored.Lec02_01_file.m This M-file also shows the use of logical and plotting functions in Matlab.

10/28/ Lec 1512 FORMATS for scan and print The format structure in Matlab is very similar to C (and unix programs such as awk) Mostly these are used for outputting values Basic types (see details in Matlab On-line help) %f, %e, %g — floating point numbers %d — integer values %s, %c — String and single characters \n —newline (needed often at ends of format) \r — carriage return

10/28/ Lec 1513 Dialog boxes We can make the File selection even better in the example using a dialog box. The Matlab M-file Lec02_02_db.m shows an example of how we might do this.Lec02_02_db.m This example shows ways to get file names from a directory listing. At this point we try these features on Athena In the next two lectures, you will develop a Matlab program to manipulate data of this type.

10/28/ Lec 1514 Summary of Today’s class Continued examining Matlab operations path and addpath commands Variables and constants IO using fopen, scanf etc. Formats Dialog boxes Much of the lecture is spent actually using these features in the M-files that are included with the lecture.