# MATLAB Programming. Problem 1: Sequential

Size: px
Start display at page:

Transcription

2 Division of Engineering Fundamentals, Copyright 1999 by J.C. Malzahn Kampe 2 / 21 % This program will calculate the % area and circumference of a circle, % allowing the radius as an input. R = input('please enter the radius: '); AREA = pi * R^2; CIRC = 2.0 * pi * R; fprintf('\n Radius = %f units',r) fprintf('\n Area = %f square units', AREA) fprintf('\n Circumference = %f units\n', CIRC) START INPUT R AREA = π R 2 CIRC = 2.0 π R OUTPUT R, AREA, CIRC STOP Figure 1. A MATLAB program (a script m-file named Prob1) and the corresponding flowchart for Problem 1. At this point you may have many questions about how we get to the contents of Figure 1, so let s go through that first. After reading Problem 1 above, we must first develop an approach (algorithm) to obtain what the problem statement requires. Our solution algorithm is documented with the flowchart that appears in Figure 1. The flowchart is produced using the drawing features available in MS Word under Flowchart in the AutoShapes menu of the lower toolbar. Next we translate the flowcharted algorithm to a computer program (code) that MATLAB can interpret and execute. This program appears on the left in Figure 1. In order to produce this code, we open MATLAB, and go to the File menu in the upper toolbar, and select New. Of the options that come up, we then select M-File; this opens the MATLAB Editor/Debugger window. Once this window is open, we can type in our program, edit the program, and save it to our Work folder. Now take a look at the correspondence between the flowchart and the code in Figure 1. The first thing to note is that there are no MATLAB commands in the code to START or STOP the program. The script file begins with statements that have been commented out of the executable statements by placing % in the first position on those lines. The % tells MATLAB that what follows on that line can be ignored during program run. We use the comment lines to describe what the program does. Also, if, in the command window, we type

4 Division of Engineering Fundamentals, Copyright 1999 by J.C. Malzahn Kampe 4 / 21 the format field are enclosed within single quote marks, and the variable name (which stores the value) specified to fill the number format field is listed outside the quotes, but before the closing parenthesis. Note, also, that a comma separates the format string (i.e., what is contained within the single quotes) and the variable name that stores the value to be placed in the number format field. It was not necessary to use three different fprintf statements because you can output more than one argument with fprintf statements. Three were used to keep the length of the code statements short enough to fit within Figure 1. The number field was specified as a fixed point formatted field by use of %f. Use %e for exponential format, and %g when either fixed point or exponential format (which ever is shorter) is acceptable. We can also tell MATLAB how many places past the decimal point we would like, as in %.3f, which specifies that three places after the decimal be displayed in fixed point format. Now, if you do not wish to format your output, you can use MATLAB s disp command, which has the following syntax disp(argument) where argument is replaced with a single variable name, or with a character string (that cannot contain any format fields) enclosed within single quotes. The disp statement will accept only one argument, so for our flowchart in Figure 1, three disp statements would be required just to output the variables, with no annotating text. Now that we understand the translation of the flowchart to code, how is the code executed? If you are in the Editor/Debugger window with the script m-file open, you can choose Run from the options in the Tools pull-down menu, and the command window will show execution of the program.» Please enter the radius: 32 Radius = units Area = square units Circumference = units If you are in the command window, you can enter the script m-file name at the prompt.» Prob1 Please enter the radius: 32 Radius = units Area = square units Circumference = units»

5 Division of Engineering Fundamentals, Copyright 1999 by J.C. Malzahn Kampe 5 / 21» Prob1 Please enter the radius: 5 Radius = units Area = square units Circumference = units» Problem 2: Selection / Decision The solution to Problem 2 involves a decision on whether the radius, area and circumference values should be printed. This decision to output is based on whether the area value exceeds 20. Figure 2 shows a MATLAB program and flowcharted algorithm that produces the results requested in Problem 2. START % This program will calculate the % area and circumference of a circle, % allowing the radius as an input, % but will only provide output if the % area exceeds 20. R = input('please enter the radius: '); AREA = pi * R^2; INPUT R AREA = π R 2 CIRC = 2.0 π R CIRC = 2.0 * pi * R; if AREA > 20.0 end fprintf('\n Radius = %f units',r) fprintf('\n Area = %f square units', AREA) fprintf('\n Circumference = %f units\n', CIRC) if AREA > 20.0 FALSE TRUE OUTPUT R, AREA, CIRC STOP Figure 2. A MATLAB program (a script m-file named Prob2) and the corresponding flowchart for Problem 2.

7 Division of Engineering Fundamentals, Copyright 1999 by J.C. Malzahn Kampe 7 / 21 START N = 0 R = 0.0 AREA = 0.0 CIRC = 0.0 for J from 1 to 10 by 1 OUTPUT N INPUT R AREA = π R 2 CIRC = 2.0 π R if AREA > 20.0 True OUTPUT R, AREA, CIRC False N = N + 1 STOP Figure 3a. A flowchart that documents a solution algorithm for Problem 3.

8 Division of Engineering Fundamentals, Copyright 1999 by J.C. Malzahn Kampe 8 / 21 % This program will calculate the % area and circumference of ten circles, % allowing the radius as an input, % but will only provide output for circles % with an area that exceeds 20. N = 0; R = 0.0; AREA = 0.0; CIRC = 0.0; for J = 1:1:10 end R = input('please enter the radius: '); AREA = pi * R^2; CIRC = 2.0 * pi * R; if AREA > 20.0 fprintf('\n Radius = %f units',r) fprintf('\n Area = %f square units', AREA) fprintf('\n Circumference = %f units\n', CIRC) else N = N + 1; end fprintf('\n Number of circles that do not have area > 20: %.0f \n', N) Figure 3b. A MATLAB program (script m-file named Prob3) for Problem 3 that corresponds to the flowchart of Figure 3a. Take a close look at Figure 3a; the flowchart there appears substantially different from the flowchart shown in Figure 2. We should examine the differences, one at a time, in order to gain an understanding of what the new requirements of Problem 3 s solution entail in terms of flowcharting and subsequent programming. The most substantial change between the two flowcharts is the looping of the logic flow path. This is accommodated, in the flowchart, by introduction of the looping hexagon symbol (which contains for J from 1 to 10 by 1 ) and the return of logic flow back to the hexagon after the decision structure executes. The statement inside the hexagon indicates that a predetermined number of executions of the loop will occur, which is controlled by the value of J. The first time the hexagon symbol is entered, J is set to 1, and then compared to the ending value for J, which here is 10. If the current value of J does not exceed its ending value (here 10), the loop will execute. That is, logic flow will move down through the INPUT symbol, through the two process blocks, through the decision diamond and along the path selected by the value of AREA, and then back to the loop hexagon. Upon return to the hexagon, J will increment by 1 to become 2, and then be compared to 10. As 2 does not exceed 10, the loop will execute again. This repeats until

9 Division of Engineering Fundamentals, Copyright 1999 by J.C. Malzahn Kampe 9 / 21 J becomes 11. When 11 is compared to the ending value for J (which is 10), logic flow exits the loop because the looping conditions are no longer met. The loop depicted in Figure 3 is called a for loop. A for loop is used when the number of times a procedure must be repeated is known, either by the programmer or by the user. In the statement within the hexagon, for J from 1 to 10 by 1, any of the numbers that specify the starting value, the ending value, or the incrementing value, can be replaced by a variable name, which, in turn, can be allowed as input. For example, if we put for J from 1 to NUMBER by 1 in the hexagon, then we could let the user input how many circles were to be evaluated by entering that quantity as NUMBER in an input value assignment statement that preceded the loop. Now we turn our attention to the process block below the decision diamond. This process block contains a counting value assignment statement (N = N + 1) that counts the number of circles that do not meet the area criterion for output. In the flowchart of Figure 3, we can see that if AREA > 20.0 is false, then the selected logic flow path will execute N = N + 1. If AREA > 20.0 is true, the counting statement is bypassed. Note that each time N = N + 1 executes, the value of N increases by 1, thus counting the executions of the N = N + 1 statement, and hence the number of times that AREA > 20.0 is false. Another change in the flowcharts as we move from Problem 2 to Problem 3 is the addition of a new process block in Figure 3. This process block contains value assignment statements that set the variables N, R, AREA, and CIRC equal to zero, and is placed just below START. This procedure is called initialization of variables. It is often only a safety feature that experienced programmers use when solution algorithms become complex, but sometimes it is required in the logic of the algorithm. In the case of Problem 3, the initialization of R, AREA, and CIRC is not required, but it is necessary that we initialize N at a value of zero. This is so for two reasons. The first reason that N must be set to zero involves the counting statement N = N + 1. In execution of this statement, MATLAB will always need a current value of N to evaluate the right side of the statement (i.e., N + 1). The first time the statement executes, the new value of N becomes 1. If N is not initialized at zero, N = N + 1 cannot keep a proper count of the number of circles that do not meet the area criterion for output. The second reason we initialize N at zero is because a user may have ten circles, all of which do meet the area criterion. If this happens, then when loop execution is completed, MATLAB will need a numeric value for N in order to execute the N output required upon loop exit. If N has not been defined (i.e., given a numeric value), MATLAB will respond with an error statement. The value N should be storing in this event is zero, because all circles will have met the area criterion. It should be noted that zero is not always the appropriate value to use for variable initialization. In the case of Problem 3, however, zero works for the logic of the algorithm.

10 Division of Engineering Fundamentals, Copyright 1999 by J.C. Malzahn Kampe 10 / 21 We are now ready to look at the MATLAB program (Figure 3b) that corresponds to the flowchart in Figure 3a. Below the comments, we see the value assignment statements that initialize N, R, AREA, and CIRC. Although these are typed in on a single line, MATLAB reads them as four separate statements because the semicolons that suppress the echoes also act as delimiters. Next, the for loop opens with for J = 1:1:10 and closes with the second end statement. You should next notice that the if structure contains two new statements, else and N = N + 1. if AREA > 20.0 fprintf('\n Radius = %f units',r) fprintf('\n Area = %f square units', AREA) fprintf('\n Circumference = %f units\n', CIRC) else N = N + 1; end In this if structure, the statements to be executed when AREA > 20.0 is true follow directly below the if statement. Those statements that are executed only when AREA > 20.0 is false are placed directly below an else statement, and the if structure is closed with the first end statement. You should note that, for Problem 2 (where we had nothing to execute when AREA > 20.0 was false), an else statement was not required. The function of the else here is to ensure that the counting statement (N = N + 1) is bypassed when AREA > 20.0 is true, and that N = N + 1 executes when AREA > 20.0 is false. During script file run, if AREA > 20.0 is true, MATLAB will execute all statements that follow the if until it reaches the else, and all statements between else and end are skipped. If AREA > 20.0 is false, MATLAB will skip all statements until it reaches the else, and then resume execution. You should be aware that if structures can be nested so that elseif statements are often used in programming to provide third, fourth, and more alternate logic flow paths. The last thing to observe in the code shown in Figure 3b is the final fprintf statement. This provides the output of N, the number of circles that do not meet the area criterion. A verification of the script file Prob3 is shown below in the MATLAB output for a run from the command window.

12 Division of Engineering Fundamentals, Copyright 1999 by J.C. Malzahn Kampe 12 / 21 Problem 4: Repetition ( while Loop) In Problem 4, it is required that the loop executes for as many times as required by the user. Now, as discussed above, we could use a for loop, and have the user count the number of circles to be evaluated. This is no great task when only a few executions are required. However, if the user has a large number of circles to evaluate, counting them is not an option. Further, if interrupted by something more pressing, the user may not be able to run all the circles in one session. In efforts to create a user friendly program, these situations should be anticipated. A flowchart that documents an algorithm for Problem 4 is shown in Figure 4a. The corresponding MATLAB script m-file is provided in Figure 4b. The main distinction between the flowcharts for Problems 3 and 4 is the type of loop employed. Problem 4 requires a repeat of procedural steps for as many times as the user wishes to run circles. In this case, we use a while loop because we cannot predetermine how many times the loop should execute. The looping condition in the while loop of Problem 4 is based on the value of R. When R is positive, the loop executes. This makes physical sense, as any circle that should be evaluated will have a positive radius. Now, to accommodate the change in the logic used to control the number of loop executions, we need two other modifications in our flowchart and program. First, we must input a value for R before we enter the loop, so that MATLAB can obtain a nonzero numeric value for R before it reaches the while loop statement. The second modification we need to make is moving the input of R that sits within the loop. This second input statement must occur just prior to re-entering the loop hexagon. This new position ensures that R is evaluated as greater than zero before any calculations are executed (in case the user enters zero to quit). This input position also ensures that, when the user enters zero for R in order to quit, the circle with R = 0 is not counted among those circles for which AREA > 20.0 is false. In the MATLAB code that corresponds to Figure 4a (found in Figure 4b), we see the implementation of the required changes to our solution algorithm. We find an input statement R = input('please enter the radius (enter 0 to quit): '); which precedes the while statement while R > 0.0 that starts the loop. Also, the input statement for R within the loop now follows the end that closes the if structure.

13 Division of Engineering Fundamentals, Copyright 1999 by J.C. Malzahn Kampe 13 / 21 START N = 0 R = 0.0 AREA = 0.0 CIRC = 0.0 INPUT R while R > 0.0 OUTPUT N AREA = π R 2 CIRC = 2.0 π R INPUT R if AREA > 20.0 True OUTPUT R, AREA, CIRC False N = N + 1 STOP Figure 4a. A flowchart that documents a solution algorithm for Problem 4.

14 Division of Engineering Fundamentals, Copyright 1999 by J.C. Malzahn Kampe 14 / 21 % This program will calculate the % area and circumference of circles, % allowing the radius as an input, % but will only provide output for circles % with an area that exceeds 20. N = 0; R = 0.0; AREA = 0.0; CIRC = 0.0; R = input('please enter the radius (enter 0 to quit): '); while R > 0.0 end AREA = pi * R^2; CIRC = 2.0 * pi * R; if AREA > 20.0 fprintf('\n Radius = %f units',r) fprintf('\n Area = %f square units', AREA) fprintf('\n Circumference = %f units\n', CIRC) else N = N + 1; end R = input('please enter the radius (enter 0 to quit): '); fprintf('\n Number of circles that do not have area > 20: %.0f \n', N) Figure 4b. A MATLAB program (script m-file named Prob4) for Problem 4 that corresponds to the flowchart in Figure 4a. The last thing to note about the code in Figure 4b is the user prompt in the input statements. Because our code is set up to allow the user to control execution of the loop, we must provide the user with some instructions on how to exit the program. Hence, enter 0 to quit is added to the prompt that requests an input for R.

16 Division of Engineering Fundamentals, Copyright 1999 by J.C. Malzahn Kampe 16 / 21 % This function will calculate the % area and circumference of a circle. function [AREA, CIRC] = circle(r) AREA = pi * R^2; CIRC = 2 * pi * R; START INPUT R AREA = π R 2 CIRC = 2.0 π R OUTPUT AREA, CIRC STOP Figure 5. A flowchart that documents the algorithm of the MATLAB function m-file shown to the left, which calculates the area and circumference of a circle. This function m-file must be saved as circle.m. Look at the function statement function [AREA, CIRC] = circle(r) that begins our code for the function named circle. This m-file must be saved as circle.m so that MATLAB will find it when the function is called in the workspace. The word function tells MATLAB how to interpret the rest of the statement. In the case of our function circle, a value is received from the workspace or script m-file that called the function; this value acquires the variable name R when circle receives it. Next, as circle executes, the value assignment statements AREA = pi * R^2; CIRC = 2 * pi * R; use R to calculate values that are then assigned to the function variables AREA and CIRC. When execution of circle is completed, the values stored under AREA and CIRC are passed back to the statement in the workspace or script file that called circle; this

17 Division of Engineering Fundamentals, Copyright 1999 by J.C. Malzahn Kampe 17 / 21 constitutes the output of the function circle. Now we should look at how the function is called. Examine the output shown below for MATLAB s response to the call of function circle.» [a,c] = circle(5) a = c =» In the value assignment statement that we entered, circle was called, and was sent the value 5, which it received under the name R. AREA and CIRC were assigned values during execution of circle. The values stored under AREA and CIRC in the function were passed back to the command window statement that called circle, and that statement ( [a,c] = circle(5) ) assigned those values received to variables named a and c. Now, it should be understood that the function variables AREA and CIRC are local to the function, and the command window will not recognize AREA and CIRC as part of the current workspace.» [a,c] = circle(5) a = c = » AREA??? Error using ==> area Not enough input arguments.» CIRC??? Undefined function or variable 'CIRC'.»

18 Division of Engineering Fundamentals, Copyright 1999 by J.C. Malzahn Kampe 18 / 21 This is a major distinction between script m-files and function m-files. You see, when a script m-file executes, that file is carried into and becomes part of the current workspace, as though you had just typed in all of the commands within the script file. Function m- files, on the other hand, actually exchange (receive and pass back) only values with the workspace, and the lines of code that are contained within the function file remain distant and distinct from the workspace. The best way to gain familiarity with function m-files is to write a few of them. Here are two suggestions. 1. Write a function m-file that will return the area of a right triangle when the lengths of the two legs are provided. 2. Write a function m-file that will return N!, where N is a positive integer. Formatted Output Often when we use a computer as a tool to implement our solution to a problem, it is because we are dealing with substantial amounts of data and/or calculations. In order to see the output of the computer program without looking through pages and pages of the generated information, we organize the output into the form of tables or graphs. In MATLAB, to generate a table as output, we make use of the fprintf statement, which allows the output of more than one variable. In the code below, note that the fprintf statements that print the table title, column headings, and break bar are placed before the loop that generates the data and fills the table columns. Note, also, that since numeric data should be right-justified, we have specified a field size (four spaces) in the fixed point format fields (designated %4.1f ) for the area and circumference values. % This program will generate a table of % area and circumference values for % circles of radii from 1 to 5 inches. fprintf('\n\n Table I. Values of circle area and circumference for given circle radii.') fprintf('\n\n\n Radius, R Area, A Circumference, C\n') fprintf(' inches square inches inches\n') fprintf(' ') for R = 1.0:1.0:5.0 end AREA = pi * R^2; CIRC = 2 * pi * R; fprintf('\n\n %.1f %4.1f %4.1f\n', R, AREA, CIRC)

19 Division of Engineering Fundamentals, Copyright 1999 by J.C. Malzahn Kampe 19 / 21 When executed, this code will produce the following table. Table I. Values of circle area and circumference for given circle radii. Radius, R Area, A Circumference, C inches square inches inches If we prefer a plot of our data, we use the line commands for plotting and labeling as statements in our code. And, because circle area is a power function of radius, we use the loglog command to generate a log-log plot of area versus radius. % This program will generate a log-log plot % of area versus radius for circles of radii % from 1 to 5 inches. for R = 1.0:1.0:5.0 AREA = pi * R^2; loglog(r,area,'o') hold on end xlabel('circle Radius R, inches') ylabel('circle Area A, square inches') grid title('the INFLUENCE OF CIRCLE RADIUS ON CIRCLE AREA')

20 Division of Engineering Fundamentals, Copyright 1999 by J.C. Malzahn Kampe 20 / 21 The figure shown below was generated upon execution of the preceding code. The only editing done in MATLAB s figure window was moving the figure title to its proper place below the x-axis. It should be noted that these values are not experimental, and, strictly speaking, should not be evident as points on the plot. However, in the code above, we asked for point-by-point plotting because the plot command was inside the loop; this prevents MATLAB from using a line to plot the values Circle Area A, square inches Circle Radius R, inches THE INFLUENCE OF CIRCLE RADIUS ON CIRCLE AREA If we want a line instead of points for this plot, we can build two vectors inside the loop to store our radius and area values, and then have a plot command subsequent to the loop. This is actually a more efficient way of programming because the plot command is only executed once instead of five times. It also has the advantage of saving each value of radius and area that are generated within the loop. See the example code and output figure found on the following page.

21 Division of Engineering Fundamentals, Copyright 1999 by J.C. Malzahn Kampe 21 / 21 % This program will generate a log-log plot % of area versus radius for circles of radii % from 1 to 5 inches. N = 0; for R = 1.0:1.0:5.0 N = N + 1; AREA(N) = pi * R^2; RADIUS(N) = R; end loglog(radius,area,'-') hold on xlabel('circle Radius R, inches') ylabel('circle Area A, square inches') grid title('the INFLUENCE OF CIRCLE RADIUS ON CIRCLE AREA') 10 2 Circle Area A, square inches Circle Radius R, inches THE INFLUENCE OF CIRCLE RADIUS ON CIRCLE AREA

### Name: 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

### Appendix: Tutorial Introduction to MATLAB

Resampling Stats in MATLAB 1 This document is an excerpt from Resampling Stats in MATLAB Daniel T. Kaplan Copyright (c) 1999 by Daniel T. Kaplan, All Rights Reserved This document differs from the published

### MATLAB Basics MATLAB numbers and numeric formats

MATLAB Basics MATLAB numbers and numeric formats All numerical variables are stored in MATLAB in double precision floating-point form. (In fact it is possible to force some variables to be of other types

### MATLAB 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 m-file because it must be saved with a file

### Beginner s Matlab Tutorial

Christopher Lum lum@u.washington.edu Introduction Beginner s Matlab Tutorial This document is designed to act as a tutorial for an individual who has had no prior experience with Matlab. For any questions

### AMATH 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

### Exercise 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

### ChE-1800 H-2: Flowchart Diagrams (last updated January 13, 2013)

ChE-1800 H-2: Flowchart Diagrams (last updated January 13, 2013) This handout contains important information for the development of flowchart diagrams Common Symbols for Algorithms The first step before

### Introduction to Matlab

Introduction to Matlab Social Science Research Lab American University, Washington, D.C. Web. www.american.edu/provost/ctrl/pclabs.cfm Tel. x3862 Email. SSRL@American.edu Course Objective This course provides

### 2 SYSTEM DESCRIPTION TECHNIQUES

2 SYSTEM DESCRIPTION TECHNIQUES 2.1 INTRODUCTION Graphical representation of any process is always better and more meaningful than its representation in words. Moreover, it is very difficult to arrange

### 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:

### Informatica 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)

### Writing Control Structures

Writing Control Structures Copyright 2006, Oracle. All rights reserved. Oracle Database 10g: PL/SQL Fundamentals 5-1 Objectives After completing this lesson, you should be able to do the following: Identify

### MATLAB 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

### 6. Control Structures

- 35 - Control Structures: 6. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may bifurcate, repeat code or take decisions. For that purpose,

### PL / SQL Basics. Chapter 3

PL / SQL Basics Chapter 3 PL / SQL Basics PL / SQL block Lexical units Variable declarations PL / SQL types Expressions and operators PL / SQL control structures PL / SQL style guide 2 PL / SQL Block Basic

### Curve Fitting, Loglog Plots, and Semilog Plots 1

Curve Fitting, Loglog Plots, and Semilog Plots 1 In this MATLAB exercise, you will learn how to plot data and how to fit lines to your data. Suppose you are measuring the height h of a seedling as it grows.

### Moving from CS 61A Scheme to CS 61B Java

Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you

### Algorithm & 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

### Visual Logic Instructions and Assignments

Visual Logic Instructions and Assignments Visual Logic can be installed from the CD that accompanies our textbook. It is a nifty tool for creating program flowcharts, but that is only half of the story.

### Using SPSS, Chapter 2: Descriptive Statistics

1 Using SPSS, Chapter 2: Descriptive Statistics Chapters 2.1 & 2.2 Descriptive Statistics 2 Mean, Standard Deviation, Variance, Range, Minimum, Maximum 2 Mean, Median, Mode, Standard Deviation, Variance,

### Chapter 2: Algorithm Discovery and Design. Invitation to Computer Science, C++ Version, Third Edition

Chapter 2: Algorithm Discovery and Design Invitation to Computer Science, C++ Version, Third Edition Objectives In this chapter, you will learn about: Representing algorithms Examples of algorithmic problem

### Unit 1 Number Sense. In this unit, students will study repeating decimals, percents, fractions, decimals, and proportions.

Unit 1 Number Sense In this unit, students will study repeating decimals, percents, fractions, decimals, and proportions. BLM Three Types of Percent Problems (p L-34) is a summary BLM for the material

### Quick Reference ebook

This file is distributed FREE OF CHARGE by the publisher Quick Reference Handbooks and the author. Quick Reference ebook Click on Contents or Index in the left panel to locate a topic. The math facts listed

### PROG0101 Fundamentals of Programming PROG0101 FUNDAMENTALS OF PROGRAMMING. Chapter 3 Algorithms

PROG0101 FUNDAMENTALS OF PROGRAMMING Chapter 3 1 Introduction to A sequence of instructions. A procedure or formula for solving a problem. It was created mathematician, Mohammed ibn-musa al-khwarizmi.

### MS Access: Advanced Tables and Queries. Lesson Notes Author: Pamela Schmidt

Lesson Notes Author: Pamela Schmidt Tables Text Fields (Default) Text or combinations of text and numbers, as well as numbers that don't require calculations, such as phone numbers. or the length set by

Operators Lecture 2 Mathcad Basics + Addition, - Subtraction, * Multiplication, / Division, ^ Power ( ) Specify evaluation order Order of Operations ( ) ^ highest level, first priority * / next priority

### 5.1 Radical Notation and Rational Exponents

Section 5.1 Radical Notation and Rational Exponents 1 5.1 Radical Notation and Rational Exponents We now review how exponents can be used to describe not only powers (such as 5 2 and 2 3 ), but also roots

### 4. How many integers between 2004 and 4002 are perfect squares?

5 is 0% of what number? What is the value of + 3 4 + 99 00? (alternating signs) 3 A frog is at the bottom of a well 0 feet deep It climbs up 3 feet every day, but slides back feet each night If it started

### 9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements

9 Control Statements 9.1 Introduction The normal flow of execution in a high level language is sequential, i.e., each statement is executed in the order of its appearance in the program. However, depending

### While 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

### Computational Mathematics with Python

Boolean Arrays Classes Computational Mathematics with Python Basics Olivier Verdier and Claus Führer 2009-03-24 Olivier Verdier and Claus Führer Computational Mathematics with Python 2009-03-24 1 / 40

### MATLAB Workshop 14 - Plotting Data in MATLAB

MATLAB: Workshop 14 - Plotting Data in MATLAB page 1 MATLAB Workshop 14 - Plotting Data in MATLAB Objectives: Learn the basics of displaying a data plot in MATLAB. MATLAB Features: graphics commands Command

### ALGORITHMS AND FLOWCHARTS

ALGORITHMS AND FLOWCHARTS A typical programming task can be divided into two phases: Problem solving phase produce an ordered sequence of steps that describe solution of problem this sequence of steps

### JavaScript: Control Statements I

1 7 JavaScript: Control Statements I 7.1 Introduction 2 The techniques you will learn here are applicable to most high-level languages, including JavaScript 1 7.2 Algorithms 3 Any computable problem can

### VB.NET Programming Fundamentals

Chapter 3 Objectives Programming Fundamentals In this chapter, you will: Learn about the programming language Write a module definition Use variables and data types Compute with Write decision-making statements

### Introduction to Python

Caltech/LEAD Summer 2012 Computer Science Lecture 2: July 10, 2012 Introduction to Python The Python shell Outline Python as a calculator Arithmetic expressions Operator precedence Variables and assignment

### Sources: On the Web: Slides will be available on:

C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,

### Two-way selection. Branching and Looping

Control Structures: are those statements that decide the order in which individual statements or instructions of a program are executed or evaluated. Control Structures are broadly classified into: 1.

### Eventia Log Parsing Editor 1.0 Administration Guide

Eventia Log Parsing Editor 1.0 Administration Guide Revised: November 28, 2007 In This Document Overview page 2 Installation and Supported Platforms page 4 Menus and Main Window page 5 Creating Parsing

### Exercise 1: Python Language Basics

Exercise 1: Python Language Basics In this exercise we will cover the basic principles of the Python language. All languages have a standard set of functionality including the ability to comment code,

### How to test and debug an ASP.NET application

Chapter 4 How to test and debug an ASP.NET application 113 4 How to test and debug an ASP.NET application If you ve done much programming, you know that testing and debugging are often the most difficult

### How 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

### Flowchart Techniques

C H A P T E R 1 Flowchart Techniques 1.1 Programming Aids Programmers use different kinds of tools or aids which help them in developing programs faster and better. Such aids are studied in the following

### Computational Mathematics with Python

Numerical Analysis, Lund University, 2011 1 Computational Mathematics with Python Chapter 1: Basics Numerical Analysis, Lund University Claus Führer, Jan Erik Solem, Olivier Verdier, Tony Stillfjord Spring

### Computational Mathematics with Python

Computational Mathematics with Python Basics Claus Führer, Jan Erik Solem, Olivier Verdier Spring 2010 Claus Führer, Jan Erik Solem, Olivier Verdier Computational Mathematics with Python Spring 2010 1

### Signal Processing First Lab 01: Introduction to MATLAB. 3. Learn a little about advanced programming techniques for MATLAB, i.e., vectorization.

Signal Processing First Lab 01: Introduction to MATLAB Pre-Lab and Warm-Up: You should read at least the Pre-Lab and Warm-up sections of this lab assignment and go over all exercises in the Pre-Lab section

### Introduction to Measurement Tools

Introduction to Measurement Tools Revu's built-in measurement tools make it easy to take length, area, perimeter, diameter, volume and radius measurements, count from PDFs and perform area cutouts. Compatibility

### Chapter One Introduction to Programming

Chapter One Introduction to Programming 1-1 Algorithm and Flowchart Algorithm is a step-by-step procedure for calculation. More precisely, algorithm is an effective method expressed as a finite list of

### Notes on Algorithms, Pseudocode, and Flowcharts

Notes on Algorithms, Pseudocode, and Flowcharts Introduction Do you like hot sauce? Here is an algorithm for how to make a good one: Volcanic Hot Sauce (from: http://recipeland.com/recipe/v/volcanic-hot-sauce-1125)

### MATLAB DFS. Interface Library. User Guide

MATLAB DFS Interface Library User Guide DHI Water Environment Health Agern Allé 5 DK-2970 Hørsholm Denmark Tel: +45 4516 9200 Fax: +45 4516 9292 E-mail: dhi@dhigroup.com Web: www.dhigroup.com 2007-03-07/MATLABDFS_INTERFACELIBRARY_USERGUIDE.DOC/JGR/HKH/2007Manuals/lsm

### 7 Relations and Functions

7 Relations and Functions In this section, we introduce the concept of relations and functions. Relations A relation R from a set A to a set B is a set of ordered pairs (a, b), where a is a member of A,

### River Dell Regional School District. Computer Programming with Python Curriculum

River Dell Regional School District Computer Programming with Python Curriculum 2015 Mr. Patrick Fletcher Superintendent River Dell Regional Schools Ms. Lorraine Brooks Principal River Dell High School

### We 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.

### Excel: Introduction to Formulas

Excel: Introduction to Formulas Table of Contents Formulas Arithmetic & Comparison Operators... 2 Text Concatenation... 2 Operator Precedence... 2 UPPER, LOWER, PROPER and TRIM... 3 & (Ampersand)... 4

### MATLAB Workshop 3 - Vectors in MATLAB

MATLAB: Workshop - Vectors in MATLAB page 1 MATLAB Workshop - Vectors in MATLAB Objectives: Learn about vector properties in MATLAB, methods to create row and column vectors, mathematical functions with

### VHDL 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

### SOME EXCEL FORMULAS AND FUNCTIONS

SOME EXCEL FORMULAS AND FUNCTIONS About calculation operators Operators specify the type of calculation that you want to perform on the elements of a formula. Microsoft Excel includes four different types

### Perl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl

First CGI Script and Perl Perl in a nutshell Prof. Rasley shebang line tells the operating system where the Perl interpreter is located necessary on UNIX comment line ignored by the Perl interpreter End

### Lecture 2 Notes: Flow of Control

6.096 Introduction to C++ January, 2011 Massachusetts Institute of Technology John Marrero Lecture 2 Notes: Flow of Control 1 Motivation Normally, a program executes statements from first to last. The

### Arc Length and Areas of Sectors

Student Outcomes When students are provided with the angle measure of the arc and the length of the radius of the circle, they understand how to determine the length of an arc and the area of a sector.

### Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Translation Translating to Java Introduction to Computer Programming The job of a programmer is to translate a problem description into a computer language. You need to be able to convert a problem description

### Area, Perimeter, Volume and Pythagorean Theorem Assessment

Area, Perimeter, Volume and Pythagorean Theorem Assessment Name: 1. Find the perimeter of a right triangle with legs measuring 10 inches and 24 inches a. 34 inches b. 60 inches c. 120 inches d. 240 inches

### Creating a Simple Macro

28 Creating a Simple Macro What Is a Macro?, 28-2 Terminology: three types of macros The Structure of a Simple Macro, 28-2 GMACRO and ENDMACRO, Template, Body of the macro Example of a Simple Macro, 28-4

### Simulation Tools. Python for MATLAB Users I. Claus Führer. Automn 2009. Claus Führer Simulation Tools Automn 2009 1 / 65

Simulation Tools Python for MATLAB Users I Claus Führer Automn 2009 Claus Führer Simulation Tools Automn 2009 1 / 65 1 Preface 2 Python vs Other Languages 3 Examples and Demo 4 Python Basics Basic Operations

### PL/SQL Overview. Basic Structure and Syntax of PL/SQL

PL/SQL Overview PL/SQL is Procedural Language extension to SQL. It is loosely based on Ada (a variant of Pascal developed for the US Dept of Defense). PL/SQL was first released in ١٩٩٢ as an optional extension

### 6 3 4 9 = 6 10 + 3 10 + 4 10 + 9 10

Lesson The Binary Number System. Why Binary? The number system that you are familiar with, that you use every day, is the decimal number system, also commonly referred to as the base- system. When you

Chapter 5 Programming Statements Chapter Table of Contents OVERVIEW... 57 IF-THEN/ELSE STATEMENTS... 57 DO GROUPS... 58 IterativeExecution... 59 JUMPING... 61 MODULES... 62 Defining and Executing a Module....

### PYTHON Basics http://hetland.org/writing/instant-hacking.html

CWCS Workshop May 2009 PYTHON Basics http://hetland.org/writing/instant-hacking.html Python is an easy to learn, modern, interpreted, object-oriented programming language. It was designed to be as simple

### Using Casio Graphics Calculators

Using Casio Graphics Calculators (Some of this document is based on papers prepared by Donald Stover in January 2004.) This document summarizes calculation and programming operations with many contemporary

### A.2. Exponents and Radicals. Integer Exponents. What you should learn. Exponential Notation. Why you should learn it. Properties of Exponents

Appendix A. Exponents and Radicals A11 A. Exponents and Radicals What you should learn Use properties of exponents. Use scientific notation to represent real numbers. Use properties of radicals. Simplify

### Final Exam Review: VBA

Engineering Fundamentals ENG1100 - Session 14B Final Exam Review: VBA 1 //coe/dfs/home/engclasses/eng1101/f03/ethics/en1.e05.finalcoursewrapup.sxi Final Programming Exam Topics Flowcharts Assigning Variables

### Select the Crow s Foot entity relationship diagram (ERD) option. Create the entities and define their components.

Α DESIGNING DATABASES WITH VISIO PROFESSIONAL: A TUTORIAL Microsoft Visio Professional is a powerful database design and modeling tool. The Visio software has so many features that we can t possibly demonstrate

### Math Review. for the Quantitative Reasoning Measure of the GRE revised General Test

Math Review for the Quantitative Reasoning Measure of the GRE revised General Test www.ets.org Overview This Math Review will familiarize you with the mathematical skills and concepts that are important

### PGR Computing Programming Skills

PGR Computing Programming Skills Dr. I. Hawke 2008 1 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

### How do you compare numbers? On a number line, larger numbers are to the right and smaller numbers are to the left.

The verbal answers to all of the following questions should be memorized before completion of pre-algebra. Answers that are not memorized will hinder your ability to succeed in algebra 1. Number Basics

### Data Tool Platform SQL Development Tools

Data Tool Platform SQL Development Tools ekapner Contents Setting SQL Development Preferences...5 Execution Plan View Options Preferences...5 General Preferences...5 Label Decorations Preferences...6

### The Center for Teaching, Learning, & Technology

The Center for Teaching, Learning, & Technology Instructional Technology Workshops Microsoft Excel 2010 Formulas and Charts Albert Robinson / Delwar Sayeed Faculty and Staff Development Programs Colston

### Lab 1. The Fourier Transform

Lab 1. The Fourier Transform Introduction In the Communication Labs you will be given the opportunity to apply the theory learned in Communication Systems. Since this is your first time to work in the

### I PUC - Computer Science. Practical s Syllabus. Contents

I PUC - Computer Science Practical s Syllabus Contents Topics 1 Overview Of a Computer 1.1 Introduction 1.2 Functional Components of a computer (Working of each unit) 1.3 Evolution Of Computers 1.4 Generations

### Lies My Calculator and Computer Told Me

Lies My Calculator and Computer Told Me 2 LIES MY CALCULATOR AND COMPUTER TOLD ME Lies My Calculator and Computer Told Me See Section.4 for a discussion of graphing calculators and computers with graphing

### 2+2 Just type and press enter and the answer comes up ans = 4

Demonstration Red text = commands entered in the command window Black text = Matlab responses Blue text = comments 2+2 Just type and press enter and the answer comes up 4 sin(4)^2.5728 The elementary functions

### grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print

grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print In the simplest terms, grep (global regular expression print) will search input

### Everyday Mathematics GOALS

Copyright Wright Group/McGraw-Hill GOALS The following tables list the Grade-Level Goals organized by Content Strand and Program Goal. Content Strand: NUMBER AND NUMERATION Program Goal: Understand the

### Microsoft Excel 2010 Part 3: Advanced Excel

CALIFORNIA STATE UNIVERSITY, LOS ANGELES INFORMATION TECHNOLOGY SERVICES Microsoft Excel 2010 Part 3: Advanced Excel Winter 2015, Version 1.0 Table of Contents Introduction...2 Sorting Data...2 Sorting

1 6 JavaScript: Introduction to Scripting 2 Comment is free, but facts are sacred. C. P. Scott The creditor hath a better memory than the debtor. James Howell When faced with a decision, I always ask,

### SYSTEMS OF EQUATIONS AND MATRICES WITH THE TI-89. by Joseph Collison

SYSTEMS OF EQUATIONS AND MATRICES WITH THE TI-89 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

### IV-1Working with Commands

Chapter IV-1 IV-1Working with Commands Overview... 2 Multiple Commands... 2 Comments... 2 Maximum Length of a Command... 2 Parameters... 2 Liberal Object Names... 2 Data Folders... 3 Types of Commands...

### Character strings and. Lab tutor : Dennis Yang LIU Email : csygliu@comp.polyu.edu.hk Lab 5 : Oct. 16, 2014

Lab 5 of COMP 319 Character strings and File I/O Lab tutor : Dennis Yang LIU Email : csygliu@comp.polyu.edu.hk Lab 5 : Oct. 16, 2014 1 Review of Lab 4 1. General concepts of user-defined functions 2. How

Retrieving Data Using the SQL SELECT Statement Objectives After completing this lesson, you should be able to do the following: List the capabilities of SQL SELECT statements Execute a basic SELECT statement

### Object 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

### 1998. (R. Bird and P. Wadler, Introduction to Functional Programming, Prentice

Mathematical Structures in Programs 15 Algebra) The Shorter Oxford English Dictionary): the reunion of broken parts a calculus of symbols combined according to defined laws Haskell 3 4 Richard Bird. Introduction

### Instructor Özgür ZEYDAN (PhD) CIV 112 Computer Programming http://cevre.beun.edu.tr/zeydan/

Algorithms Pseudocode Flowcharts (PhD) CIV 112 Computer Programming http://cevre.beun.edu.tr/zeydan/ Why do we have to learn computer programming? Computers can make calculations at a blazing speed without

### Quantitative vs. Categorical Data: A Difference Worth Knowing Stephen Few April 2005

Quantitative vs. Categorical Data: A Difference Worth Knowing Stephen Few April 2005 When you create a graph, you step through a series of choices, including which type of graph you should use and several

### 2. Capitalize initial keyword In the example above, READ and WRITE are in caps. There are just a few keywords we will use:

Pseudocode: An Introduction Flowcharts were the first design tool to be widely used, but unfortunately they do t very well reflect some of the concepts of structured programming. Pseudocode, on the other

### This loop prints out the numbers from 1 through 10 on separate lines. How does it work? Output: 1 2 3 4 5 6 7 8 9 10

Java Loops & Methods The while loop Syntax: while ( condition is true ) { do these statements Just as it says, the statements execute while the condition is true. Once the condition becomes false, execution