MATLAB for Chemical engineer

Size: px
Start display at page:

Download "MATLAB for Chemical engineer"

Transcription

1 University of Baghdad College of Engineering Department of Chemical Engineering MATLAB for Chemical engineer Basic and Applications Lecture No. 9 Dr. Mahmood Khazzal Hummadi Samar Kareem 2016

2 Lecture No. 9 Looping statements and descision statements: The conditions are given below. The column of the left hand side is to compare two values and those on the right hand side are to add multiple conditions: 1. LOOPING: Looping or iterative functions are extremely useful in engineering problem solving. 2 MKH

3 1. For statements loop a specific number of times, and keep track of each iteration with an incrementing index variable. A loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages. For example, preallocate a 10-element vector, and calculate five values: x = ones(1,10); for n = 2:6 x(n) = 2 * x(n - 1); 2. While statements loop as long as a condition remains true. For example, find the first integer n for which factorial(n) is a 100-digit number: n = 1; nfactorial = 1; while nfactorial < 1e100 n = n + 1; nfactorial = nfactorial * n; Each loop requires the keyword. 3 MKH

4 It is a good idea to indent the loops for readability, especially when they are nested (that is, when one loop contains another loop): A = zeros(5,100); for m = 1:5 for n = 1:100 A(m, n) = 1/(m + n - 1); You can programmatically exit a loop using a break statement, or skip to the next iteration of a loop using a continue statement. Exit Loop before Expression Is False. Example: Sum a sequence of random numbers until the next random number is greater than an upper limit. Then, exit the loop using a break statement. limit = 0.8; s = 0; while 1 tmp = rand; if tmp > limit break s = s + tmp; 4 MKH

5 2. Decision Decision making structures require that the programmer should specify one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false. 1. if... statement If the expression evaluates to true, then the block of code inside the if statement will be executed. If the expression evaluates to false, then the first set of code after the statement will be executed. Example: Create a script file and type the following code : a= 10; % check the condition using if statement if a < 20 % if condition is true then print the following fprintf('a is less than 20\n' ); fprintf('value of a is : %d\n', a); 5 MKH

6 2. if...else... statement An if statement can be followed by an optional else statement, which executes when the expression is false. If the boolean expression evaluates to true, then the if block of code will be executed, otherwise else block of code will be executed. If the boolean expression evaluates to true, then the if block of code will be executed, otherwise else block of code will be executed. Example Create a script file and type the following code a = 100; % check the boolean condition if a < 20 else % if condition is true then print the following fprintf('a is less than 20\n' ); % if condition is false then print the following fprintf('a is not less than 20\n' ); fprintf('value of a is : %d\n', a); 3. if...elseif...elseif...else... Statements. An if statement can be followed by one (or more) optional elseif... and anelse statement, which is very useful to test various conditions. When using if... elseif...else statements, are few points to keep in mind: there An if can have zero or one else's and it must come after any elseif's. An if can have zero to many elseif's and they must come before the else. Once an else if succeeds, none of the remaining elseif's or else's will be tested. if <expression 1> % Executes when the expression 1 is true <statement(s)> 6 MKH

7 elseif <expression 2> % Executes when the boolean expression 2 is true <statement(s)> Elseif <expression 3> % Executes when the boolean expression 3 is true <statement(s)> else % executes when the none of the above condition is true <statement(s)> Example: a = 100; %check the boolean condition if a == 10 % if condition is true then print the following fprintf('value of a is 10\n' ); elseif( a == 20 ) % if else if condition is true fprintf('value of a is 20\n' ); elseif a == 30 else % if else if condition is true fprintf('value of a is 30\n' ); % if none of the conditions is true ' fprintf('none of the values are matching\n'); fprintf('exact value of a is: %d\n', a ); 4. The Nested if Statements It is always legal in MATLAB to nest if-else statements which means you can use one if or elseif statement inside another if or elseif statement(s). Syntax 7 MKH

8 The syntax for a nested if statement is as follows if <expression 1> % Executes when the boolean expression 1 is true if <expression 2> % Executes when the boolean expression 2 is true You can nest elseif...else in the similar way as you have nested if statement. Example Create a script file and type the following code in it a = 100; b = 200; % check the boolean condition if( a == 100 ) % if condition is true then check the following if( b == 200 ) % if condition is true then print the following fprintf('value of a is 100 and b is 200\n' ); fprintf('exact value of a is : %d\n', a ); fprintf('exact value of b is : %d\n', b ); Answer Value of a is 100 and b is 200 Exact value of a is : 100 Exact value of b is : The switch Statement A switch block conditionally executes one set of statements from several choices. Each choice is covered by a case statement. An evaluated switch_expression is a scalar or string. An evaluated case_expression is a scalar, a string or a cell array of scalars or strings. 8 MKH

9 The switch block tests each case until one of the cases is true. A case is true when For numbers, eq(case_expression,switch_expression). For strings, strcmp(case_expression,switch_expression). For objects that support theeq(case_expression,switch_expression). For a cell array case_expression, at least one of the elements of the cell array matches switch_expression, as defined above for numbers, strings and objects. When a case is true, MATLAB executes the corresponding statements and then exits the switch block. The otherwise block is optional and executes only when no case is true. Syntax The syntax of switch statement in MATLAB is switch <switch_expression> case <case_expression> <statements> case <case_expression> <statements> otherwise <statements> Example Create a script file and type the following code in it grade = 'B'; switch(grade) case 'A' fprintf('excellent!\n' ); 9 MKH

10 case 'B' fprintf('well done\n' ); case 'C' fprintf('well done\n' ); case 'D' fprintf('you passed\n' ); case 'F' fprintf('better try again\n' ); otherwise fprintf('invalid grade\n' ); When you run the file, it displays Well done 6. The Nested switch Statements It is possible to have a switch as part of the statement sequence of an outer switch. Even if the case constants of the inner and outer switch contain common values, no conflicts will arise. Syntax The syntax for a nested switch statement is as follows switch(ch1) case 'A' fprintf('this A is part of outer switch'); switch(ch2) case 'A' fprintf('this A is part of inner switch' ); case 'B' fprintf('this B is part of inner switch' ); 10 MKH

11 case 'B' fprintf('this B is part of outer switch' ); Example Create a script file and type the following code in it a = 100; b = 200; switch(a) case 100 fprintf('this is part of outer switch %d\n', a ); switch(b) case 200 fprintf('this is part of inner switch %d\n', a ); fprintf('exact value of a is : %d\n', a ); fprintf('exact value of b is : %d\n', b ); When you run the file, it displays This is part of outer switch 100 This is part of inner switch 100 Exact value of a is : 100 Exact value of b is : MKH

12 Problems Q1) Find the value of y. Use function. A) B) Q2)Write the code required to determine the value of Q. The arrays Z and Y are generated as following: Z i =i+1, Y i =i 2 -i.use Subroutine Q N i0 Y i N! N i0 Z! i Q3)Solve the second order algebraic equation with one variable ax 2 + bx + c =0. The solution. Note use Function. b x b2 4ac 2a Q4) Calculate the kinetic and potential energies of an object at different velocities and heights respectively.. Use velocities and heights ranged from 1 to 1000 m ( step 1). Q5) Make an array for the numbers from 0 to 100, then make a second one represents the results of multiplying each sequential two numbers in the first array. Q6) The one dimension arrays A and B,and the number for the each array are 20 value. calculate the summation of array A and the summation of array B and find the y value, where A(i)=i and B(i)= i^2, where the value of y is calculate as following : Where MB is the average of B array. 12 MKH

13 Q7) Design windows application to find the densities of different six gases ( O 2,H 2, N 2, CO 2, CH 4,C 3 H 8, C 2 H 2 ) at temperatures ranged from 0 to 300 o C (step 10 ). The user should enter pressure in atm. Q8)Use loop to find the bubble point of ternary system (Ethanol 40 mol%, Water 20 mol% and Benzene 40 mol%). Knowing that the vapor pressure for three components are calculated by: Ethanol Po e=exp( /(t-50.5)) Water Po w=exp( /(t-46.13)) Benzene Po b=exp( /(t-52.36)) Where Ki= P o i /Pt,Pt=760,yi =Kixi, At Bubble point Σyi=ΣKi xi =1 Q9)Given that the vapor pressure of methyl chloride at K is bar, write a code to calculate the molar volume of saturated vapor at these conditions using Redlich/Kwong equation. Knowing; a= *r 2 T c 2.5 /Pc b= *rt c /P c V i+1 =(RT/P)+b- (a*(v i -b))/(t 1/2 PV i (V i +b)) R=83.14, Tc= k, Pc= 66.8 bar Q10) A simple force balance on a spherical particle reaching terminal velocity in a fluid is given by; Where: V t : Terminal velocity in m/s g : Acceleration of gravity p p : Particle density D p : The diameter of the spherical particle in m C D : Dimensionless drag coefficient. The drag coefficient on a spherical particle at terminal velocity varies with Reynolds number (Re) as followings: C D =24/Re for Re< 0.1 C D =24*(1+0.14* Re^0.7)/Re for 0.1=<Re=< 1000 CD=0.44 for 1000<Re=< CD=0.19-8*10^4/Re for <Re Q11)Write a computer program to calculate molar volume and compressibility factor for gaseous ammonia at a pressure values (1-30 atm) by using of the Redlich-Kwong equation of state. The equations and variables are listed below. R= gas constant (R = atm L/g-mol K),Tc= the critical temperature (405.5 K for ammonia) Pc= the critical pressure (111.3 atm for ammonia) Compressibility factor is given by Z= PV/RT 13 MKH

14 Q12)Calculate pressure drop (N/m 2 ) across a pipe of diameter d (m) and length L (m). The fluid properties are velocity u (m/s), density ρ (kg/m 3 ), and viscosity µ (kg/m.s). du Re For laminar flow: Re < 2100: 8 j f Re For turbulent flow: 10 5 > Re > 2100: j f 1/ 4 Re L 2 P 4 j f u d Q13) write the code required to calculate the density in g/lit of 50 mol% propane (C 3 H 8 )-50 mol% isobutene (i-c 4 H 8 ) gaseous mixture.the pressure in atm, temperature in K and critical constants Pc and Tc for propane and iso-butane.(note: Use function ). M p z z i ri 0.2T mix mix c ri M yi p, T p y i p y z PM z RT i i ri i T T ci ri lit. atm R gmol. k Comp. Pc, atm Tc, K M, g/gmol C 4 H C 3 H Q14) Estimate the heat capacity of difference gases (O 2,H 2, N 2, CO 2, CH 4,C 3 H 8, C 2 H 2 ) at different temperatures ( from 0 to 1000 o C step 10 )., Cp J/mol K, T deg K. component a b c d O E E E-08 H E E E-10 N E E E-08 CO E E E-09 CH E E E-08 C 3 H E E E-09 C 2 H E E E MKH

Decision Making in C

Decision Making in C Decision Making in C Decision making structures require that the programmer specify one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed

More information

Programming in MATLAB Part 2

Programming in MATLAB Part 2 Programming in MATLAB Part 2 A computer program is a sequence of computer commands. In a simple program the commands are executed one after the other in the order they are typed. MATLAB provides several

More information

MATLAB Operators, control flow and scripting. Edited by Péter Vass

MATLAB Operators, control flow and scripting. Edited by Péter Vass MATLAB Operators, control flow and scripting Edited by Péter Vass Operators An operator is a symbol which is used for specifying some kind of operation to be executed. An operator is always the member

More information

Following is the general form of a typical decision making structure found in most of the programming languages:

Following is the general form of a typical decision making structure found in most of the programming languages: Decision Making Decision making structures have one or more conditions to be evaluated or tested by the program, along with a statement or statements that are to be executed if the condition is determined

More information

21-Loops Part 2 text: Chapter ECEGR 101 Engineering Problem Solving with Matlab Professor Henry Louie

21-Loops Part 2 text: Chapter ECEGR 101 Engineering Problem Solving with Matlab Professor Henry Louie 21-Loops Part 2 text: Chapter 6.4-6.6 ECEGR 101 Engineering Problem Solving with Matlab Professor Henry Louie While Loop Infinite Loops Break and Continue Overview Dr. Henry Louie 2 WHILE Loop Used to

More information

Loops and Conditionals. HORT Lecture 11 Instructor: Kranthi Varala

Loops and Conditionals. HORT Lecture 11 Instructor: Kranthi Varala Loops and Conditionals HORT 59000 Lecture 11 Instructor: Kranthi Varala Relational Operators These operators compare the value of two expressions and returns a Boolean value. Beware of comparing across

More information

Relational & Logical Operators, Selection Statements

Relational & Logical Operators, Selection Statements Relational & Logical Operators, Selection Statements by Ahmet Sacan selection statements, branching statements, condition, relational expression, Boolean expression, logical expression, relational operators,

More information

Modeling Evaporating Liquid Spray

Modeling Evaporating Liquid Spray Tutorial 16. Modeling Evaporating Liquid Spray Introduction In this tutorial, FLUENT s air-blast atomizer model is used to predict the behavior of an evaporating methanol spray. Initially, the air flow

More information

Thinking Like an Engineer. Instructor Slides

Thinking Like an Engineer. Instructor Slides Instructor Slides Thinking Like an Engineer An Active Learning Approach Stephan, Bowman, Park, Sill, Ohland Third Edition Copyright 2015 Pearson Prentice-Hall, Inc. Create relational expressions using

More information

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan Lecture 08-1 Programming in C++ PART 1 By Assistant Professor Dr. Ali Kattan 1 The Conditional Operator The conditional operator is similar to the if..else statement but has a shorter format. This is useful

More information

Modeling Evaporating Liquid Spray

Modeling Evaporating Liquid Spray Tutorial 17. Modeling Evaporating Liquid Spray Introduction In this tutorial, the air-blast atomizer model in ANSYS FLUENT is used to predict the behavior of an evaporating methanol spray. Initially, the

More information

Mathcad Lecture #3 In-class Worksheet Functions

Mathcad Lecture #3 In-class Worksheet Functions Mathcad Lecture #3 In-class Worksheet Functions At the end of this lecture, you should be able to: find and use intrinsic Mathcad Functions for fundamental, trigonometric, and if statements construct compound

More information

Computer Programing. for Physicists [SCPY204] Class 02: 25 Jan 2018

Computer Programing. for Physicists [SCPY204] Class 02: 25 Jan 2018 Computer Programing Class 02: 25 Jan 2018 [SCPY204] for Physicists Content: Data, Data type, program control, condition and loop, function and recursion, variable and scope Instructor: Puwis Amatyakul

More information

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

V2 2/4/ Ch Programming in C. Flow of Control. Flow of Control. Flow of control The order in which statements are executed

V2 2/4/ Ch Programming in C. Flow of Control. Flow of Control. Flow of control The order in which statements are executed Programming in C 1 Flow of Control Flow of control The order in which statements are executed Transfer of control When the next statement executed is not the next one in sequence 2 Flow of Control Control

More information

Informatics Ingeniería en Electrónica y Automática Industrial. Control flow

Informatics Ingeniería en Electrónica y Automática Industrial. Control flow Informatics Ingeniería en Electrónica y Automática Industrial Control flow V1.1 Autores Control Flow Statements in C language Introduction if-else switch while for do-while break continue return goto 2

More information

Flow of Control. Flow of control The order in which statements are executed. Transfer of control

Flow of Control. Flow of control The order in which statements are executed. Transfer of control 1 Programming in C Flow of Control Flow of control The order in which statements are executed Transfer of control When the next statement executed is not the next one in sequence 2 Flow of Control Control

More information

Selection Statements

Selection Statements Selection Statements by Ahmet Sacan selection statements, branching statements, condition, relational expression, Boolean expression, logical expression, relational operators, logical operators, truth

More information

Programming for Experimental Research. Flow Control

Programming for Experimental Research. Flow Control Programming for Experimental Research Flow Control FLOW CONTROL In a simple program, the commands are executed one after the other in the order they are typed. Many situations require more sophisticated

More information

CP FAQS Q-1) Define flowchart and explain Various symbols of flowchart Q-2) Explain basic structure of c language Documentation section :

CP FAQS Q-1) Define flowchart and explain Various symbols of flowchart Q-2) Explain basic structure of c language Documentation section : CP FAQS Q-1) Define flowchart and explain Various symbols of flowchart ANS. Flowchart:- A diagrametic reperesentation of program is known as flowchart Symbols Q-2) Explain basic structure of c language

More information

Introduction to C Programming

Introduction to C Programming 1 2 Introduction to C Programming 2.6 Decision Making: Equality and Relational Operators 2 Executable statements Perform actions (calculations, input/output of data) Perform decisions - May want to print

More information

Programming and Data Structures

Programming and Data Structures Programming and Data Structures Document Prepared By: Dr. Subhankar Joardar (H.O.D.) Mrs. Gitika Maity (Asst.Prof.) Mrs. Patrali Pradhan (Asst.Prof.) Mrs. Sunanda Jana (Asst.Prof.) Mrs. Rajrupa Metia (Asst.Prof.)

More information

Computer Programming ECIV 2303 Chapter 6 Programming in MATLAB Instructor: Dr. Talal Skaik Islamic University of Gaza Faculty of Engineering

Computer Programming ECIV 2303 Chapter 6 Programming in MATLAB Instructor: Dr. Talal Skaik Islamic University of Gaza Faculty of Engineering Computer Programming ECIV 2303 Chapter 6 Programming in MATLAB Instructor: Dr. Talal Skaik Islamic University of Gaza Faculty of Engineering 1 Introduction A computer program is a sequence of computer

More information

Introduction to CFX. Workshop 2. Transonic Flow Over a NACA 0012 Airfoil. WS2-1. ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.

Introduction to CFX. Workshop 2. Transonic Flow Over a NACA 0012 Airfoil. WS2-1. ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved. Workshop 2 Transonic Flow Over a NACA 0012 Airfoil. Introduction to CFX WS2-1 Goals The purpose of this tutorial is to introduce the user to modelling flow in high speed external aerodynamic applications.

More information

Physics 326G Winter Class 6

Physics 326G Winter Class 6 Physics 36G Winter 008 Class 6 Today we will learn about functions, and also about some basic programming that allows you to control the execution of commands in the programs you write. You have already

More information

7 Control Structures, Logical Statements

7 Control Structures, Logical Statements 7 Control Structures, Logical Statements 7.1 Logical Statements 1. Logical (true or false) statements comparing scalars or matrices can be evaluated in MATLAB. Two matrices of the same size may be compared,

More information

Control Statements. Objectives. ELEC 206 Prof. Siripong Potisuk

Control Statements. Objectives. ELEC 206 Prof. Siripong Potisuk Control Statements ELEC 206 Prof. Siripong Potisuk 1 Objectives Learn how to change the flow of execution of a MATLAB program through some kind of a decision-making process within that program The program

More information

Chapter 4: Programming with MATLAB

Chapter 4: Programming with MATLAB Chapter 4: Programming with MATLAB Topics Covered: Programming Overview Relational Operators and Logical Variables Logical Operators and Functions Conditional Statements For Loops While Loops Debugging

More information

Introduction to ANSYS CFX

Introduction to ANSYS CFX Workshop 03 Fluid flow around the NACA0012 Airfoil 16.0 Release Introduction to ANSYS CFX 2015 ANSYS, Inc. March 13, 2015 1 Release 16.0 Workshop Description: The flow simulated is an external aerodynamics

More information

function [s p] = sumprod (f, g)

function [s p] = sumprod (f, g) Outline of the Lecture Introduction to M-function programming Matlab Programming Example Relational operators Logical Operators Matlab Flow control structures Introduction to M-function programming M-files:

More information

Solved with COMSOL Multiphysics 4.0a. COPYRIGHT 2010 COMSOL AB.

Solved with COMSOL Multiphysics 4.0a. COPYRIGHT 2010 COMSOL AB. Journal Bearing Introduction Journal bearings are used to carry radial loads, for example, to support a rotating shaft. A simple journal bearing consists of two rigid cylinders. The outer cylinder (bearing)

More information

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #16 Loops: Matrix Using Nested for Loop

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #16 Loops: Matrix Using Nested for Loop Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #16 Loops: Matrix Using Nested for Loop In this section, we will use the, for loop to code of the matrix problem.

More information

Terminal Falling Velocity of a Sand Grain

Terminal Falling Velocity of a Sand Grain Terminal Falling Velocity of a Sand Grain Introduction The first stop for polluted water entering a water work is normally a large tank, where large particles are left to settle. More generally, gravity

More information

Flow Control. CSC215 Lecture

Flow Control. CSC215 Lecture Flow Control CSC215 Lecture Outline Blocks and compound statements Conditional statements if - statement if-else - statement switch - statement? : opertator Nested conditional statements Repetitive statements

More information

Tutorial 1. Introduction to Using FLUENT: Fluid Flow and Heat Transfer in a Mixing Elbow

Tutorial 1. Introduction to Using FLUENT: Fluid Flow and Heat Transfer in a Mixing Elbow Tutorial 1. Introduction to Using FLUENT: Fluid Flow and Heat Transfer in a Mixing Elbow Introduction This tutorial illustrates the setup and solution of the two-dimensional turbulent fluid flow and heat

More information

Engineering Innovation Center MATLAB Basics

Engineering Innovation Center MATLAB Basics Engineering Innovation Center MATLAB Basics MATLAB Short for MATrix LABoratory Both a programming language and the interface Designed to deal with large sets of data and analysis Allows matrix manipulations,

More information

Strömningslära Fluid Dynamics. Computer laboratories using COMSOL v4.4

Strömningslära Fluid Dynamics. Computer laboratories using COMSOL v4.4 UMEÅ UNIVERSITY Department of Physics Claude Dion Olexii Iukhymenko May 15, 2015 Strömningslära Fluid Dynamics (5FY144) Computer laboratories using COMSOL v4.4!! Report requirements Computer labs must

More information

Tutorial: Heat and Mass Transfer with the Mixture Model

Tutorial: Heat and Mass Transfer with the Mixture Model Tutorial: Heat and Mass Transfer with the Mixture Model Purpose The purpose of this tutorial is to demonstrate the use of mixture model in FLUENT 6.0 to solve a mixture multiphase problem involving heat

More information

Loops / Repetition Statements

Loops / Repetition Statements Loops / Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops C has three kinds of repetition statements: the while loop the for

More information

Module 16: Data Flow Analysis in Presence of Procedure Calls Lecture 32: Iteration. The Lecture Contains: Iteration Space.

Module 16: Data Flow Analysis in Presence of Procedure Calls Lecture 32: Iteration. The Lecture Contains: Iteration Space. The Lecture Contains: Iteration Space Iteration Vector Normalized Iteration Vector Dependence Distance Direction Vector Loop Carried Dependence Relations Dependence Level Iteration Vector - Triangular

More information

Tutorial: Hydrodynamics of Bubble Column Reactors

Tutorial: Hydrodynamics of Bubble Column Reactors Tutorial: Introduction The purpose of this tutorial is to provide guidelines and recommendations for solving a gas-liquid bubble column problem using the multiphase mixture model, including advice on solver

More information

EOS Mixing Rule Parameters

EOS Mixing Rule Parameters EOS Mixing Rule Parameters GENPAR Fitting of Equation of State Mixing Rule Parameters for Flash and VLE Calculation DDBSP Dortmund Data Bank Software Package DDBST Dortmund Data Bank Software & Separation

More information

INTRODUCTION TO C++ PROGRAM CONTROL. Dept. of Electronic Engineering, NCHU. Original slides are from

INTRODUCTION TO C++ PROGRAM CONTROL. Dept. of Electronic Engineering, NCHU. Original slides are from INTRODUCTION TO C++ PROGRAM CONTROL Original slides are from http://sites.google.com/site/progntut/ Dept. of Electronic Engineering, NCHU Outline 2 Repetition Statement for while do.. while break and continue

More information

Non-Newtonian Transitional Flow in an Eccentric Annulus

Non-Newtonian Transitional Flow in an Eccentric Annulus Tutorial 8. Non-Newtonian Transitional Flow in an Eccentric Annulus Introduction The purpose of this tutorial is to illustrate the setup and solution of a 3D, turbulent flow of a non-newtonian fluid. Turbulent

More information

Control structures in C. Going beyond sequential

Control structures in C. Going beyond sequential Control structures in C Going beyond sequential Flow of control in a program Start (main) Program starts with the first statement in main Instructions proceed sequentially: One at a time Top to bottom

More information

4.0 Programming with MATLAB

4.0 Programming with MATLAB 4.0 Programming with MATLAB 4.1 M-files The term M-file is obtained from the fact that such files are stored with.m extension. M-files are alternative means of performing computations so as to expand MATLAB

More information

EP578 Computing for Physicists

EP578 Computing for Physicists EP578 Computing for Physicists Topic 3 Selection & Loops Department of Engineering Physics University of Gaziantep Course web page wwwgantepedutr/~bingul/ep578 Oct 2011 Sayfa 1 1 Introduction This lecture

More information

Computational Study of Laminar Flowfield around a Square Cylinder using Ansys Fluent

Computational Study of Laminar Flowfield around a Square Cylinder using Ansys Fluent MEGR 7090-003, Computational Fluid Dynamics :1 7 Spring 2015 Computational Study of Laminar Flowfield around a Square Cylinder using Ansys Fluent Rahul R Upadhyay Master of Science, Dept of Mechanical

More information

TYPE 529: RADIANT SLAB

TYPE 529: RADIANT SLAB TYPE 529: RADIANT SLAB General Description This component is intended to model a radiant floor-heating slab, embedded in soil, and containing a number of fluid filled pipes. The heat transfer within the

More information

INTRODUCTION TO COMPUTER SCIENCE - LAB

INTRODUCTION TO COMPUTER SCIENCE - LAB LAB # O2: OPERATORS AND CONDITIONAL STATEMENT Assignment operator (=) The assignment operator assigns a value to a variable. X=5; Expression y = 2 + x; Increment and decrement (++, --) suffix X++ X-- prefix

More information

Flow Control: Branches and loops

Flow Control: Branches and loops Flow Control: Branches and loops In this context flow control refers to controlling the flow of the execution of your program that is, which instructions will get carried out and in what order. In the

More information

A B C D E. Settings Choose height, H, free stream velocity, U, and fluid (dynamic viscosity and density ) so that: Reynolds number

A B C D E. Settings Choose height, H, free stream velocity, U, and fluid (dynamic viscosity and density ) so that: Reynolds number Individual task Objective To derive the drag coefficient for a 2D object, defined as where D (N/m) is the aerodynamic drag force (per unit length in the third direction) acting on the object. The object

More information

CHAPTER 3. Elementary Fluid Dynamics

CHAPTER 3. Elementary Fluid Dynamics CHAPTER 3. Elementary Fluid Dynamics - Understanding the physics of fluid in motion - Derivation of the Bernoulli equation from Newton s second law Basic Assumptions of fluid stream, unless a specific

More information

Middle East Technical University Mechanical Engineering Department ME 485 CFD with Finite Volume Method Fall 2017 (Dr. Sert)

Middle East Technical University Mechanical Engineering Department ME 485 CFD with Finite Volume Method Fall 2017 (Dr. Sert) Middle East Technical University Mechanical Engineering Department ME 485 CFD with Finite Volume Method Fall 2017 (Dr. Sert) ANSYS Fluent Tutorial Developing Laminar Flow in a 2D Channel 1 How to use This

More information

This is the basis for the programming concept called a loop statement

This is the basis for the programming concept called a loop statement Chapter 4 Think back to any very difficult quantitative problem that you had to solve in some science class How long did it take? How many times did you solve it? What if you had millions of data points

More information

Research and Design working characteristics of orthogonal turbine Nguyen Quoc Tuan (1), Chu Dinh Do (2), Quach Thi Son (2)

Research and Design working characteristics of orthogonal turbine Nguyen Quoc Tuan (1), Chu Dinh Do (2), Quach Thi Son (2) GSJ: VOLUME 6, ISSUE 6, JUNE 018 116 Research and Design working characteristics of orthogonal turbine Nguyen Quoc Tuan (1), Chu Dinh Do (), Quach Thi Son () (1) Institute for hydro power and renewable

More information

Programming Basics and Practice GEDB029 Decision Making, Branching and Looping. Prof. Dr. Mannan Saeed Muhammad bit.ly/gedb029

Programming Basics and Practice GEDB029 Decision Making, Branching and Looping. Prof. Dr. Mannan Saeed Muhammad bit.ly/gedb029 Programming Basics and Practice GEDB029 Decision Making, Branching and Looping Prof. Dr. Mannan Saeed Muhammad bit.ly/gedb029 Decision Making and Branching C language possesses such decision-making capabilities

More information

Lecture 5 Tao Wang 1

Lecture 5 Tao Wang 1 Lecture 5 Tao Wang 1 Objectives In this chapter, you will learn about: Selection criteria Relational operators Logical operators The if-else statement Nested if statements C++ for Engineers and Scientists,

More information

There are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions.

There are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions. Introduction In the programs that we have dealt with so far, all statements inside the main function were executed in sequence as they appeared, one after the other. This type of sequencing is adequate

More information

In this lab, you will learn more about selection statements. You will get familiar to

In this lab, you will learn more about selection statements. You will get familiar to Objective: In this lab, you will learn more about selection statements. You will get familiar to nested if and switch statements. Nested if Statements: When you use if or if...else statement, you can write

More information

The Java language has a wide variety of modifiers, including the following:

The Java language has a wide variety of modifiers, including the following: PART 5 5. Modifier Types The Java language has a wide variety of modifiers, including the following: Java Access Modifiers Non Access Modifiers 5.1 Access Control Modifiers Java provides a number of access

More information

5. Selection: If and Switch Controls

5. Selection: If and Switch Controls Computer Science I CS 135 5. Selection: If and Switch Controls René Doursat Department of Computer Science & Engineering University of Nevada, Reno Fall 2005 Computer Science I CS 135 0. Course Presentation

More information

H.C. Chen 1/24/2019. Chapter 4. Branching Statements and Program Design. Programming 1: Logical Operators, Logical Functions, and the IF-block

H.C. Chen 1/24/2019. Chapter 4. Branching Statements and Program Design. Programming 1: Logical Operators, Logical Functions, and the IF-block Chapter 4 Branching Statements and Program Design Programming 1: Logical Operators, Logical Functions, and the IF-block Learning objectives: 1. Write simple program modules to implement single numerical

More information

Introduction. C provides two styles of flow control:

Introduction. C provides two styles of flow control: Introduction C provides two styles of flow control: Branching Looping Branching is deciding what actions to take and looping is deciding how many times to take a certain action. Branching constructs: if

More information

PDS Lab Section 16 Autumn Tutorial 3. C Programming Constructs

PDS Lab Section 16 Autumn Tutorial 3. C Programming Constructs PDS Lab Section 16 Autumn-2017 Tutorial 3 C Programming Constructs This flowchart shows how to find the roots of a Quadratic equation Ax 2 +Bx+C = 0 Start Input A,B,C x B 2 4AC False x If 0 True B x 2A

More information

C++ PROGRAMMING SKILLS Part 2 Programming Structures

C++ PROGRAMMING SKILLS Part 2 Programming Structures C++ PROGRAMMING SKILLS Part 2 Programming Structures If structure While structure Do While structure Comments, Increment & Decrement operators For statement Break & Continue statements Switch structure

More information

Compressible Flow in a Nozzle

Compressible Flow in a Nozzle SPC 407 Supersonic & Hypersonic Fluid Dynamics Ansys Fluent Tutorial 1 Compressible Flow in a Nozzle Ahmed M Nagib Elmekawy, PhD, P.E. Problem Specification Consider air flowing at high-speed through a

More information

CS110D: PROGRAMMING LANGUAGE I

CS110D: PROGRAMMING LANGUAGE I CS110D: PROGRAMMING LANGUAGE I Computer Science department Lecture 5&6: Loops Lecture Contents Why loops?? While loops for loops do while loops Nested control structures Motivation Suppose that you need

More information

Chemical Equilibrium CHAPTER 15. Chemistry: The Molecular Nature of Matter, 6 th edition By Jesperson, Brady, & Hyslop

Chemical Equilibrium CHAPTER 15. Chemistry: The Molecular Nature of Matter, 6 th edition By Jesperson, Brady, & Hyslop Chemical Equilibrium CHAPTER 15 Chemistry: The Molecular Nature of Matter, 6 th edition By Jesperson, Brady, & Hyslop CHAPTER 15 Chemical Equilibrium Learning Objectives: q Reversible Reactions and Equilibrium

More information

Computational Physics - Fortran February 1997

Computational Physics - Fortran February 1997 Fortran 90 Decision Structures IF commands 3 main possibilities IF (logical expression) IF (logical expression) THEN IF (logical expression) THEN IF (logical expression) THEN expression TRUE expression

More information

HIGH PERFORMANCE COMPUTATION (HPC) FOR THE

HIGH PERFORMANCE COMPUTATION (HPC) FOR THE HIGH PERFORMANCE COMPUTATION (HPC) FOR THE DEVELOPMENT OF FLUIDIZED BED TECHNOLOGIES FOR BIOMASS GASIFICATION AND CO2 CAPTURE P. Fede, H. Neau, O. Simonin Université de Toulouse; INPT, UPS ; IMFT ; 31400

More information

COGS 119/219 MATLAB for Experimental Research. Fall 2016 Week 1 Built-in array functions, Data types.m files, begin Flow Control

COGS 119/219 MATLAB for Experimental Research. Fall 2016 Week 1 Built-in array functions, Data types.m files, begin Flow Control COGS 119/219 MATLAB for Experimental Research Fall 2016 Week 1 Built-in array functions, Data types.m files, begin Flow Control .m files We can write the MATLAB commands that we type at the command window

More information

CFD-1. Introduction: What is CFD? T. J. Craft. Msc CFD-1. CFD: Computational Fluid Dynamics

CFD-1. Introduction: What is CFD? T. J. Craft. Msc CFD-1. CFD: Computational Fluid Dynamics School of Mechanical Aerospace and Civil Engineering CFD-1 T. J. Craft George Begg Building, C41 Msc CFD-1 Reading: J. Ferziger, M. Peric, Computational Methods for Fluid Dynamics H.K. Versteeg, W. Malalasekara,

More information

Introduction to Matlab. By: Hossein Hamooni Fall 2014

Introduction to Matlab. By: Hossein Hamooni Fall 2014 Introduction to Matlab By: Hossein Hamooni Fall 2014 Why Matlab? Data analytics task Large data processing Multi-platform, Multi Format data importing Graphing Modeling Lots of built-in functions for rapid

More information

Comparison Between Numerical & PIV Experimental Results for Gas-Solid Flow in Ducts

Comparison Between Numerical & PIV Experimental Results for Gas-Solid Flow in Ducts Fabio Kasper Comparison Between Numerical & PIV Experimental Results for Gas-Solid Flow in Ducts Rodrigo Decker, Oscar Sgrott Jr., Henry F. Meier Waldir Martignoni Agenda Introduction The Test Bench Case

More information

Lecture 7 Tao Wang 1

Lecture 7 Tao Wang 1 Lecture 7 Tao Wang 1 Objectives In this chapter, you will learn about: Interactive loop break and continue do-while for loop Common programming errors Scientists, Third Edition 2 while Loops while statement

More information

Theory of control structures

Theory of control structures Theory of control structures Paper written by Bohm and Jacopini in 1966 proposed that all programs can be written using 3 types of control structures. Theory of control structures sequential structures

More information

Module 17: Loops Lecture 34: Symbolic Analysis. The Lecture Contains: Symbolic Analysis. Example: Triangular Lower Limits. Multiple Loop Limits

Module 17: Loops Lecture 34: Symbolic Analysis. The Lecture Contains: Symbolic Analysis. Example: Triangular Lower Limits. Multiple Loop Limits The Lecture Contains: Symbolic Analysis Example: Triangular Lower Limits Multiple Loop Limits Exit in The Middle of a Loop Dependence System Solvers Single Equation Simple Test GCD Test Extreme Value Test

More information

Simulation of Flow Development in a Pipe

Simulation of Flow Development in a Pipe Tutorial 4. Simulation of Flow Development in a Pipe Introduction The purpose of this tutorial is to illustrate the setup and solution of a 3D turbulent fluid flow in a pipe. The pipe networks are common

More information

Microwell Mixing with Surface Tension

Microwell Mixing with Surface Tension Microwell Mixing with Surface Tension Nick Cox Supervised by Professor Bruce Finlayson University of Washington Department of Chemical Engineering June 6, 2007 Abstract For many applications in the pharmaceutical

More information

COMP 208 Computers in Engineering

COMP 208 Computers in Engineering COMP 208 Computers in Engineering Lecture 14 Jun Wang School of Computer Science McGill University Fall 2007 COMP 208 - Lecture 14 1 Review: basics of C C is case sensitive 2 types of comments: /* */,

More information

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments Basics Objectives Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments 2 Class Keyword class used to define new type specify

More information

SPC 307 Aerodynamics. Lecture 1. February 10, 2018

SPC 307 Aerodynamics. Lecture 1. February 10, 2018 SPC 307 Aerodynamics Lecture 1 February 10, 2018 Sep. 18, 2016 1 Course Materials drahmednagib.com 2 COURSE OUTLINE Introduction to Aerodynamics Review on the Fundamentals of Fluid Mechanics Euler and

More information

Using the Eulerian Multiphase Model for Granular Flow

Using the Eulerian Multiphase Model for Granular Flow Tutorial 21. Using the Eulerian Multiphase Model for Granular Flow Introduction Mixing tanks are used to maintain solid particles or droplets of heavy fluids in suspension. Mixing may be required to enhance

More information

Modeling External Compressible Flow

Modeling External Compressible Flow Tutorial 3. Modeling External Compressible Flow Introduction The purpose of this tutorial is to compute the turbulent flow past a transonic airfoil at a nonzero angle of attack. You will use the Spalart-Allmaras

More information

Tutorial 17. Using the Mixture and Eulerian Multiphase Models

Tutorial 17. Using the Mixture and Eulerian Multiphase Models Tutorial 17. Using the Mixture and Eulerian Multiphase Models Introduction: This tutorial examines the flow of water and air in a tee junction. First you will solve the problem using the less computationally-intensive

More information

LECTURE 04 MAKING DECISIONS

LECTURE 04 MAKING DECISIONS PowerPoint Slides adapted from *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* Copyright 2012 Pearson Education Inc. COMPUTER PROGRAMMING LECTURE 04 MAKING DECISIONS

More information

CS 302: INTRODUCTION TO PROGRAMMING. Lectures 7&8

CS 302: INTRODUCTION TO PROGRAMMING. Lectures 7&8 CS 302: INTRODUCTION TO PROGRAMMING Lectures 7&8 Hopefully the Programming Assignment #1 released by tomorrow REVIEW The switch statement is an alternative way of writing what? How do you end a case in

More information

C/C++ Programming for Engineers: Matlab Branches and Loops

C/C++ Programming for Engineers: Matlab Branches and Loops C/C++ Programming for Engineers: Matlab Branches and Loops John T. Bell Department of Computer Science University of Illinois, Chicago Review What is the difference between a script and a function in Matlab?

More information

ECE 202 LAB 3 ADVANCED MATLAB

ECE 202 LAB 3 ADVANCED MATLAB Version 1.2 1 of 13 BEFORE YOU BEGIN PREREQUISITE LABS ECE 201 Labs EXPECTED KNOWLEDGE ECE 202 LAB 3 ADVANCED MATLAB Understanding of the Laplace transform and transfer functions EQUIPMENT Intel PC with

More information

Branches, Conditional Statements

Branches, Conditional Statements Branches, Conditional Statements Branches, Conditional Statements A conditional statement lets you execute lines of code if some condition is met. There are 3 general forms in MATLAB: if if/else if/elseif/else

More information

Quiz Determine the output of the following program:

Quiz Determine the output of the following program: Quiz Determine the output of the following program: 1 Structured Programming Using C++ Lecture 4 : Loops & Iterations Dr. Amal Khalifa Dr. Amal Khalifa - Spring 2012 1 Lecture Contents: Loops While do-while

More information

Loops / Repetition Statements. There are three loop constructs in C. Example 2: Grade of several students. Example 1: Fixing Bad Keyboard Input

Loops / Repetition Statements. There are three loop constructs in C. Example 2: Grade of several students. Example 1: Fixing Bad Keyboard Input Loops / Repetition Statements Repetition s allow us to execute a multiple times Often they are referred to as loops C has three kinds of repetition s: the while loop the for loop the do loop The programmer

More information

Flow Control. Statements We Will Use in Flow Control. Statements We Will Use in Flow Control Relational Operators

Flow Control. Statements We Will Use in Flow Control. Statements We Will Use in Flow Control Relational Operators Flow Control We can control when how and the number of times calculations are made based on values of input data and/or data calculations in the program. Statements We Will Use in Flow Control for loops

More information

COMP519 Web Programming Lecture 27: PHP (Part 3) Handouts

COMP519 Web Programming Lecture 27: PHP (Part 3) Handouts COMP519 Web Programming Lecture 27: PHP (Part 3) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool Control

More information

CHAPTER 2.1 CONTROL STRUCTURES (SELECTION) Dr. Shady Yehia Elmashad

CHAPTER 2.1 CONTROL STRUCTURES (SELECTION) Dr. Shady Yehia Elmashad CHAPTER 2.1 CONTROL STRUCTURES (SELECTION) Dr. Shady Yehia Elmashad Outline 1. The if Selection Structure 2. The if/else Selection Structure 3. The switch Multiple-Selection Structure 1. The if Selection

More information

Lab 5 - Repetition. September 26, 2018

Lab 5 - Repetition. September 26, 2018 Lab 5 - Repetition September 26, 2018 1 ME 30 Lab 5 - Repetition ME 30 ReDev Team Description and Summary: This lab introduces the programming concept of repetition, also called looping, where some operations

More information

Chapter 4: Making Decisions

Chapter 4: Making Decisions Chapter 4: Making Decisions 4.1 Relational Operators Relational Operators Used to compare numbers to determine relative order Operators: > Greater than < Less than >= Greater than or equal to

More information

204111: Computer and Programming

204111: Computer and Programming 204111: Computer and Programming Week 4: Control Structures t Monchai Sopitkamon, Ph.D. Overview Types of control structures Using selection structure Using repetition structure Types of control ol structures

More information

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017 Control Structures Lecture 4 COP 3014 Fall 2017 September 18, 2017 Control Flow Control flow refers to the specification of the order in which the individual statements, instructions or function calls

More information