PGR Computing Programming Skills


 Albert Samson Martin
 1 years ago
 Views:
Transcription
1 PGR Computing Programming Skills Dr. I. Hawke Introduction The purpose of computing is to do something faster, more efficiently and more reliably than you could as a human do it. One obvious point that is frequently lost is that there is nothing a computer can do that you, as a human cannot; the computer will just do it so much faster. Sooner or later you will find that no standard package will perform a task that you want to do. At which point, you can either fill in the gaps by hand, or you can try to make the computer do what you want. Any attempt at the latter is essentially programming; it is only useful if it saves you time. Because it takes time to learn how to programme and how to make a computer do what you want, nearly all programming tasks worth doing are 1. repetitive 2. time consuming 3. something you want done more than once. The last point is key, as although you may want the computer to do something more than once, it may be days, or months, or longer, between the times when you do the task for the first and second time. Why is this important? Because you will have forgotten how you did it the first time, so unless you have explained your code properly, you will have to start from scratch. This document gives you some ideas of how to think about programming. It will focus on some simple, mathematical examples. Some of the text is specific to MATLAB, but the theory should carry over to any computing task. 1
2 2 TACTICS 2 Tactics This section will focus on concrete small details that can massively ease the burden of reading and maintaining code. The aim should be that if you follow these guidelines in spirit, if not detail, then a somebody should be able to use and understand your code without any input from you. 2.1 Documentation Let us start with a simple example. The following MATLAB function should be very simple to understand: function c = MyDumbFunction(a, b) c = a / b; end When saved in the file MyDumbFunction.m this function can be called; it will return the result of the first number divided by the second. Example 1. Download this function from the website. Save the function in a place you can access. Launch MATLAB and ensure that the working directory contains this file (to change working directory, click the button with three dots... in the toolbar to the right of Current Directory ). Try calling the function with some numbers. For example, in the Command Window try MyDumbFunction(1, 2) Check that you get the expected answer for each case. 1 You can define vectors in MATLAB in a simple fashion, such as A = [1 2 3] B = [3 4 5] Try calling the function with a vector in an argument, such as MyDumbFunction(A, 2) MyDumbFunction(A, B) MyDumbFunction(1, A) 1 Note that if you get bored of typing MyDumbFunction all the time then MATLAB has a name completion utility. Try typing the first couple of letters of the function and pressing the TAB key. 2
3 2 TACTICS 2.1 Documentation Can you explain the results? Defining a matrix in MATLAB is also simple: C = [1 2; 3 4] Experiment and see when and how the matrix can be used as an argument to this function. Finally, try MyDumbFunction(1, 0) What do you think the function should do in this case? By the end of the previous example you should be very bored of typing MyDumbFunction. More to the point, you will probably have almost forgotten what this function actually does. The name of the function gives you no idea as to its purpose. The file contains no information, and no useful help statements. The only way of understanding the purpose of this function is to read and understand the code. As the example above showed, there can be pitfalls in calling even the simplest code that you might not immediately think of. If you can start to lose any idea of the purpose and pitfalls of a simple function after just a few minutes, then you can easily imagine the problem with complex functions over days, weeks or months. The answer to this is documentation. Documentation starts with having sensible names for functions and variables, and continues by including easytofind help statements and code comments. Example 2. Modify the function MyDumbFunction so that the function and variables have sensible names. Once you have done that we want to include helpful comments. In the MAT LAB window try typing help plot. This prints to the screen a long comment describing and explaining how to use the inbuilt MATLAB function plot, what the arguments mean, what values it returns, what the options are, and where to get more help. MATLAB allows you to do this for your own code as well. To include a comment in a MATLAB function it just has to start with the symbol. Any text placed after that will have no effect, and is a useful way of documenting the code. The first block of comments that appear at the top of the file, before the function statement, will be printed to the screen when the help mechanism is used. Add documentation to your renamed function. Check that it prints to the screen. See if your neighbour thinks it is sufficient. You can compare against the function MyDivide on the BLACKBOARD website. 3
4 2 TACTICS 2.2 Type checking 2.2 Type checking In example 1 we saw that the function MyDumbFunction, now renamed to MyDivide, would happily take any input even though the function was originally designed to work only with single real numbers. In some cases this made sense, such as dividing a matrix by a single number. In many it does not try the function with one argument the number 1 and the other the string rabbit. Many program languages are typed; that is, every variable must be declared to be a particular thing, such as an integer or a string of characters. In strongly typed languages then the arguments to all functions also have to be declared in advance. In these cases the problem of passing nonsense to a function is reduced (although, of course, not eliminated). MATLAB does not type its variables, except implicitly. This has its advantages in producing simple, flexible code. However, as we have seen, it has major disadvantages in producing robust code that will either always work, or will fail gracefully with an informative error message. Example 3. Take the function that you have produced in example 2. The aim is to modify this function to check its arguments so that it only works for single real numbers. This is a restriction that is not totally necessary, but making a general function that knows when, for example, a matrix would work is unnecessarily complex for now. The key functions that we want to use here are the functions isscalar and isnumeric or isreal. All of these are logical functions returning either true or false 2, and each checks for the obvious thing. If the input is not what we want then the function should report an error and stop this can be done in a simple way using the input error function. Modify your function so that it checks the input. Make sure that each argument is a single real number. If it is not, report an appropriate error. 2.3 Graceful failure Another point seen in example 1 was that division by 0 returned Inf, the floating point representation of infinity. Whilst this may be correct, it may not necessarily be exactly what we want. We should also note that a similar thing would happen 2 In common with the C programming language, true can alternatively be interpreted numerically as 1 and false as 0. It is wise not to rely on this behaviour across programming languages as it will sometimes work and sometimes not occasionally it will vary depending on the implementation of a programming language. 4
5 2 TACTICS 2.3 Graceful failure if we tried to divide by any sufficiently small number (that MATLAB could not distinguish from 0 in terms of its floating point representation). In particular, consider what would happen if we wanted to use this function as part of a more complex algorithm. If some general function was expecting a standard real number to be returned by MyDivide and used it directly, then a simple error in the input could render this assumption invalid. It may be the case that we assume that the divisor is never equal to zero; therefore, if a number is passed through which MATLAB believes to be zero, that this is merely a failure of the floating point representation. We would then have to adjust the algorithm in some way. One simple adjustment would be to say that if the absolute value of the divisor were less than some small number, the divisor is taken to be that small number (with the appropriate sign). Example 4. The aim will be to modify the function MyDivide so that it fails gracefully. There will be two options. 1. The function can be called with two arguments, as above, and it will check to see if the divisor is too close to zero. If so it will fail with a meaningful error message. 2. The function will be called with three arguments, with the third giving the small number that will be used if necessary. To check how close a number is to zero (or indeed to any floating point number), MATLAB has the intrinsic function eps. The gives the gap to the next number that MATLAB can tell to be different. So eps(0) gives the smallest number that can be distinguished from zero. For safety, you should probably check that the Divisor is at least some multiple, say 10, of this number. The use of an optional argument in MATLAB is straightforward. You just write the function out with all the possible arguments it might receive (in this case 3: Numerator, Divisor, threshold) and, when the optional argument is not required just call it with two. Inside the function the variable nargin will give the number of arguments that the function was called with. If the optional argument was not provided then it is good programming practise to give the variable a value anyway. Modify your function so that it will now fail gracefully as suggested; an example is given in MyGracefulDivide.m. 5
6 2 TACTICS 2.4 Too many options 2.4 Too many options In the previous section we ended up adding an argument to our function. This allowed the function to fail gracefully, which is always good, but it does make the logic of the function less intuitive. The function is meant to divide two numbers yet it has three arguments. This is not necessarily a problem the argument is optional and so the function can still be used in an intuitive fashion but it may indicate the thin end of the wedge. What if there are lots of possible ways to modify the behaviour of a function? Do we have to keep expanding the possible arguments that the function might take? It should be clear that this cannot work. Imagine if there are two optional paths that the function might take. If we declare the function as function Ratio = MySillyDivide(Numerator, Divisor,... option1, option2) then we can only distinguish between option1 and option2 by their position in the argument list. That is, if we want to take the second option we always have to pass through a value corresponding to the first, even though we will never use it! This sort of programming is nonintuitive and very cumbersome as the number of arguments to the function increases, and should be avoided wherever possible. One alternative 3 is to pass only one additional variable which, as above, will be optional. This variable will however contain all the information on the possible options. These are often called option tables, and can be built in Matlab using structures. An option table is typically a single variable, often called options, which contains a list of variables with their value. This value can be anything; numbers, strings, etc. The variables (called the fields of the structure) are set and accessed using a. : options.name = My name options.mark = 20 A = options.mark The last line sets A to 20. Clearly we can set any number of options inside a structure (options table) and then just pass the one variable to the routine. This bypasses the problem with passing multiple options; all that is needed is, within the function, to check whether the option has been set and if so to what value. The function isfield is used to see if an option has been set within the options table. 3 An alternative is to use the variable argument list; take a look at the varargin function. This is used, for example, by the MATLAB plot function, but I would not recommend it for your own codes. 6
7 2 TACTICS 2.5 Summary Example 5. Modify the function MyDivide so that it fails gracefully based on the (optional) parameters passed in the (optional) third argument. 1. If the option threshold is set then the function behaves as in example If the option threshold is not set but the option my infinity is, then if the divisor is too close to zero the value of my infinity should be returned. An example that implements this is given in MyOptionalDivide.m. Note that when you test this function you have to be careful to remove the value of threshold from the options table, as it takes precedence over my infinity. To do this use options = rmfield(options, threshold ); or similar. 2.5 Summary 1. Make all function names, variables, etc. meaningful. 2. Add comments to your function; in particular add a header comment. 3. Check the inputs to your function; if they do not meet your expectations give a helpful error message. 4. Make everything as intuitive as possible by minimizing extra arguments. 7
8 3 STRATEGY 3 Strategy The previous section concentrated on the lowlevel: how to write code that really did things, and how to do it in a way that can be easily understood and maintained. However, there is far more to writing good, easy to maintain programs that the low level tactics that we have looked at so far. In many ways the most important thing is to have a clear strategy of what you want to achieve, and to structure your code in a logical fashion based on that strategy. Often people are happy to fill in the gaps in how you are trying to do something, but only if it is obvious to them what you are trying to do. 3.1 Objects and variables In the previous section our task (dividing two numbers) was sufficiently simple that it was obvious how we would do it. With most programming tasks there is more than one way of approaching the problem, and some thought about what you are trying to do and how you are trying to do it can lead to large benefits, both in how you think about your code and how you explain it. An example comes by looking at a simple polynomial, y(x) = a 0 + a 1 x + a 2 x a N x N N = a i x i. i=0 (1a) (1b) Starting from this viewpoint we have that the coefficients {a i } give a complete (and simple) description of the polynomial, and so a vector of N + 1 numbers containing these coefficients is sufficient to completely describe the polynomial. From this we can create a computer code that manipulates the coefficients directly to, e.g., evaluate this polynomial or its derivatives at a point, or to divide it by another polynomial. But with further thought we can easily see that there may be other, potentially better ways of describing the polynomial. For example, the monomial form y(x) = a N N i=0 (x b i ) (2) immediately gives you information about the roots of the equation, and the form y(x) = a N D i=0 (x b i ) m i (3) 8
9 3 STRATEGY 3.2 Planning and PseudoCode gives total information about the roots and their multiplicities. These sorts of forms are very useful when dealing with polynomials with multiple roots, or where distinct roots lie very close to each other. Another alternative is the nested form y(x) = α 0 + x (α 1 + x (α x (α N 1 + xα N )... )) (4) which ensures that the polynomial can be evaluated with the minimum number of operations, which helps numerical stability. Which is the best representation? The answer is problem dependent. If you have to accurately evaluate a polynomial or its derivatives many times, e.g. using Horner s Algorithm, then you need the form of equation (4). If you are interested in the behaviour near roots or their properties, then you need the form of equation (3). It is rare that the simple forms of equation (1) will be what you want. For a quick, single purpose project that is all the information that you need. You decide on the representation of the polynomial based on the problem that you want to solve. You write your code for that representation, taking care to explain both the representation itself and the aspects of it that your code relies on. For a general project you think more deeply. The object that you are interested in is the polynomial, not its representation(s). There are many things that you might want to use a polynomial for, or operations that you want to apply to it. So there may be a variety of representations that you want to be able to use, in order to simplify the operations or algorithms that you apply. In a sense, this is like tensors and coordinate systems. The object is the tensor, which does not know (or care) about coordinates. Operations are in theory applied to the object. However, in practice it is often easier to concretely apply an operation in a given coordinate system. By being able to convert between representations, and by carefully separating out the objects from their representations, the big picture of your code will be easier to understand, debug, modify and extend. This idea of focussing on objects is at the core of Object Oriented Programming, which is now sufficiently old to have been absorbed into most programming languages and packages. Further techniques that make your life easier, such as inheritance, can be read about in many standard texts. (Inheritance is the idea that an object can live in many classes. For example, a shape object can be moved around or duplicated. A circle is a shape object with extra information, so can be moved around or duplicated using code written for a general shape object) 3.2 Planning and PseudoCode You will normally start with a task that you want to accomplish but only a limited amount of detail of the steps to take. The first stage, before writing code, is to 9
10 3 STRATEGY 3.2 Planning and PseudoCode plan what you are going to do. A useful technique that is often recommended, either once you have a plan or to help build one, is to go through a series of handwritten steps, starting from the big picture. At each stage you write down what you want the code to do. You then break each step into smaller steps that will accomplish this. An advantage of this technique is that you should by the end automatically have the appropriate comments to explain your code (although often the code produced should be sufficiently straightforward that the comments required are minimal). As an example we shall consider a simple task: to write a function that takes a matrix and returns the eigenvector corresponding to the eigenvalue with largest absolute value. There does in fact already exist a MATLAB command that does almost exactly this (eigs), but we shall ignore that in the following 4. We start by writing exactly what we want to do as a MATLAB comment. function V = maxeigenvector(a) This will be a function that will return the eigenvector corresponding to the eigenvalue with largest absolute value. We then want to be a bit more concrete as to what we are actually doing, by defining the input and output. function V = maxeigenvector(a) Input : a square matrix A. Output: the eigenvector V corresponding to the eigenvalue with largest absolute value. In the case where there are multiple eigenvalues with largest absolute value, this will be the first one found. This will be a function that will return the eigenvector corresponding to the eigenvalue with largest absolute value. As you can see we have already made two choices. The first is that we have restricted the input to square matrices. As we have restricted the input, we should put a check in the code on the input: function V = maxeigenvector(a) 4 The eigs command returns the largest eigenvalues and their associated eigenvectors usually the largest six. However, it can return confusing results if there is not a unique eigenvalue that has largest absolute value. 10
11 3 STRATEGY 3.2 Planning and PseudoCode Input : a square matrix A. Output: the eigenvector V corresponding to the eigenvalue with largest absolute value. In the case where there are multiple eigenvalues with largest absolute value, this will be the first one found. Check that A is a square matrix. This will be a function that will return the eigenvector corresponding to the eigenvalue with largest absolute value. Secondly we have chosen what should happen in the complicated case where there are multiple eigenvalues with maximum absolute value. At this stage we need to reduce each stage in our pseudocode to something more basic. We currently have two steps: checking the input and the body of the function itself. We start with the input checking step and break this down: function V = maxeigenvector(a)... Check that A is a square matrix. Check that A is numerical (and not a string or a structure) Check that A is a matrix (and not, for example, 3 dimensional) Check that A is square This will be a function that will return the eigenvector corresponding to the eigenvalue with largest absolute value. Each of the three steps is sufficiently simple that you should expect there to be a MATLAB function for each, and indeed there is: isnumeric, ndims, and size do the job. At this point we can turn the pseudocode in to real code as in the following: function V = maxeigenvector(a)... Check that A is a square matrix. if (not(isnumeric(a))) error( The input to maxeigenvector is not a numeric matrix! ) 11
12 3 STRATEGY 3.2 Planning and PseudoCode end if (ndims(a) = 2) error( The input to maxeigenvector is not a 2dimensional... matrix! ) end if (size(a,1) = size(a,2)) error( The input to maxeigenvector is not a square matrix! ) end This will be a function that will return the eigenvector corresponding to the eigenvalue with largest absolute value. As you can see we have removed the low level comments as the code is sufficiently selfexplanatory. A similar procedure is applied to the actual body of the code. The steps that I would take are: function V = maxeigenvector(a)... This will be a function that will return the eigenvector corresponding to the eigenvalue with largest absolute value. followed by function V = maxeigenvector(a)... This will be a function that will return the eigenvector corresponding to the eigenvalue with largest absolute value. First compute the eigenvalues and associated eigenvectors of A Next find the maximum eigenvalue (by absolute value) Finally return the associated eigenvector. Again there are MATLAB functions or operations to do each of these steps; eig, abs, max, and array subscripting are required: function V = maxeigenvector(a)... 12
13 3 STRATEGY 3.3 Optimization This will be a function that will return the eigenvector corresponding to the eigenvalue with largest absolute value. First compute the eigenvalues and associated eigenvectors of A We should note that D1 is a MATRIX containing the eigenvalues on the diagonal. [V1,D1] = eig(a); Next find the maximum eigenvalue (by absolute value) The maximum absolute value is in C, but we do not care about it. The index array I gives the location of the maximum. [C,I] = max(abs(d1)); Finally return the associated eigenvector. V = V1(:, I(1)); 3.3 Optimization Optimization is the art of making your program run faster. According to the old saying there are two rules about optimization: 1. Don t do it. 2. (For experts only): Don t do it yet. The reason for this is encapsulated in another old saying: Premature optimization is the root of all evil. Both are exaggerated, but hold more than a grain of truth. The key reason for this is the truism is that optimization saves computer time, whereas you should be interested in saving person time. If it takes you 2 hours to improve a code that then runs in 10 minutes instead of 20 then you have lost time, not gained (unless, of course, you need to run the code many times). Most often you will find a good planning will minimize additional overhead. However, there are a few additional points that are MATLAB specific Vector operations MATLAB naturally applies operations to vectors and matrices wherever possible, such as > x = 0:0.01:4; > s = sin(x); 13
14 3 STRATEGY 3.3 Optimization The second line could have been written using a loop over the elements of the array s: > x = 0:0.01:4; > for i = 1:401 > s(i) = sin(x(i)); > end The use of a loop is, in some cases, more natural. However, it is usually less transparent (it certainly is above) and it imposes more structure than necessary: in the example above it is irrelevant in what order the operations take place, but by using a loop we have imposed an order, and this order may not be the fastest. By using vector operations we allow MATLAB to choose the fastest possible method Growing vectors The loop above has more problems in terms of efficiency. The problem is that the vector s has no definite size before the loop starts. Therefore every time the loop is executed MATLAB has to perform the following steps: 1. I am being asked to assign a value to s(i). 2. Does the vector s already have i elements? 3. No. 4. Therefore I must increase the size of s to contain i elements. 5. Then I assign a value to s(i). Although this is not the precise algorithm it uses, you see the problem: there is much more work than necessary having to go on inside the loop. Instead it is fastest to say before the loop what size s needs to be. The standard method for doing this is to initialize the vector (or array) to the zero vector (array) with the appropriate size; therefore a better loop structure is > x = 0:0.01:4; > s = zeros(size(x)); > for i = 1:401 > s(i) = sin(x(i)); > end Note that in other programming languages such as C or Fortran predefining the size of an array is often necessary, and indexing outside of the array will lead to failure at compilation time (if you are lucky), a code crash (in most cases), or garbage results (if you are really unlucky). 14
15 3 STRATEGY 3.3 Optimization Use specialist tools If you have no choice but to optimize (if the program would take more time than you could possibly have available) then the first thing is to find out what part of your code takes the time. In MATLAB there is the Profiler, which will return detailed information on your script. To launch the profiler, go to the Editor and from the Tools menu select Open Profiler. There is considerable online help, but its use is straightforward. 15
Introduction. Chapter 1
Chapter 1 Introduction MATLAB (Matrix laboratory) is an interactive software system for numerical computations and graphics. As the name suggests, MATLAB is especially designed for matrix computations:
More informationProgramming Languages & Tools
4 Programming Languages & Tools Almost any programming language one is familiar with can be used for computational work (despite the fact that some people believe strongly that their own favorite programming
More informationCHAPTER 3 Numbers and Numeral Systems
CHAPTER 3 Numbers and Numeral Systems Numbers play an important role in almost all areas of mathematics, not least in calculus. Virtually all calculus books contain a thorough description of the natural,
More informationTECHNOLOGY Computer Programming II Grade: 912 Standard 2: Technology and Society Interaction
Standard 2: Technology and Society Interaction Technology and Ethics Analyze legal technology issues and formulate solutions and strategies that foster responsible technology usage. 1. Practice responsible
More informationHypercosm. Studio. www.hypercosm.com
Hypercosm Studio www.hypercosm.com Hypercosm Studio Guide 3 Revision: November 2005 Copyright 2005 Hypercosm LLC All rights reserved. Hypercosm, OMAR, Hypercosm 3D Player, and Hypercosm Studio are trademarks
More informationExercise 4 Learning Python language fundamentals
Exercise 4 Learning Python language fundamentals Work with numbers Python can be used as a powerful calculator. Practicing math calculations in Python will help you not only perform these tasks, but also
More informationb) lower case always use lower case for all matlab commands. This is what matlab recognizes.
1 Matlab 1) Fundamentals a) Getting Help for more detailed help on any topic, typing help, then a space, and then the matlab command brings up a detailed page on the command or topic. For really difficult
More informationSolution of Linear Systems
Chapter 3 Solution of Linear Systems In this chapter we study algorithms for possibly the most commonly occurring problem in scientific computing, the solution of linear systems of equations. We start
More information10.3 POWER METHOD FOR APPROXIMATING EIGENVALUES
55 CHAPTER NUMERICAL METHODS. POWER METHOD FOR APPROXIMATING EIGENVALUES In Chapter 7 we saw that the eigenvalues of an n n matrix A are obtained by solving its characteristic equation n c n n c n n...
More informationCDROM Appendix E: Matlab
CDROM Appendix E: Matlab Susan A. Fugett Matlab version 7 or 6.5 is a very powerful tool useful for many kinds of mathematical tasks. For the purposes of this text, however, Matlab 7 or 6.5 will be used
More informationName: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.
Name: Class: Date: Exam #1  Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to
More information10.3 POWER METHOD FOR APPROXIMATING EIGENVALUES
58 CHAPTER NUMERICAL METHODS. POWER METHOD FOR APPROXIMATING EIGENVALUES In Chapter 7 you saw that the eigenvalues of an n n matrix A are obtained by solving its characteristic equation n c nn c nn...
More informationMATLAB Functions. function [Out_1,Out_2,,Out_N] = function_name(in_1,in_2,,in_m)
MATLAB Functions What is a MATLAB function? A MATLAB function is a MATLAB program that performs a sequence of operations specified in a text file (called an mfile because it must be saved with a file
More informationCryptography and Network Security Department of Computer Science and Engineering Indian Institute of Technology Kharagpur
Cryptography and Network Security Department of Computer Science and Engineering Indian Institute of Technology Kharagpur Module No. # 01 Lecture No. # 05 Classic Cryptosystems (Refer Slide Time: 00:42)
More informationIntroduction to Python
WEEK ONE Introduction to Python Python is such a simple language to learn that we can throw away the manual and start with an example. Traditionally, the first program to write in any programming language
More informationUserdefined Functions (UDFs)
Userdefined Functions (UDFs) In this lecture I will be introducing the programmation language Visual Basic for Applications (VBA) and explaining one particular use of it: creating UDFs. VBA is a powerful
More information[Refer Slide Time: 05:10]
Principles of Programming Languages Prof: S. Arun Kumar Department of Computer Science and Engineering Indian Institute of Technology Delhi Lecture no 7 Lecture Title: Syntactic Classes Welcome to lecture
More informationManifold Learning Examples PCA, LLE and ISOMAP
Manifold Learning Examples PCA, LLE and ISOMAP Dan Ventura October 14, 28 Abstract We try to give a helpful concrete example that demonstrates how to use PCA, LLE and Isomap, attempts to provide some intuition
More informationMatlab Tutorial Francesco Franco
Matlab Tutorial Francesco Franco Matlab is a software package that makes it easier for you to enter matrices and vectors, and manipulate them. The interface follows a language that is designed to look
More informationDynamics and Vibrations Mupad tutorial
Dynamics and Vibrations Mupad tutorial School of Engineering Brown University This tutorial introduces the MATLAB mupad environment for symbolic calculations. You should work through the MATLAB tutorial
More informationIntroduction to Statistics for Computer Science Projects
Introduction Introduction to Statistics for Computer Science Projects Peter Coxhead Whole modules are devoted to statistics and related topics in many degree programmes, so in this short session all I
More informationMAT 275 Laboratory 1 Introduction to MATLAB
MAT 275 Laboratory 1 Introduction to MATLAB MATLAB is a computer software commonly used in both education and industry to solve a wide range of problems. This Laboratory provides a brief introduction to
More informationWhile Loops and Animations
C h a p t e r 6 While Loops and Animations In this chapter, you will learn how to use the following AutoLISP functions to World Class standards: 1. The Advantage of Using While Loops and Animation Code
More information7 Time series analysis
7 Time series analysis In Chapters 16, 17, 33 36 in Zuur, Ieno and Smith (2007), various time series techniques are discussed. Applying these methods in Brodgar is straightforward, and most choices are
More informationWe will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.
LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.
More informationUSC Marshall School of Business Marshall Information Services
USC Marshall School of Business Marshall Information Services Excel Dashboards and Reports The goal of this workshop is to create a dynamic "dashboard" or "Report". A partial image of what we will be creating
More informationCourse 10550A: Programming in Visual Basic with Microsoft Visual Studio 2010 OVERVIEW
Course 10550A: Programming in Visual Basic with Microsoft Visual Studio 2010 OVERVIEW About this Course This course teaches you Visual Basic language syntax, program structure, and implementation by using
More information1 Short Introduction to Time Series
ECONOMICS 7344, Spring 202 Bent E. Sørensen January 24, 202 Short Introduction to Time Series A time series is a collection of stochastic variables x,.., x t,.., x T indexed by an integer value t. The
More informationLAB 1 REPRESENTATION OF NUMBERS AND INTRODUCTION TO C
LAB 1 REPRESENTATION OF NUMBERS AND INTRODUCTION TO C 1. LAB OBJECTIVE The objective of this lab is to review binary numbers and to review/introduce you to the C programming language and the MATLAB environment.
More informationA Concrete Introduction. to the Abstract Concepts. of Integers and Algebra using Algebra Tiles
A Concrete Introduction to the Abstract Concepts of Integers and Algebra using Algebra Tiles Table of Contents Introduction... 1 page Integers 1: Introduction to Integers... 3 2: Working with Algebra Tiles...
More informationCommon and Uncommon Standard Number Sets
Common and Uncommon Standard Number Sets W. Blaine Dowler July 8, 2010 Abstract There are a number of important (and interesting unimportant) sets in mathematics. Sixteen of those sets are detailed here.
More informationCOGNITIVE TUTOR ALGEBRA
COGNITIVE TUTOR ALGEBRA Numbers and Operations Standard: Understands and applies concepts of numbers and operations Power 1: Understands numbers, ways of representing numbers, relationships among numbers,
More informationChapter 6 Operators and Flow Control
Chapter 6 Operators and Flow Control 6.1. Relational and Logical Operators MATLAB has a logical data type, with the possible values 1, representing true, and 0, representing false. Logicals are produced
More informationVHDL Test Bench Tutorial
University of Pennsylvania Department of Electrical and Systems Engineering ESE171  Digital Design Laboratory VHDL Test Bench Tutorial Purpose The goal of this tutorial is to demonstrate how to automate
More informationFundamentals of Python: First Programs. Chapter 3: Control Statements modifications by Mr. Dave Clausen
Fundamentals of Python: First Programs Chapter 3: Control Statements modifications by Mr. Dave Clausen Objectives After completing this chapter, you will be able to: Write a loop to repeat a sequence of
More informationEuler s Method and Functions
Chapter 3 Euler s Method and Functions The simplest method for approximately solving a differential equation is Euler s method. One starts with a particular initial value problem of the form dx dt = f(t,
More informationVISUAL ALGEBRA FOR COLLEGE STUDENTS. Laurie J. Burton Western Oregon University
VISUAL ALGEBRA FOR COLLEGE STUDENTS Laurie J. Burton Western Oregon University VISUAL ALGEBRA FOR COLLEGE STUDENTS TABLE OF CONTENTS Welcome and Introduction 1 Chapter 1: INTEGERS AND INTEGER OPERATIONS
More informationMATLAB Tutorial. Chapter 6. Writing and calling functions
MATLAB Tutorial Chapter 6. Writing and calling functions In this chapter we discuss how to structure a program with multiple source code files. First, an explanation of how code files work in MATLAB is
More information1. A(n) structure is a logical design that controls the order in which a set of statements execute. a. function b. control c. sequence d.
Chapter Four MULTIPLE CHOICE 1. A(n) structure is a logical design that controls the order in which a set of statements execute. a. function b. control c. sequence d. iteration 2. The decision structure
More informationMachine Learning and Pattern Recognition Logistic Regression
Machine Learning and Pattern Recognition Logistic Regression Course Lecturer:Amos J Storkey Institute for Adaptive and Neural Computation School of Informatics University of Edinburgh Crichton Street,
More informationJava Application Developer Certificate Program Competencies
Java Application Developer Certificate Program Competencies After completing the following units, you will be able to: Basic Programming Logic Explain the steps involved in the program development cycle
More informationKS3 Computing Group 1 Programme of Study 2015 2016 2 hours per week
1 07/09/15 2 14/09/15 3 21/09/15 4 28/09/15 Communication and Networks esafety Obtains content from the World Wide Web using a web browser. Understands the importance of communicating safely and respectfully
More informationThe Factor Theorem and a corollary of the Fundamental Theorem of Algebra
Math 421 Fall 2010 The Factor Theorem and a corollary of the Fundamental Theorem of Algebra 27 August 2010 Copyright 2006 2010 by Murray Eisenberg. All rights reserved. Prerequisites Mathematica Aside
More information(Refer Slide Time: 1:42)
Introduction to Computer Graphics Dr. Prem Kalra Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture  10 Curves So today we are going to have a new topic. So far
More informationWe call this set an ndimensional parallelogram (with one vertex 0). We also refer to the vectors x 1,..., x n as the edges of P.
Volumes of parallelograms 1 Chapter 8 Volumes of parallelograms In the present short chapter we are going to discuss the elementary geometrical objects which we call parallelograms. These are going to
More informationVisual basic tutorial problems, developed by Dr. Clement,
EXCEL Visual Basic Tutorial Problems (Version January, 2011) Dr. Prabhakar Clement Arthur H. Feagin Distinguished Chair Professor Department of Civil Engineering, Auburn University Home page: http://www.eng.auburn.edu/users/clemept/
More information15.062 Data Mining: Algorithms and Applications Matrix Math Review
.6 Data Mining: Algorithms and Applications Matrix Math Review The purpose of this document is to give a brief review of selected linear algebra concepts that will be useful for the course and to develop
More informationIntroduction to Matlab
Information Technology Rice University Document UNIX 17 July 11, 2002 Introduction to Matlab Basic Matlab Commands and Syntax This document teaches the user how to create Matlab matrices, learn about Matlab
More information6 Scalar, Stochastic, Discrete Dynamic Systems
47 6 Scalar, Stochastic, Discrete Dynamic Systems Consider modeling a population of sandhill cranes in year n by the firstorder, deterministic recurrence equation y(n + 1) = Ry(n) where R = 1 + r = 1
More informationMATLAB Basics IV: mfiles and loops 1
MATLAB Basics IV: mfiles and loops 1 In this handout, we will work with M ATLAB programs called mfiles. For technical reasons that will be explained shortly, it is important that you start your M ATLAB
More informationAn Introduction to MATLAB Programming
An Introduction to MATLAB Programming Center for Interdisciplinary Research and Consulting Department of Mathematics and Statistics University of Maryland, Baltimore County wwwumbcedu/circ Winter 2008
More informationIntroduction to MATLAB
Introduction to MATLAB Matlab is a program that allows you to carry out computations in a straightforward manner, removing much of the tedium involved in programming. It is extremely useful for creating
More informationAlternate Appendix A: Using the TI89 Calculator
Alternate Appendix A: Using the TI89 Calculator This document summarizes TI89 calculation and programming operations as they relate to the text, Inside Your Calculator. Even those who do not read the
More informationAlgorithm & Flowchart & Pseudo code. Staff Incharge: S.Sasirekha
Algorithm & Flowchart & Pseudo code Staff Incharge: S.Sasirekha Computer Programming and Languages Computers work on a set of instructions called computer program, which clearly specify the ways to carry
More informationPowerPoints organized by Dr. Michael R. Gustafson II, Duke University
Part 1 Chapter 3 Programming with MATLAB PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright The McGrawHill Companies, Inc. Permission required for reproduction
More informationMATLAB Programming. Problem 1: Sequential
Division of Engineering Fundamentals, Copyright 1999 by J.C. Malzahn Kampe 1 / 21 MATLAB Programming When we use the phrase computer solution, it should be understood that a computer will only follow directions;
More informationMoving from CS 61A Scheme to CS 61B Java
Moving from CS 61A Scheme to CS 61B Java Introduction Java is an objectoriented language. This document describes some of the differences between objectoriented programming in Scheme (which we hope you
More information14:440:127 Introduction to Computers for Engineers. Notes for Lecture 01
14:440:127 Introduction to Computers for Engineers Notes for Lecture 01 Rutgers University, Spring 2010 Instructor Blase E. Ur 1 What Is Matlab? Matlab ( MATrix LABoratory ) is a software package and
More informationAMATH 352 Lecture 3 MATLAB Tutorial Starting MATLAB Entering Variables
AMATH 352 Lecture 3 MATLAB Tutorial MATLAB (short for MATrix LABoratory) is a very useful piece of software for numerical analysis. It provides an environment for computation and the visualization. Learning
More information(Refer Slide Time: 00:00:56 min)
Numerical Methods and Computation Prof. S.R.K. Iyengar Department of Mathematics Indian Institute of Technology, Delhi Lecture No # 3 Solution of Nonlinear Algebraic Equations (Continued) (Refer Slide
More informationDigital Electronics. 1.0 Introduction to Number Systems. Module
Module 1 www.learnaboutelectronics.org Digital Electronics 1.0 Introduction to What you ll learn in Module 1 Section 1.0. Recognise different number systems and their uses. Section 1.1 in Electronics.
More informationThomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation
Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science updated 03/08/2012 Unit 1: JKarel 8 weeks http://www.fcps.edu/is/pos/documents/hs/compsci.htm
More informationIV2Programming Overview
Chapter IV2 IV2Programming Overview Overview... 22 Organizing Procedures... 22 WaveMetrics Procedure Files... 23 Macros and Functions... 23 Scanning and Compiling Procedures... 24 Indentation Conventions...
More informationGoldSim Version 10.5 Summary
GoldSim Version 10.5 Summary Summary of Major New Features and Changes December 2010 Table of Contents Introduction... 3 Documentation of New Features... 3 Installation Instructions for this Version...
More informationSummation Algebra. x i
2 Summation Algebra In the next 3 chapters, we deal with the very basic results in summation algebra, descriptive statistics, and matrix algebra that are prerequisites for the study of SEM theory. You
More informationbitmedia Access 2007 Basics Entry test Database Basics Entry test Basic database terms What is Access 2007? Tables and indexes
bitmedia Access 2007 Basics Databases such as Access are often considered by some to live in the shadows of the Microsoft Office Package. This is, as we hope to demonstrate in the course of this module,
More informationUNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. A Model of Programming Languages
UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division CS61B Spring 1998 P. N. Hilfinger A Model of Programming Languages 1 Programming Models One
More informationSFC A Structured Flow Chart Editor Version 2.3 User s Guide Tia Watts, Ph.D. Sonoma State University
SFC A Structured Flow Chart Editor Version 2.3 User s Guide Tia Watts, Ph.D. Sonoma State University 1 of 35 SFC A Structured Flow Chart Editor Version 2.3 User s Guide Table of Contents 1. Introduction...
More information7 Communication Classes
this version: 26 February 2009 7 Communication Classes Perhaps surprisingly, we can learn much about the longrun behavior of a Markov chain merely from the zero pattern of its transition matrix. In the
More information0 Introduction to Data Analysis Using an Excel Spreadsheet
Experiment 0 Introduction to Data Analysis Using an Excel Spreadsheet I. Purpose The purpose of this introductory lab is to teach you a few basic things about how to use an EXCEL 2010 spreadsheet to do
More informationInformatica e Sistemi in Tempo Reale
Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)
More informationProgramming and Data Structure
Programming and Data Structure Dr. P.P.Chakraborty Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture # 07 Data Structuring: Case Study  III We shall continue
More informationNumerical Methods Lecture 2 Simultaneous Equations
Numerical Methods Lecture 2 Simultaneous Equations Topics: matrix operations solving systems of equations Matrix operations: Mathcad is designed to be a tool for quick and easy manipulation of matrix forms
More informationProgramming in Access VBA
PART I Programming in Access VBA In this part, you will learn all about how Visual Basic for Applications (VBA) works for Access 2010. A number of new VBA features have been incorporated into the 2010
More informationthe points are called control points approximating curve
Chapter 4 Spline Curves A spline curve is a mathematical representation for which it is easy to build an interface that will allow a user to design and control the shape of complex curves and surfaces.
More informationObject Oriented Software Design
Object Oriented Software Design Introduction to Java  II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction
More informationVALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANKULATHUR 603 203 DEPARTMENT OF COMPUTER APPLICATIONS QUESTION BANK IN REVISED BLOOM S TAXONOMY
ACADEMIC YEAR: 0 7 VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANKULATHUR 0 0 SEMESTER: ODD BRANCH: MCA YEAR: I SEMESTER: I SUBJECT CODE AND NAME: MC70 Problem Solving and Programming NAME OF THE FACULTY
More informationNumerical Matrix Analysis
Numerical Matrix Analysis Lecture Notes #10 Conditioning and / Peter Blomgren, blomgren.peter@gmail.com Department of Mathematics and Statistics Dynamical Systems Group Computational Sciences Research
More informationScicos is a Scilab toolbox included in the Scilab package. The Scicos editor can be opened by the scicos command
7 Getting Started 7.1 Construction of a Simple Diagram Scicos contains a graphical editor that can be used to construct block diagram models of dynamical systems. The blocks can come from various palettes
More informationMATLAB @ Work. MATLAB Source Control Using Git
MATLAB @ Work MATLAB Source Control Using Git Richard Johnson Using source control is a key practice for professional programmers. If you have ever broken a program with a lot of editing changes, you can
More informationParallel and Distributed Computing Programming Assignment 1
Parallel and Distributed Computing Programming Assignment 1 Due Monday, February 7 For programming assignment 1, you should write two C programs. One should provide an estimate of the performance of pingpong
More informationCHAPTER 2 PROBLEM SOLVING
CHAPTER 2 PROBLEM SOLVING This chapter will cover the following topics: Problem Solving Concepts for the Computer PreProgramming Phase Programming Or Implementation Phase What Problem Can Be Solved By
More informationSales Performance Management Using Salesforce.com and Tableau 8 Desktop Professional & Server
Sales Performance Management Using Salesforce.com and Tableau 8 Desktop Professional & Server Author: Phil Gilles Sales Operations Analyst, Tableau Software March 2013 p2 Executive Summary Managing sales
More information6 Gaussian Elimination
G1BINM Introduction to Numerical Methods 6 1 6 Gaussian Elimination 61 Simultaneous linear equations Consider the system of linear equations a 11 x 1 + a 12 x 2 + + a 1n x n = b 1 a 21 x 1 + a 22 x 2 +
More informationEliminate Memory Errors and Improve Program Stability
Eliminate Memory Errors and Improve Program Stability with Intel Parallel Studio XE Can running one simple tool make a difference? Yes, in many cases. You can find errors that cause complex, intermittent
More informationAbsolute Value of Reasoning
About Illustrations: Illustrations of the Standards for Mathematical Practice (SMP) consist of several pieces, including a mathematics task, student dialogue, mathematical overview, teacher reflection
More informationFREE VERSION. Created by: Jason Nesbitt Mobile App Development Guide
FREE VERSION Created by: Jason Nesbitt Mobile App Development Guide Quickly learn all of the necessary skills needed to build your very own customisable mobile apps. Important: Download Example Files by
More informationCurriculum Map. Discipline: Computer Science Course: C++
Curriculum Map Discipline: Computer Science Course: C++ August/September: How can computer programs make problem solving easier and more efficient? In what order does a computer execute the lines of code
More informationImage Manipulation in MATLAB Due 11/1 at 5:00 PM
Image Manipulation in MATLAB Due 11/1 at 5:00 PM 1 Introduction Digital images are just matrices of pixels, and any type of matrix operation can be applied to a matrix containing image data. In this project
More informationChapter 7: Software Development Stages Test your knowledge  answers
Chapter 7: Software Development Stages Test your knowledge  answers 1. What is meant by constraints and limitations on program design? Constraints and limitations are based on such items as operational,
More informationAthena Knowledge Base
Athena Knowledge Base The Athena Visual Studio Knowledge Base contains a number of tips, suggestions and how to s that have been recommended by the users of the software. We will continue to enhance this
More informationStudents in their first advanced mathematics classes are often surprised
CHAPTER 8 Proofs Involving Sets Students in their first advanced mathematics classes are often surprised by the extensive role that sets play and by the fact that most of the proofs they encounter are
More informationObject Oriented Software Design
Object Oriented Software Design Introduction to Java  II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 28, 2010 G. Lipari (Scuola Superiore Sant Anna) Introduction
More informationSQL Server Array Library 201011 László Dobos, Alexander S. Szalay
SQL Server Array Library 201011 László Dobos, Alexander S. Szalay The Johns Hopkins University, Department of Physics and Astronomy Eötvös University, Department of Physics of Complex Systems http://voservices.net/sqlarray,
More informationSYSTEMS OF EQUATIONS AND MATRICES WITH THE TI89. by Joseph Collison
SYSTEMS OF EQUATIONS AND MATRICES WITH THE TI89 by Joseph Collison Copyright 2000 by Joseph Collison All rights reserved Reproduction or translation of any part of this work beyond that permitted by Sections
More informationOutline. hardware components programming environments. installing Python executing Python code. decimal and binary notations running Sage
Outline 1 Computer Architecture hardware components programming environments 2 Getting Started with Python installing Python executing Python code 3 Number Systems decimal and binary notations running
More informationASEN 3112  Structures. MDOF Dynamic Systems. ASEN 3112 Lecture 1 Slide 1
19 MDOF Dynamic Systems ASEN 3112 Lecture 1 Slide 1 A TwoDOF MassSpringDashpot Dynamic System Consider the lumpedparameter, massspringdashpot dynamic system shown in the Figure. It has two point
More informationThis is great when speed is important and relatively few words are necessary, but Max would be a terrible language for writing a text editor.
Dealing With ASCII ASCII, of course, is the numeric representation of letters used in most computers. In ASCII, there is a number for each character in a message. Max does not use ACSII very much. In the
More informationHow long is the vector? >> length(x) >> d=size(x) % What are the entries in the matrix d?
MATLAB : A TUTORIAL 1. Creating vectors..................................... 2 2. Evaluating functions y = f(x), manipulating vectors. 4 3. Plotting............................................ 5 4. Miscellaneous
More information