22 views

save

- Mathematics Introduction for MSc
- Matlab Matrix Operations
- 20090708_Commodities in the if Study UNDP_Cover and Table of Content
- R Matrix Tutor
- Scilab Tutorial
- 1234yuiokp
- 21-29
- 9akk105151d0125 Prioritization Module
- mathematics sd-2016
- 304 Matrix
- process design dynamics_Matrix
- Turkey_A New Method for Noise Elimination From Measured Frequency Response Functions
- Jan 2009
- HWs
- Greenbacks or Greenspace
- Pre - Lab 1
- Chapter 3 Matrices.pdf
- Semi producto tensorial de matrices
- pamelachrissis lesson10 28
- Appendix a-Signals and Systems
- Basic Mathematics Notes
- Bai-tap-buoi-4
- 2nd cheapter.docx
- Assign 1 Sol
- mathematics sd-2016
- Amt-142 (Matrices) Unit 1
- MathematicsSD-2016
- Spru Ill on Finite Difference Method
- AM27
- 4 Matrices 2009
- PJN3-1000_assy8
- BackRiver_BureauWaterWastewater
- DiffEq.pdf
- Lecture_3_AirPollution_v2.pdf
- ENCH442_S18_Lecture3.pdf
- Environmental organic chemistry
- PolymersPlusUserGuideVolume1.pdf
- Lecture_2_AirPollution.pdf
- Lab Guide 2017
- ENCH442_S18_Lecture2.pdf
- GPSS3
- 219800136-Chemistry-and-Technology-of-Rubber.pdf
- DiffEq
- ENCH442_S18_Lecture1
- Kinetics Solution Manual
- Lecture 3 AirPollution v2
- lecture_4_2016.pdf
- Determination of Physical Properties of Organic Liquids
- Chemical_Process_Safety_Fundamentals_with_Applications_by_Daniel_A._Crowl__and_Joseph_E_Louvar.pdf
- Final Lab Report Group 1 Flow Through Fluidized Beds.doc
- Kinetic Data
- ENCH445-Lecture6.pdf
- lecture2_ench445
- 02 Overview of Drinking Water Treatment
- ENCH445-Lecture5-corrected.pdf
- Lecture 2 AirPollution Environmental Engineering
- Lecture_2_AirPollution.pdf

**ENCH 225: Chemical Engineering Problem Solving and Experimental Design
**

Course Packet

Dr. Joshua Enszer

Spring 2015

version 1.82 – last edit 16 January 2015

This course packet was written expressly for use in ENCH 225 at the University of Maryland Baltimore

County. Please do not reproduce any part of this document for use outside of the chemical engineering

program without express permission from the author.

**Several examples in probability and statistics are adapted from examples in Larson and Farber’s
**

Elementary Statistics, 2nd edition. The dimensional analysis comes mostly from Fox and McDonald’s

Introduction to Fluid Mechanics, 7th edition. Revised examples are planned for future versions.

**This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
**

License.

How to Use this Course Packet

A typical chapter in this course packet will include:

**Required Reading/Viewing: These are references to specific chapters or sections in the required text for
**

ENCH 225 or web links to online tutorials or other videos of interest. Items listed as “required” should be

viewed before or while working through the content of the chapter.

**Recommended Reading for Further Consideration: These are references to sections or chapters of books
**

that are required or references for either ENCH 215 or ENCH 225. Some (probably not all) are available

in the library. In many cases, they present very similar information in another way, so if a particular topic

seems confusing, perhaps the extra perspective will help. Further, many recommendations will go more

in depth on topics (including providing many more examples), so if you are especially interested in that

particular topic or tool, this is my way of giving you more information or ideas with which to challenge

yourself. In most cases, the recommendations include several more examples and practice problems.

Learning Objectives associated with that chapter directly reference those from the course syllabus, and

in some cases break those objectives down in more detail.

Sections break down the major topics and tools. Many sections include worked out examples and more

examples with which to practice.

**Explorations finish up several chapters of the course packet and correspond to the computer lab
**

activities for that week.

**Optional chapters and sections include details (but unfortunately currently sometimes unfinished
**

thoughts) that will not be included in exams, but are meant to provide more detail/connections among

the required topics. Most notably, the chapter on probability and combinatorics is linked to statistics,

but you can complete the statistical tests without a very deep understanding of those concepts.

i

Contents

1 Degree of Freedom Analysis ............................................................................................................ 1

1.1 Degree of Freedom Analysis for Extensive Variables ................................................................. 2

1.1.1 Extensive Variable Material Balances ................................................................................ 2

1.1.2 Extensive Variable Atomic Balances .................................................................................. 3

1.1.3 Extensive Variable Energy Balances .................................................................................. 4

1.1.4 Practice Problems............................................................................................................. 4

1.2 Degree of Freedom Analysis with both Extensive and Intensive Variables................................. 7

2 Systems of Linear Equations ............................................................................................................ 8

2.1 Matrix Operations .................................................................................................................... 9

2.1.1 Practice Problems........................................................................................................... 10

2.2 Matrix Determinant and Rank ................................................................................................ 10

2.2.1 Practice Problems........................................................................................................... 11

2.3 Systems of Linear Equations ................................................................................................... 11

2.3.1 Practice Problems........................................................................................................... 13

2.4 The Condition Number ........................................................................................................... 13

2.5 Chemical Reactions ................................................................................................................ 15

2.5.1 Practice Problems........................................................................................................... 17

2.6 Steady-State Material Balances .............................................................................................. 18

2.6.1 Practice Problems........................................................................................................... 20

2.7 MATLAB Exploration: Linear Algebra ...................................................................................... 24

2.7.1 Practice Problems........................................................................................................... 33

3 Descriptive Statistics and Basic Probability Theory ......................................................................... 35

3.1 Descriptive Statistics .............................................................................................................. 52

3.1.1 Frequency Distributions .................................................................................................. 52

3.1.2 Measures of Central Tendency ....................................................................................... 53

3.1.3 Measures of Variation .................................................................................................... 54

3.1.4 Measures of Position ...................................................................................................... 54

3.1.5 Practice Problems........................................................................................................... 55

3.2 Introduction to Probability ..................................................................................................... 55

3.2.1 Practice Problem ............................................................................................................ 57

3.3 (Optional Section) More on Probability Theory and Combinatorics ......................................... 57

3.4 (Optional Section) Computations with Probability Distributions ............................................. 58

3.4.1 Binomial Probability Distributions................................................................................... 59

3.4.2 Uniform and Normal Probability Distributions ................................................................ 60

ii

**3.4.3 Normal Approximation of Binomial Distribution ............................................................. 61
**

3.4.4 The Central Limit Theorem ............................................................................................. 62

3.4.5 Calculations with Probability Distributions ...................................................................... 62

3.4.6 Probability Examples ...................................................................................................... 63

4 Algorithmic Thinking ...................................................................................................................... 35

4.1 The Six Operations of a Computer .......................................................................................... 35

4.1.1 Practice Problems........................................................................................................... 37

4.2 Flowcharts ............................................................................................................................. 38

4.2.1 Practice Problems........................................................................................................... 40

4.3 MATLAB Exploration: Scripts, Functions, and Visualization ..................................................... 41

4.3.1 Practice Problems........................................................................................................... 51

5 Introduction to Inferential Statistics............................................................................................... 66

5.1 Confidence Intervals .............................................................................................................. 66

5.1.1 Confidence Intervals on the Mean .................................................................................. 67

5.1.2 (Optional) Confidence Intervals on Proportions .............................................................. 69

5.1.3 Confidence Intervals on Variances .................................................................................. 70

5.1.4 Practice Problem ............................................................................................................ 71

5.2 Single Sample Hypothesis Testing ........................................................................................... 71

5.2.1 Method 1: Computing a Standardized Critical Value (α is known) ................................... 73

5.2.2 Method 2: Computing an Observed Level of Significance (α unknown) ........................... 74

5.2.3 Statistical Computations for Hypothesis Tests: An Overview ........................................... 74

5.2.4 Hypothesis Testing for a Mean ....................................................................................... 75

5.2.5 (Optional) Hypothesis Testing for a Proportion ............................................................... 76

5.2.6 Hypothesis Testing for a Variance or Standard Deviation ................................................ 77

5.2.7 Hypothesis Testing Summary .......................................................................................... 78

5.2.8 Practice Problems........................................................................................................... 79

5.3 Two-Sample Hypothesis Testing ............................................................................................. 81

5.3.1 Differences Between Means ........................................................................................... 82

5.3.2 (Optional) Differences Between Proportions .................................................................. 84

5.3.3 Differences Between Variances ...................................................................................... 85

5.3.4 Practice Problems........................................................................................................... 86

6 Iterative Programming Applications ............................................................................................... 87

6.1 Root-Finding Methods............................................................................................................ 89

6.1.1 Closed Methods ............................................................................................................. 89

6.1.2 Open Methods ............................................................................................................... 90

iii

**6.2 (Optional Section) Optimization Methods .............................................................................. 92
**

6.3 MATLAB Exploration: Applications of Loops and Conditionals................................................. 93

6.3.1 Practice Problems......................................................................................................... 100

7 Curve Fitting ................................................................................................................................ 102

7.1 Correlation and Causation .................................................................................................... 102

7.1.1 Practice Problem .......................................................................................................... 103

7.2 Hypothesis Testing for the Regression Coefficient ................................................................ 103

7.3 Regression ........................................................................................................................... 104

7.3.1 Linear Regression ......................................................................................................... 105

7.3.2 Confidence Intervals and Hypothesis Testing on Linear Regression Parameters ............ 108

7.3.3 (Optional-ish) Polynomial Regression ........................................................................... 110

7.3.4 (Optional-ish) Multiple Linear Regression ..................................................................... 111

7.3.5 General Linear Least Squares Theory ............................................................................ 112

7.3.6 Practice Problems......................................................................................................... 114

7.4 Interpolation and Splines ..................................................................................................... 119

7.5 Interpolation versus Regression ........................................................................................... 121

7.5.1 Practice Problems......................................................................................................... 122

7.6 Excel and MATLAB Exploration: Statistics and Curve Fitting Tools ......................................... 123

7.6.1 Practice Problem .......................................................................................................... 131

8 Numerical Integration and Differentiation ................................................................................... 132

8.1 Integration Methods ............................................................................................................ 133

8.1.1 Practice Problem .......................................................................................................... 134

8.2 Taylor Series and Numerical Derivatives ............................................................................... 135

8.3 First-Order Ordinary Differential Equations .......................................................................... 137

8.3.1 Euler’s Method ............................................................................................................. 138

8.3.2 Higher-Order Runge-Kutta Methods ............................................................................. 138

8.4 Systems of First-Order Ordinary Differential Equations......................................................... 139

8.5 Boundary Value Problems .................................................................................................... 140

8.5.1 Shooting Methods ........................................................................................................ 141

8.5.2 Finite Difference Methods ............................................................................................ 142

8.6 MATLAB Exploration: Differential Equations and Advanced Visualization ............................. 143

8.6.1 Practice Problems......................................................................................................... 151

9 Dimensional Analysis and Similarity ............................................................................................. 154

9.1 Rendering Equations Dimensionless ..................................................................................... 155

9.2 The Buckingham Method ..................................................................................................... 157

iv

**9.2.1 Practice Problems......................................................................................................... 163
**

9.3 Similarity .............................................................................................................................. 163

9.3.1 Practice Problems......................................................................................................... 164

10 The Scientific Method and Experimental Design .......................................................................... 166

10.1 The Engineering Method and the Scientific Method ............................................................. 166

10.2 One-Factor Experiments ....................................................................................................... 169

10.3 Analysis of Variance (Multi-Sample Test for Means) ............................................................. 169

10.3.1 Practice Problems......................................................................................................... 173

10.4 Two-Factor Experiments and Two-Way Analysis of Variance ................................................ 174

10.4.1 Practice Problem .......................................................................................................... 177

10.5 Factorial Design.................................................................................................................... 177

10.6 Model Selection ................................................................................................................... 179

v

**1 Degree of Freedom Analysis
**

Recommended for Further Consideration:

**Section 2.4 of Murphy’s Introduction to Chemical Processes, Principles, Analysis, and Synthesis, 1st
**

edition. This section most closely matches the discussion in this chapter of our course packet.

**Sections 4.3d and 6.2 of Felder and Rousseau’s Elementary Principles of Chemical Processes, 3rd edition.
**

Note that their version of degree of freedom analysis is significantly different from mine – they only

count items they absolutely don’t know as variables and then find appropriate equations to solve for

those unknowns. This works, but if you’re not a seasoned problem solver, you can sometimes miss an

equation and not know where to go from there.

**Sections 2.7, 10.2, and 13.8 of Smith, Van Ness, and Abbott’s Introduction to Chemical Engineering
**

Thermodynamics, 6th edition. This gets into way more of the calculus of the application, which we’ll not

touch in this course.

**Chapter 2 of Seborg et al.’s Process Dynamics and Control, 3rd edition. This is a very dense summary of
**

chemical engineering mathematical models and applications.

Chapter Goals

**Determine the number of variables and equations in a chemical engineering problem. This is a helpful
**

strategy in many chemical engineering courses, because it can provide insight into the way a problem is

solved – but it is especially important in process control and design where the degrees of freedom is

almost always positive, meaning you must recognize where you get to make design decisions.

Identify the types of equations you must write to solve a chemical engineering problem. This will help

in your efforts to write a system of equations. Later in this course we’ll talk about how to solve them.

**A degree of freedom analysis provides information that is important to designing and/or solving
**

engineering problems. By performing a degree of freedom analysis, you can determine what type of

engineering problem you are working on. Problems with zero degrees of freedom are typically

encountered in introductory engineering courses, because this is the case in which there is one unique

solution to a problem. In practice, engineering problems actually have a positive number of degrees of

freedom, and each degree of freedom means another design decision!

**Degree of freedom analysis differs slightly depending on whether you are focusing on extensive
**

quantities or also considering intensive quantities. An extensive quantity gives information regarding the

scale of a process. Examples of extensive quantities include mass, moles, and volume, or their

corresponding flow rates. Intensive variables are independent of the scale or size of the engineering

system. Commonly encountered examples of intensive variables are temperature, pressure, and

concentration (e.g. mole fraction).

**In a sense, degree of freedom analysis is comparing the number of variables in your system to the
**

number of constraints (each constraint can be written mathematically as an equation). The number of

degrees of freedom in engineering problems is the number of variables minus the number of

1

if a system is not at steady state. Independence is covered more in Chapter 2. because our choice in design variables can change the behavior (and profitability!) of our chemical system.1 Extensive Variable Material Balances In degree of freedom analysis of chemical engineering systems. This becomes important in process analysis and process design. then you have an underspecified system.1 Degree of Freedom Analysis for Extensive Variables 1. 1. once all arbitrary variables are declared. there are two possibilities in this situation. The purpose of this chapter is only to identify the number of degrees of freedom and classify the kinds of equations or relationships that should be used to solve chemical engineering problems.1. recall from calculus that indefinite integrals require an arbitrary integration constant (the infamous “+C” in your calculus homework). Each stream has a corresponding flowrate for each component in the stream. its inclusion does not change the solution to the problem. If the number of degrees of freedom for a system is zero. This flowrate is an extensive variable – mass. there are three sources of extensive variables: Process stream components. specific gravity. introducing a new variable in our system. Provided you have done degree of freedom analysis correctly (double-check to make sure you have only counted independent equations!). If the number of degrees of freedom is negative. moles. Each reaction has an extent of reaction – an extensive variable that describes how much of a reaction has occurred. or relevant equations of state.independent equations. The tricky thing here is there is no telling which equation is redundant. recall that the accumulation of each component within a system is zero. one of our equations is redundant. and there is no solution to this overspecified problem. An underspecified system means that at least one variable can be used as a design parameter (mathematically speaking. More likely. Extents of reaction are virtually always molar flowrates. Accumulations of components. the variable is arbitrary and may be set to any value. You should be able to “translate” between mass. This new variable usually is the “initial condition” of our system. If a system is at steady-state. but for now. one of our equations is contradictory. so each component in each stream provides exactly one variable. the accumulation term in the balance equation is nonzero. we will discuss actually solving such systems of equations. This arbitrary constant is (derived from) our variable! 2 . that is. recall that independent equations cannot be derived by adding or subtracting combinations of other equations. Chemical reactions. then there is usually a unique solution to your problem – you have the same number of equations as unknowns. then you have an overspecified system. molar. If the number of degrees of freedom is positive. and volumetric flow rates using molecular weights. or volume. there is one solution to the problem). This is common in engineering. However. If we are lucky. In future chapters.

This is the direct declaration of the flowrate of one component in one stream. multiple systems can be defined. and generation and consumption refer to material within a system boundary (“stuff” is actually being made or used up inside the system). you can write material balances on each individual unit. separation coefficients. reaction selectivity. This is kind of a “catch-all” category. product yield. rather than accounting for flows of actual chemical components. unlike chemical compounds. but this too counts as one equation. This is certainly a valid approach for solving chemical reaction problems. Input and output are effectively flow terms. but it slightly changes our degree of freedom analysis: There are no variables from reaction rates. Balance equations. 3 . 1. This is because.2 Extensive Variable Atomic Balances Some chemical engineering problems are more easily solved by accounting for atoms entering and leaving a system. because it can be related to a number of concepts: conversion. they’re basically swapping locations. In the case of multiple-unit operations. or the overall system and all but one unit). This is any equation that describes a relationship between one stream component and any other variable in the system. This is the backbone of your introduction to material and energy balance course: One such equation can be written for each component in your system. One balance equation can be written per component per system. etc. We’ll consider the idea of the energy balance later this chapter. because if you know the mole fractions for N-1 components in a single stream. System performance specifications. so long as they are independent (for example. Other specifications. Examples of stream composition specifications are usually mass or mole fractions. Recall that input and output refer to material flows across a system boundary (“stuff” is actually entering or leaving the system). The maximum number of independent stream composition specifications in a stream containing N components is N-1. you automatically know the mole fraction of the last component (it’s the one minus all the other mole fractions). Extent of reaction does not appear as an explicit variable out of atomic balances.1. while generation and consumption are effectively chemical reaction terms.The types of equations we can write on our extensive variables can be classified as one of three kinds: Specified streams (often also referred to as a basis or set of basis equations). atoms are not being generated or consumed. reaction rate. This is any equation that describes the composition (concentrations) of an individual stream. of which there are two main types: Stream composition specifications.

acid and water) of unknown mole fraction using a second acid-water stream that is 1% acid by mass.”1st edition. For example. completely specified. (c) Propose at least one set of design decisions (specifications) that reduce this process to zero degrees of freedom in such a way that there is no solution to the problem. the number of degrees of freedom in this process increases by two. What should be the flow rate of the 1% acid solution in this system? (a) Conduct a degree of freedom analysis on this process to determine how many more details must be specified in order for this process to be completely characterized. The nitrogen flow rate into the reactor is 150 mol/h and the hydrogen is fed at a ratio of 4 moles H2 per mole of N2. Of the nitrogen fed to the reactor. one is concentrated sulfuric acid (77% acid by mass in water). (b) Propose at least one set of design decisions (specifications) that reduce this process to zero degrees of freedom in such a way that there is a solution to the problem.Extra stream composition specifications arise from chemical compounds. The system operates at steady state. (You can be as specific as necessary to demonstrate there is no solution. What new variables are introduced by assuming we are not at steady state? For each scenario below. and it’s even more important in ENCH 442. 1. 30% exits in the outlet stream (the rest reacts). These specifications only apply in the case of atomic balances. This is considered a little bit in ENCH 300.4 Practice Problems 1) A blending process is being developed to dilute a dangerous acid solution (assume the mixture is binary. Principles. as introduced by Gibbs phase rule. However.] 2) A gas mixture of hydrogen and nitrogen is fed to a reactor where they react to form ammonia. Specify the sources of each variable and equation. Designate the problem as underspecified. [DOF = 0] 3) You are designing a mixer that produces 200 kg/day of battery acid. it’s possible to much more greatly complicate degree of freedom analyses by considering thermodynamic degrees of freedom. because degree of freedom analysis is needed to figure out our options for controlling a system.1. Analysis. perform an extensive degree of freedom analysis (do not solve). or overspecified. Raw materials are three streams – one is pure water. and 4 .1. [Some of these are adapted from Murphy’s “Introduction to Chemical Processes. 1. and Synthesis. a stream of water becomes a stream of hydrogen and oxygen where the mole fraction of hydrogen is 2/3 and the mole fraction of oxygen is 1/3.3 Extensive Variable Energy Balances The introduction of energy considerations to engineering systems does not particularly change our degree of freedom analysis – generally including energy on top of a material balance DOF analysis means just adding one variable (the amount of energy being added or removed from the system) and one equation (the general energy balance).) (d) If the system is not assumed to be at steady state.

why do you think that happened? Which specifications are actual specifications and which are constraints?] 6) A bioreactor system consists of three units: first. but due to environmental constraints. (The reaction goes to completion and there is no (CH3)3Ga or NH3 exiting. but thanks to the nutrient. The reactants are in their stoichiometric ratio and carried in with an inert gas. [DOF = 0… if you got a negative number. where gallium nitride will deposit as the result of a reaction between trimethyl gallium and ammonia. one is dilute sulfuric acid (4. The nutrient solution is then fed directly into the bioreactor.5% acid by mass in water). [DOF = 2… this one is tricky! Try writing out the equations to see why.] 5) Salad greens are washed to remove debris before being packaged for sale. a stream of water is combined with a stream of solid particles of nutrient in a mixing tank. The greens are mixed with 150 gallons of water per day and washed. The amount of nutrient supplied to the plant is 100 grams per day. The product of the mixer is 18. methane. 5 . where nothing is accumulated in any unit. She puts a 1 cm2 chip of aluminum oxide in a reactor. This inert gas sweeps out the reaction byproduct.) The researcher wants to estimate the grown of GaN on the chip. The freshly-picked greens contain 1 lbm debris per 12 lbm of greens. but the flow rate of water is not automatically prescribed. The dirty water is dumped into a nearby river.6% acid in water.5% by volume. the system will reach steady-state. basically according to the “reaction” Algae + Nutrient → 2 Algae + Waste Exiting the bioreactor. then. is a stream of algae and water (with dissolved nutrients and waste). is limited to a maximum of 4 barrels per day. After some time. with a maximum debris content of 1. This process removes 99. One facility processed 1500 1-pound packages of greens per day. This stream is fed into a separator. preloaded with 100 micrograms of algae. [DOF = 1] 4) A researcher is making LEDs. where 100% of the algae and some of the water are separated from the rest of the material. it grows.9% of the debris an all the wash-water from the greens. then spun-dry to separate the dirty water from the greens.

The system is at steady state. (c) Provide an example of extra information that would reduce this scenario to having zero degrees of freedom such that it is actually impossible to solve the problem (hint: make it so the solution is physically impossible – negative flow rates.7) Today is your first day working as an engineer for the Fictitious Chemical Conglomerate and you are ready to make your mark on the world! Today also happens to be the day the FCC is experiencing problems in its Food Science division – the premade smoothie processing units are not meeting the target set forth by management.5% honey Use degree of freedom analysis to help explain to your supervisor why the target set forth by management cannot be met. such that all material flow rates are known? (b) Provide an example of extra information that would reduce this scenario to having zero degrees of freedom such that you can solve the problem. Your supervisor has given you the following specifications to the primary mixer. where it undergoes both complete and incomplete combustion. where 1 gmol/s of water exits. The stack gas is fed to a condenser. etc. (a) How many more pieces of information are required for this scenario to be completely characterized. Feed streams into mixer (three streams): Premade fruit and yogurt mixture (35% fruit). mole fractions greater than 1.) 6 . fed at a rate of 100 kg/hr Raw oats Honey Output mixture specifications (single stream): 30% fruit 10% oats 2. 8) Methane is fed to a burner at a rate of 10 gmol/s.

because this analysis will help you to determine how to most effectively design a process such that you are able to maintain it at the desired temperature. flow rate. Gibbs phase rule says we actually need 2-π more equations than that to completely characterize it on both a mass/molar basis and an energy basis. we said that a stream required c equations to completely characterize it on a mass or molar basis. We have already been partially applying Gibbs phase rule to a stream – in the extensive variable DOF analysis.1.2 Degree of Freedom Analysis with both Extensive and Intensive Variables Recall from the Gibbs phase rule that a stream can be completely specified according to where the number of thermodynamics degrees of freedom d. or an observation that a stream is in equilibrium with another (such as a saturated vapor in equilibrium with a saturated liquid). is a function of the number of chemical components c and phases π.f. simultaneously. pressure. Intensive DOF analysis will prove most useful when you take a course in process control. and more. These equations are always specifications such as a declaration of the temperature or pressure of the stream. 7 .

and Synthesis. but note that you can’t get by just clicking through menus in ENCH 225.1. Principles.mathworks.1. Introduction to Linear Algebra.2. work through 2. 2. Chapters 1-2.4 of Murphy’s Introduction to Chemical Processes. They can be used to evaluate chemical reactions by numerically determining stoichiometric coefficients. You can check out Chapter 2 if you want.1. Analysis. and multiply matrices will help in your understanding of MATLAB programming. First skim these sections to see how much you are comfortable with.1. Sections 3. Chapter Goals Perform basic matrix arithmetic. The first two sections of the MATLAB Linear Algebra video at http://www. and 5.html.6 this week. Linear equations also appear in chemical engineering analysis in the case of single-phase steady-state material balances (and some special cases of multi-phase steady-state material balances and/or energy balances). If you’re comfortable.1 in Pratap’s Getting Started with MATLAB. Linear equations arise in chemical engineering primarily in two distinct applications. subtract. now focusing on the creation and solution of linear systems of equations. 3.2 Systems of Linear Equations Required Reading/Viewing: Chapter 3 of the free version of the MATLAB Interactive Tutorial published by Mathworks at http://www. These sections provide more examples of linear algebra as it is applied to chemical engineering problems. Recommended for Further Consideration: Any linear algebra textbook will provide much more detail on this topic.1. and 2.mathworks. Finding the rank of a linear system should confirm the results of degree of freedom analysis. Determine the properties of the matrix equation Ax=b including rank and condition number.com/academia/student_center/tutorials/mltutorial_launchpad. 8 . and 5.1.2.html. In this chapter we will follow up on our use of degree of freedom analysis. Pose a chemical engineering problem as a system of linear equations.2. Chapter 1 and Sections 12. If you’re new to MATLAB or uncomfortable with it. 3.1 in Attaway’s MATLAB: A Practical Introduction to Programming and Problem Solving. Your ability to add. 3.com/academia/student_center/tutorials/computational-math-tutorial- launchpad. Solving Linear Systems (about 18 minutes). The condition number will give us confidence in our computed numerical solutions to a matrix equation. focus on 1. 1st edition.7. 3.3-3.1-12.2.

Using Xi to denote the ith element of vector X. and the right-hand vector R should be n rows by 1 column. the left-hand vector L should be 1 row by n columns. Matrix arithmetic works a little differently than scalar arithmetic. If two matrices A and B are multiplied together to make matrix C. we’ll see that all Let’s go to the Video! balanced chemical reactions have one degree of freedom. the number of columns of the left-hand matrix must equal the number of rows in the right- hand matrix. The solution to this system of equations depends on the number of degrees of freedom in our problem. let’s establish a few crucial details. which can be rewritten as a single matrix equation of the form where A is a matrix of coefficients on the variables contained in the column vector x. a column vector has just one column). which is addressed by simply picking a value for one stoichiometric coefficient Click here to see another in the reaction. Later in this chapter. then the solution to this system is represented by which is usually easily computed using programs like MATLAB. which equations. A matrix with one row and one column is a scalar value. The product of these two matrices will have the same number of rows as the left matrix and the same number of columns as the right. arithmetic using MATLAB. Click here to see a little more information regarding matrix In this course we will be concerned with a system of linear equations. A matrix is an array of values. the Let’s go to the Video! element in the ith row and jth column of C is the dot product of the ith row of A and the jth column of B. which can be represented as a matrix with one dimension of length one (a row vector has just one row. then additional equations must be designed to reduce the degrees of freedom to zero. Sometimes you will hear about vectors. often happens in the laboratory. The dot product of two vectors is the sum of the products of the elements of the two vectors. Keeping with matrix multiplication rules. Multiplication is a little more complicated. Matrices can be classified by their dimensions – the number of rows and number of columns in a matrix. In order to multiply matrices.2. when we look at reaction stoichiometry.1 Matrix Operations First. application of linear algebra. In order to add and subtract matrices. the dot product is Matrix multiplication is basically a bunch of dot product calculations. they must have the same dimensions. with demonstrations of matrix If our system has a negative number of degrees of freedom. If our system has a positive number of degrees of freedom (the system is underspecified or underdetermined). If our system of equations has zero degrees of freedom. where multiple trials are conducted 9 .

then the determinant will be nonzero. There is a more general formulation for an n-by-n matrix. most computer programs try to find a compromise between number of computations (which corresponds to how long it takes to get the result!) and the accuracy of the result. explain why. we will address some zero and positive DOF problems. but this isn’t a linear algebra course. then the determinant will be zero. 10 . 1) Evaluate the result. Our aim here is to look at just a few of them so that we know just enough to be dangerous – we simply want to know how we can tell that we have a complete system of linearly independent equations to solve. Because there are a lot of computations necessary to find the determinant of a large matrix. explain why. and if the system is not independent. In this chapter. If the linear system is independent. If the multiplication is not valid.1.to find a single piece of information. The determinant of a 2x2 or 3x3 matrix is simple enough that we can write it in equation form. we can just use the det command in MATLAB. but it does mean that we need to take our results with a grain of salt – if the computer tells us that determinant of a large matrix is close to zero. it might actually be zero. 2. then we must use more advanced linear algebra to “solve” this system. we’ll reserve the topic of overspecified or overdetermined systems for Section 7.2 Matrix Determinant and Rank There is a lot of terminology specific to linear algebra to describe matrices and associated matrix algebra problems. 2) Transpose the right-hand matrix and evaluate the result.1 Practice Problems For each of the matrix multiplication problems below. Then we need to resort to other means (see the next section). In most cases. this is fine. If the multiplication is not valid. 2. so for large systems.3. The determinant of a matrix can be used to tell if a corresponding system of linear equations is independent or not (recall from ENCH 215 that a system of linear equations is independent if there is no way to write one equation as the sum of multiples of the others).

2. what can be said about the rank of this matrix? 2.3 Systems of Linear Equations The reason we care so much about matrices is that any system of linear equations can be expressed as a single matrix equation. then we say the system is of full rank (and corresponds to a system with zero degrees of freedom). but has m rows and n columns.x3} be the set of unknown values that satisfies the following system of equations: This is equivalent to the following single matrix equation: I realize these letters with subscripts may not be the most exciting thing to see – but I do want to point out that each value aij is specifically subscripted such that “i” is the row (or equation!) and “j” is the column (or corresponding x-value!).But. it can be much faster to solve a single matrix equation than to solve a system of simultaneous linear equations. 11 . 2. Armed with the right computational tools (certain calculators or computer programs). That’s where the rank comes in – it is the count of the number of linearly independent equations! When a square matrix has a rank equal to the number of rows and columns. what is the largest possible rank this matrix could have? Explain.x2. 2) If a matrix is not square. Let x={x1. Check your work using MATLAB. 3) If the determinant of a matrix is zero. we then want to know how many linearly independent equations we actually have. if we know the determinant of a matrix is zero. using the rank command. We will rely on MATLAB to compute matrix rank for us also.1 Practice Problems 1) Compute the following determinants by hand.

we’ll explore another matrix property that can seriously affect the results of computations. The solution to Ax=b is where A. so for the matrix above. We will not worry about how to compute the inverse of a matrix in this course (this topic is part of any traditional linear algebra course). we would define the following vectors and matrices like the following: So the resulting matrix equation can simply be written The solution to this equation is found using matrix arithmetic. which is a matrix of all zeroes except ones down the diagonal. or if the inverse of a matrix is given. you should be able to put it to good use – such as solving the equation we have posed here. and b are the matrices/vectors as defined previously. In the next section. There is no such thing as matrix “division. However. I. 12 . x. A -1.” only multiplication. The inverse also has the special property that it is one of the few matrices that can be multiplied on either the left or the right and the result is the same. you will need to know how to use MATLAB to find this inverse. such that their product is the identity matrix. but most square matrices A have an inverse.Typically we write matrix equations in shorthand.

we will count on computer programs to let us know how reliable our results are. If a matrix has a small condition number. computers can wind up giving completely incorrect answers (usually MATLAB will recognize this is happening and warn you that the answer may be wrong). and not all matrix equations have solutions that are easy to compute numerically. determine the solution to the matrix equation below by hand. in both directions (left-multiply and right-multiply). then an error in the values of the matrix might change a result entirely.4 The Condition Number Not all matrix equations have a solution.1 Practice Problems 1) Write the system of linear equations that is equivalent to this matrix equation: 2) Write the matrix equation that is equivalent to this system of linear equations: 3) Demonstrate that the matrix is the inverse of the matrix by multiplying them both together. In the case of very large condition numbers. when substituted back into the problem.2. They are not important to compute in ENCH 225. Check your response using MATLAB. not give us the original result? The condition number depends on the relative scales of the eigenvalues of a matrix (Eigenvalues are the characteristic values that define a matrix. 4) Using the information from the previous problem. 2. This may seem especially surprising depending on your mathematical history – how can the answer to a problem. 13 .3. If a matrix has a large condition number. If you take a course in linear algebra. The condition number of a matrix provides an estimate on how inaccurate the solution x=A -1b is when substituted back into the problem Ax=b. this means that any measurement error in the values of the matrix will have a small effect on the solution to the problem. but for the case of this course. If these eigenvalues differ greatly in magnitude. but we’ll need them in ENCH 442). then it can be mathematically impossible to solve a matrix equation to any accuracy you want (it is similar to trying to solve a problem down to the nearest billionth when you are only given rough integer estimates of the values to begin with). you will learn in more detail why.

1%. We will rely on computer software to compute matrix condition numbers for us. x2=-1. how much do you trust your solution for x? The condition number tells us that we shouldn’t trust it much: The solution to the system which is the same problem as before except one value has been adjusted by 0..01%.. It is not entirely complicated. it should get this result with little effort. We adjusted one value in the entire problem. and the solutions changed by over 50% from their original values! Even scarier is adjusting a value inside the matrix itself.04.8. However. x3=-0. If you use a calculator or MATLAB to solve the system. This will come back into play when we talk about curve fitting in Chapter 0.002. Moral of the story? Watch your condition number. it may have a very sensitive solution. we would obtain which is at least 24% away from the original values of that right-hand vector.000. 14 . x3=0.39. x2=-12. has solution x 1=0.8.Example. Even if you have a nice zero degree of freedom problem (matrix of full rank). The matrix A in the matrix equation Ax=b below has a condition number of about 100. even by 0. and x3=0. And even rounding the solution here the way these numbers are presented results in a lot of error. but we need to invest our energy elsewhere. The solution to this problem is roughly x1=11. if those vector values were the result of some experiment and had a little error in them. The solution to this system is x1=1.443. x2=-0. If we were to take our rounded x-values and recompute the right-hand vector.

reaction stoichiometry is straightforward. Some basic examples of balanced chemical reactions include The numbers in front of each chemical compound are their stoichiometric coefficients (denoted by the Greek letter nu. For example. the number of atoms on one side of the reaction must be the same as the number of atoms on the other side. and the rest are then determined. we obtain 15 . with organic chemical reactions.5 Chemical Reactions Linear algebra can prove to be a useful tool in chemistry and chemical engineering for dealing with chemical reactions. and you have learned strategies to balance them. one on H and one on O: H: O: The coefficients in front of the stoichiometric coefficients correspond to the number of atoms in that particular element (hydrogen gas and water both have 2 hydrogen atoms. This will be important in setting up our linear algebra problems. if we wanted. Here. the following two reactions are equivalent: We could even write stoichiometric coefficients of . we will adopt a convention of a negative stoichiometric coefficient when a compound is being consumed (is a reactant) and a positive coefficient when a compound is being produced (is a product). you have used rules of thumb to help balance components in a particular order. For example. which is written as ν). A balanced chemical reaction is one in which the number of atoms of reactants is the same as the number of atoms of products. and . You have certainly spent your share of time balancing chemical reactions in your chemistry courses. in balancing a chemical reaction. . In many cases. Note that these coefficients are relative quantities – in each case. we can write for the reaction where hydrogen and oxygen gases react to produce water two atomic balances. it can be time-consuming to get it right. This is a small system of linear equations that we can solve. Again. respectively. oxygen gas has 2 oxygen atoms but water only has 1). one coefficient may be chosen arbitrarily. Rewriting as a matrix.2. Adopting our new convention of negative stoichiometric coefficients for reactants. but in cases of numerous or complicated chemical compounds and elements.

so we get to design one more equation. If we choose (remember. we obtain which has solution and . What do the columns correspond to? Each column corresponds to a different chemical compound – by matrix multiplication. in order. the first column gets multiplied against the oxygen gas coefficient. Look at the last matrix equation again. it can be helpful to write the atomic matrix like this and solve using matrix algebra. then O). C. in terms of matrices. so it needs to be negative!) and rearrange our equations slightly. C: H: O: We have three equations and four unknowns. a system with one degree of freedom. the second column against the water coefficient. We can pretty easily solve this one by substitution. Do you notice anything interesting about the coefficients in the matrix? We know that the three rows correspond to the three atom balances (in this example. That means we are free to specify one stoichiometric coefficient and the rest are determined. Let’s say so our system of linear equations becomes C: H: O: Or. H.This system of equations has only two equations but three unknowns. We already know the reaction is But let’s once again pretend we don’t know how those coefficients and instead write a system of atomic balances. or we can take the inverse of the left matrix and multiply it by the column vector on the right. We can choose whatever value we want for and the other coefficients are appropriately determined. and the last column against the carbon dioxide 16 . it’s a reactant. This is an underdetermined (or underspecified) system. Let’s try a slightly more complicated example – the combustion of methane. For more complicated problems.

CH 4! This leads us to a general strategy for writing systems of linear equations to balance chemical reactions. respectively. and S. use one mole of oxygen gas.1 Practice Problems 1) Show that the matrix equation for the carbon disulfide combustion reaction can be derived from the atomic balances on carbon. We’ll use CS2 as our basis compound. This reactant will have a stoichiometric coefficient of -1 in our solution. x. 4. The column vector of stoichiometric coefficients is our unknown. Look at the column vector on the right. 2) Repeat the analysis for the combustion of methane from this section. The rest of the compounds will appear as columns in the left-hand matrix: We can solve this system by inverting the left-hand matrix and left-multiplying it against the right-hand vector to obtain the rest of our stoichiometric coefficients. 2. so 2. Carefully fill in the left-hand matrix by noting the number of atoms in each compound. O. 5. first column is 0 because there are no carbon atoms in oxygen gas. The row should correspond to the element and the column should correspond to the compound. 1. The elements of this square matrix correspond to the number of atoms in that compound.coefficient. Choose one reactant to serve as a basis. oxygen. so it will appear in the column vector in our matrix system. and carbon dioxide. How does your result differ? 17 . and 0 in the oxygen row. water. Write the number of atoms in this compound as a column vector for the right-hand side of the equation. This means the first row. List the compounds in the order they appear in the reaction. First we note the elements involved are C. we get -3. Notice that there is a 1 in the carbon row. Solve for x using matrix algebra. In this case. and sulfur. This corresponds to the atoms in methane. List the atomic elements involved in the reaction. except instead of using one mole of methane as the basis. second column is 2 because there are 2 hydrogen atoms in water! The third row counts the atoms of oxygen in oxygen gas. The second row. 4 in the hydrogen row. 1.5. Let’s try one more example to put this idea to work – the complete combustion of carbon disulfide in oxygen to form carbon dioxide and sulfur dioxide. 3. and 2. There will be one row in your matrix and column vector for each element.

and/or extents of reaction. The most straightforward way to write systems of linear systems is to treat mass or molar flowrates as the unknown variables in a problem. whenever there is a reaction. the equation is algebraic. equations may come from a basis or specified stream (the easiest kind of equation to write. 4) Use the analysis of this section to balance this chemical reaction: 2. our material balance equation becomes where νij is the stoichiometric coefficient for chemical compound i in reaction j and ξj is the extent of reaction j. but they are a lot of simple linear equations that can easily be solved in some sequential or simultaneous manner. When there is no reaction. unknowns. 3) Use the analysis of this section to determine the balanced chemical reaction representing the complete combustion of phenol (C6H5OH). Accumulation is the term that potentially results in a balance equation being a differential equation (we’ll deal with those in Chapter 8). The nice thing about treating each individual molar flowrate and each individual reaction’s extent as variables is that. or a system specification (which relates a mass/molar rate in one stream to mass/molar rates in another stream. a stream specification (which may wind up being a small system of equations that relates many mass/molar rates in a single stream). at steady state. since it’s in the form n=constant). can be written and solved as a system of linear equations. The sum of these items results in a linear equation. or the product of a constant and unknown. when applicable). simply write one linear equation for each source of equations determined in degree of freedom analysis. In addition to material balances. As general rule. either mass or moles are fine to work with. and all of these terms are variables or products of variables and constants – a linear system! 18 .6 Steady-State Material Balances Many chemical engineering problems. This is because of the nature of the overall balance equation: The terms of the overall balance equation are often straightforward – either constants. but when there is no accumulation. it’s almost always easier to work with molar flowrates (and extents of reaction will have the same units as these flowrates). Then. especially in the beginning of your academic career. All of these terms have units of moles. This often results in a lot of linear equations.

The diluted stream has a flowrate of no more than 2.9mP.o=0 (other balance) 0.p+mD. Here is one approach: Treat the important flows as “pollutant” and “other. The clean stream is just other.999mD.001mD.Example. you can apply similar techniques to many combinations of the four basic mass processes: mixing.1mP. one for other).p-mD. Pair that with two material balances (one for pollutant.000 lbm/hr. In this problem.p=0.1% pollutant Clean stream ? lbm/hr 0% pollutant Solution. how much of the polluted process stream and the clean process stream are consumed at maximum capacity? Polluted stream Diluted stream ? lbm/hr 2000 lbm/hr 10% pollutant 0.o (stream specification on polluted stream) 0.o-mD. separating. and reacting.” The polluted and diluted streams have both pollutant and other.o=2000 (specified stream) We can transform this into a matrix equation: Inverting the left matrix and left-multiplying it against the right column vector. we are given information for overall flowrates and concentrations. we obtain All units are mass per hour. The system is 19 . splitting. and we have five equations and five unknowns: mP.o (stream specification on diluted stream) mD. There’s certainly more than one way to write a linear system for this problem. A process stream with 10% pollutant by mass is diluted with another “clean” process stream (with 0% pollutant by mass) before it is discharged. As you studied in your material and energy balances class. That’s five mass flows.p=0 (pollutant balance) mP.1%. If the maximum allowable concentration of pollutant in this stream is 0.p=0. We’re given one specified stream (2000 lbm/hr diluted) and two stream specifications (% pollutants in polluted and diluted streams).o+mC.

so when he can’t get his liquid-liquid extraction unit working properly. Usually these “core” equations are the material balances themselves. So the impure stream flows in at a mass flow rate of F1 lb/hr and has a mass fraction of impurity of y1 lb impurity/lb stream 1 exiting the first stage. or stream specifications) can be substituted into the material balances.1 Practice Problems 1) You have finished your first week at the Fictitious Chemical Company and are about to leave for a well-deserved weekend when you get a call from Bob. 2. you could set up an appropriate matrix. a mass fraction of impurity of y2 lb impurity/lb stream 1 exiting the second stage. In those cases. You are much smarter than Bob. 20 .only nonlinear in cases with complicated thermodynamics (such as vapor-liquid equilibrium) or complicated reaction kinetics (reversible or high-order reactions). x2 leaving the second stage. all other specifications (basis. These sorts of problems can get pretty complicated quickly. etc. A system with a reactor and recycle can easily have over 20 equations in 20 unknowns. or you can make substitutions where it makes sense to end up with a “core” system of just a few equations and a few unknowns. and so on. but the concentration of the impurity is different at each stage. The flow rates in each direction up and down the column are constant. he calls you up to ask for help analyzing it.6. and he knows it. system. another new hire to the company. The multi-stage liquid-liquid extraction process Bob is running removes an impurity from one liquid stream by dissolving it in another liquid stream that passes it counter-currently. even though F2 is flowing the opposite direction of F1. Likewise. the stream removing the impurity from the original stream has a flow rate of F2 lb/hr and a mass fraction of impurity of x1 leaving the first stage. Consider the currently-running three-stage column below: F2 y3 x4 Stage 3 y2 x3 Stage 2 y1 x2 F1 Stage 1 y0 x1 The convention is for the subscript on the mass fraction to be the number of the stage that stream is exiting.

A solution is 10% acid by mass (the balance is water). then write a system of linear equations describing the mass flow rates of acid in the system. Perform a degree of freedom analysis on the four-stage system. 21 . Then use MATLAB to solve this system. we would have where the product of this reaction is a single molecule. We seek to determine the feed rate of magnesium sulfate and water (in lbmol/h) needed to produce one ton per hour (2000 lb m/h) of magnesium heptahydrate. there is an equilibrium ratio between the mass fractions xi and yi that is a constant value across all stages: a) Write a mass balance on impurity passing through an arbitrary stage j in terms of the flow rates F1 and F2 and appropriate mass fractions (such as xj. (b) You should find that there are six equations in six unknowns in this problem. the crystals are hydrated salts – a compound where H2O molecules are bonded to solute molecules. determining the mass fraction y4 of acid in water in its exit stage. It is put into a four-stage column at a rate of 400 lb/hr in contact with a stream of pure n-hexane entering at a flow rate of 1000 lb/hr. We can think of this as a sort of reaction. you can write the governing mathematical model in as few as four linear equations if you wish. The equilibrium constant K for this separation is 2 lb water/lb hexane. and the mass fraction x1 of acid in hexane in its exit stage.25 lb MgSO4(aq) per lb of solution. for example. (Hint: by writing the mass balance on the impurity at each stage. in the case of magnesium sulfate at room temperature. for example). At 70°F. A feed of aqueous magnesium sulfate at 220°F containing 35 wt% MgSO4 is fed to a cooling crystallizer that operates at 70°F. and substituting in the equilibrium coefficient. With the system at steady-state. One way to write the six unknowns are labeled as n1 through n5 and ξ in the process flowchart below: n1 lbmol/h MgSO4 (aq) ξ lbmol/h n3 lbmol/h MgSO4 (aq) n2 lbmol/h H2O of reaction n4 lbmol/h H2O n5 lbmol/h MgSO4·7H2O (s) Write the system of equations that relates these six variables in a single matrix equation. b) Bob needs to add another stage to this column. the solubility of MgSO4 in water is 0. (a) Conduct a degree of freedom analysis (assume steady state) to show there are zero degrees of freedom in this process.) 2) When certain solutes crystallize from aqueous solutions.

set up the system of material balances (that is. n. c) Once you have a system with zero degrees of freedom. explicitly write out all the equations). Do not solve. All percentages in the diagram below are in mole percents. and isobutane.01% propane B1 5% fuel gas 95% propane Feed 21% fuel gas 9% propane D2 38% n-butane 1% propane 32% i-butane 99% n-butane B2 3% propane 5% n-butane 92% i-butane 22 . or exactly specified. propose what piece(s) of information to ignore so that there are zero degrees of freedom. The four product streams are fuel gas (primarily hydrogen. D1 99. take a basis of 100 lbmol/hr of feed.9% fuel gas 0. methane.3) The FCC’s petrochemical division is under review for the way that it separates a portion of the crude oil that is processes each day. underspecified.butane. For your analysis. If the system is underspecified. a) Perform a degree of freedom analysis on the following setup to determine whether the system is overspecified. b) If the system is overspecified. propane. You have been tasked to investigate how the very lightest components of the hydrocarbons are separated. make additional assumption(s) on the system so that there are zero degrees of freedom. and ethane).

) 23 . 30% gravel. The engineer needs to determine how many pounds of materials should be obtained from each pit. 20% gravel. and 5700 lb coarse rock. and 18% rock by mass. and m3 be the masses of materials from the three pits. and 30% rock by mass. 50% gravel. In using MATLAB to get numerical results. and 55% rock by mass. it is fine to simply define a matrix A and vector b in the Command Window and use the appropriate operation to solve the system (but this is the last time for that – you will be asked to use MATLAB’s publish command after today). There are three pits to obtain materials – pit #1 is 52% sand. You can copy and paste what you type and see in the Command Window into a word processing document for submission. (a) Perform a degree of freedom analysis on this problem to show that there are the same number of equations as unknowns.and outflows of water Qi and mass loads (inputs) of chloride Li as labeled. (b) Letting m1. pit #3 is 25% sand. pit #2 is 20% sand. (You don’t need to solve for them. 5800 lb gravel. 4) The environmental division of FCC wants to you analyze the watershed consisting of a series of five reservoirs as shown in the figure below – each reservoir has volumetric in. then solve this system for the steady-state masses of chloride ions in each reservoir using MATLAB. m2. LA=180 mg/min LC=740 mg/min QA=67 m3/min LE=740 mg/min Reservoir A Reservoir C QC=161 m3/min QE=212 m3/min Reservoir E LB=710 mg/min LD=3850 mg/min QB=36 m3/min QD=182 m3/min Reservoir B Reservoir D 5) A civil engineer involved in a construction project requires a mixture of 4800 lb sand. write a matrix equation in the form Am=b that could then be solved to find these values. They are interested in solving for the steady-state distribution of chloride ions in each reservoir. Write out the system of equations that describes the chloride ion mass balance in each reservoir.

Solve matrix algebra equations using MATLAB.mathworks.2. (Be careful on UMBC machines to not just search for MATLAB and hit enter – “Activate MATLAB” comes before “MATLAB” alphabetically.1 in Attaway’s MATLAB: A Practical Introduction to Programming and Problem Solving or Chapter 1 through 3. you should end up in a program that looks like Figure 1 below: Figure 1: Default Configuration of the MATLAB Desktop 24 . It is also helpful to have looked through Chapters 1 and 12. so you’ll run the wrong program. Use the MATLAB Command Window as a calculator for both scalar and matrix operations.mathworks. Chapter 3 of the free version of the MATLAB Interactive Tutorial published by Mathworks at http://www. Open MATLAB on your computer. In Windows.7 MATLAB Exploration: Linear Algebra Reminder: It’s in your best interest to watch the following videos before coming to lab. You can check out Chapter 2 if you want.1-12. Write simple MATLAB scripts.com/academia/student_center/tutorials/computational-math-tutorial- launchpad. vector. but note that you can’t get by just clicking through menus in ENCH 225. MATLAB should be on the list of all programs if you use the start menu.com/academia/student_center/tutorials/mltutorial_launchpad. Generate random numbers. Define scalar. Introduction to Linear Algebra.html. The first two sections of the MATLAB Linear Algebra video at http://www.2 in Pratap’s Getting Started in MATLAB.) When MATLAB starts.html.2. Solving Linear Systems (about 18 minutes). you should be able to… Navigate the MATLAB Desktop. By the end of this exploration. and matrix variables.

” then you can no longer use the plot command! Variable names must start with a letter. Each MATLAB window has the same downward-pointing-triangle-in-a-circle in the upper right corner – these let you customize the layout of windows in MATLAB to be more useful for you personally. we will devote our attention to the largest window in the center of the MATLAB Desktop.1 When you see sections of the document like this. which in MATLAB is the variable assignment operator. from a blank prompt in the Command Window. and spaces) will result in an error or behavior that you probably don’t want. @. we must use the = sign. but can otherwise contain alphanumeric characters and underscores. You can store separate values as x and X in MATLAB. and make note of what you see 4^2 and/or what you know/learn in the 6/3 white space here! 6/3. so be careful! If you save a variable as “plot. Command History. slashes. (It literally means “is assigned the value. press the up and down arrow keys to cycle through previous entries. and Workspace as you go: 2 + 3 4 . so be careful! Variable names can overwrite MATLAB functions. For now. it pops it out to be manipulated using Microsoft Windows instead. let’s just work in the MATLAB Command Window. or. &. which lets you relocate the window into MATLAB. When you undock a MATLAB window. #. This is where MATLAB can be used as a calculator. %. Virtually every other character (!. You can drag and drop lines from the Command History back into the Command Window. but more than that.For most of today. $. If you close a MATLAB window and want it back. If we want to retain a result for use later in the Command Window. you can find it under “Layout” on the “Home” tab. Confirm that you can enter commands into this window much like you would expect on a scientific calculator. don’t use spaces anywhere in MATLAB unless you really mean it.”) There are specific rules about how variables and the variable assignment operator work: Variables are case sensitive. What is the difference between the results of the last two entries? MATLAB will perform any computation you enter into the Command Window. brackets. parentheses. ^. commas. or as a “sandbox” for testing out short commands. 25 .” and NOT “is equal to. the Command Window. In the last example. Seriously. arithmetic operators. it will automatically store the result in its memory as the variable “ans” as you can see in the Workspace. MATLAB also keeps a running log of the commands that you have entered at the prompt in the Command History. you should enter 3 * 7 what you see at left into MATLAB. The undock option is replaced with a dock option. we put a semicolon after our computation. Try entering each of the following at the >> prompt and keep an eye on the Command Window.

5]. One way is to define a vector of values. do not assign the same name to a variable! Try these out. The variable assignment operator must always be used in the form variable_you_want_to_define = what_you_want_to_assign_to_that_variable The left side is always the name of the variable you are writing to. It would be equivalent to write one of the following: x=[1 2 3 4 5]. % this should cause an error! z = y-2. but each one is easier to use in certain situations. it can’t be a mathematical expression. it doesn’t make sense. and keep an eye on the Workspace: x = 2. z +2 = y . but the = sign doesn’t mean “is equal to” in MATLAB! The colon is a special operator in MATLAB that is used in a few different ways.” and to say “molefracA” instead of “x. They all work. there are four ways to define vectors. You should be familiar with all of them. Use commas or spaces to separate elements of a row vector and semicolons to separate elements of a column vector. And some best practices: Give variables short but meaningful names. Try it: how would you define a row vector [4 93 7 -2] in MATLAB? 26 . This method must be used if there is no mathematical pattern in the creation of the vector. The right side can be any valid MATLAB command – you can assign variables to have the same value as other variables or to have the result of some command or computation. Write out each element of the vector and enclose them in square brackets.” Avoid giving variables the same name with just different use of capitalization.4.2. Notice that you can use previously defined variables to define new variables – and even to overwrite currently used variables! In the case of z=z+1. y = 4. x=[1. Notice when you defined x in that last line.” which is a valid command. z = z+1. If you have written your own MATLAB program or know there is an existing MATLAB program with a certain name. As a mathematical formula. This bears repeating. Don’t overwrite existing MATLAB functions.3. It’s clearer to say “height” than “h” or “vertical_displacement. you are literally instructing MATLAB to “assign to z the current value of z plus one. In general. x = 1:5. MATLAB automatically created a 1-by-5 row vector.

If you already have a vector. for example. and the last value.Use the colon operator to create vectors whose elements are linearly increasing or decreasing. MATLAB assumes you want to make a vector where each element is one greater than the last. but just want a certain element of it. There are some rules here. you can use mathematical operators or functions to act on that vector. By default. for example x(3) gives the third element in x. If you already have created a row vector. 27 .last_value. Vectors can only be added and subtracted if they are the same size (have the same number of elements).number_of_elements) Try it: how would you define a row vector [1 3 5 7 9] using linspace? Try it: how would you define a row vector starting at 0. so we’ll look at that in more detail now. a colon. MATLAB will automatically determine how to increment the vector. you can use parentheses to call that element out. 1:2:9 would count by twos from 1 to 9. In this case. so [1 3 5 7 9]. Vectors can only be multiplied if one is a row vector (one row and N elements) and the other is a column vector (N elements and one column). Almost every built-in function in MATLAB requires inputs to be given in parentheses following the function name. with 100 elements? Define the vector using an already existing vector. so you just have to type the first value. you should write linspace(first_value. Try it: how would you define a row vector [3 4 5 6 7 8 9] in MATLAB? You can also specify how to “increment” the vector if you need the values to be changing by some other value by writing that value between the first and last value. Try it: how would you define a row vector [4 9 14 19 24] in MATLAB? Try it: how would you define a row vector [10 9 8 7 6 5 4 3 2 1] in MATLAB? The linspace command in MATLAB is helpful when you know the first and last value of a vector and the number of elements you want in that vector. ending at 10. This is the dot product we defined back at the start of this chapter.

5). then they must be the same size and you must use the “element by element operator” in MATLAB. y=-2:2. xy=x*y_col. There are a few commands that can be helpful in “measuring” vectors: length(x) size(x) 28 . w=x+y. You should be able to add or subtract x and y. which is the period. put a dot in front of the multiplication operator: x. Let’s try a few things: x=linspace(2. In MATLAB the transpose operator is the apostrophe: y_col=y'. But you won’t be able to get the dot product: x*y % should cause an error You can get around this by transposing the second vector (turn it from a row vector to a column vector).*y Notice this is different than the dot product of two vectors! You also need the dot to perform exponentiation: x.10. Notice that “left multiplying” and “right multiplying” are different when using vectors! Many built-in functions will work element by element on vectors: sin(y).^2. yx=y_col*x. exp(y).If you want to perform element by element multiplication on a vector. or use them together with scalar values: z=2*x. To multiply element by element.

” We can use these commands together with the parentheses to call out specific elements from a matrix. To make a matrix “from scratch. if you wanted to generate a vector that has the same dimensions as another vector. MATLAB has two commands for that: help and doc. zeros. These can be helpful later on when you are writing more complicated functions and computer programs where you don’t know these lengths outright (or don’t want to repeatedly define them). plus gives more details and examples. Try it: help rand doc rand Using information from the help or doc files (including examples on those pages!).The length command returns the number of elements of a vector. the result from the size(x) evaluation is then used as an input to the ones. and eye command are helpful for automatically generating large matrices of specific types (all ones. 29 . The doc command actually opens a popped-out help window that usually includes all the information that the help command gives. or an identity matrix of mostly zeroes but ones down the diagonal). Once a matrix has been created. What do those commands do? You might be able to guess based on their outputs. you can use the length or size commands as follows: ones(size(x)) zeros(size(x)) rand(size(x)) In each of the above examples. They can be created in similar ways as before. If you make a mistake and enter different numbers of elements in each row. 7 8 9]. zeros.) MATLAB also recognizes the end command when dealing with matrices to mean “the last one. or rand command. but anytime you don’t know what a function does. The size command gives the dimensions of the vector (number of rows and columns). The ones. we call this “overloading” an operator – which makes the same character/function do different things in different situations. the colon operator takes on another important function: it is also used as the command for “everything. For example.” (In programming. The help command gives a summary of the “help file” that is associated with that command and displays it in the Command Window. 4 5 6.” simply enter the matrix one row at a time and separate the rows with semicolons: A =[1 2 3. MATLAB will flag an error. can you now… Create a vector of 100 random numbers between 0 and 1? Create a 5-by-4 matrix of random numbers between 0 and 1? Create a 5-by-4 matrix of random numbers between 0 and 10? Create a 5-by-4 matrix of random numbers between 11 and 21? Matrices are just an extension beyond vectors. all zeroes.

determinant. Those commands are straightforward: rank(A) %Matrix is of full rank if this is the number of rows/columns. it’s probably convenient to dock the editor window and drag it to sit above the Command Window. In addition to operating in the Command Window. There are many ways to do this in MATLAB. If MATLAB doesn’t do it by default. -. All the rules of matrix arithmetic are followed in MATLAB – the +. x=A(:. A(3. in MATLAB you can define A and b and then type x=inv(A)*b to solve for x. (2) Use the backslash operator. Recall from earlier this chapter that we can learn more about a matrix system and its solution if we know its rank. MATLAB will automatically “solve” the system Ax=b if you type A\b.3) should assign to x the value of every row in the third column of the matrix A.2) = 19 should reassign the value of the third row and second column of A to now be 19. and/or condition number. but instead multiply them by their inverse. but here are two: (1) Use the inv command. and multiplication on matrices.2) should assign to x the value in the third row and second column of the matrix A. The Editor can be accessed in a number of ways. det(A) cond(A) What does the evaluation trace(A) do? Consult MATLAB Help. MATLAB features an “Editor” that allows you to write complete MATLAB programs. but it’s probably easiest to just click the “New Script” icon under the Home tab (or hit Ctrl+N on the keyboard). It is a computer program that was made with the ability to work with matrices explicitly in mind. then try these: x=A(3. and * operators will perform matrix addition. x=A(end.end) should assign to x the value of the last row and last column of the matrix A. MATLAB stands for Matrix Laboratory. Remember that we don’t exactly “divide” matrices.Define the matrix A as above. MATLAB is also able to easily and quickly compute all properties of matrices we care about. 30 . So the usual rules of matrix arithmetic apply. like in Figure 2 below. If you are solving the matrix equation Ax=b. subtraction.

31 . In order for the script to be run. Also. let’s get to the real reason we are here today. or to other people who might use your computer program (but if it’s an assignment. Do not put multiple lines in the Command Window on one line in the editor. type the name of the script in the Command Window. When you write scripts. You do not need to include the extension when you save the file. but you will need to at least copy and paste commands from your Command History in a script to successfully complete this week’s lab deliverable. click the giant green triangle marked “Run” in the top center of the Editor tab. not to other people in the course. To run a script. no spaces. So. or statements about why you wrote a certain expression a certain way. The same rules for defining variables apply for defining scripts – they should be unique names and not the same as another variable or already-existing MATLAB function. These are notes to yourself. %. and should include things like units for variables. No spaces. The Command History can be really helpful here. No punctuation marks. or to the instructor. No spaces. because sharing computer programs is cheating and seriously wrong). more easily. or. one after the other. You cannot use a variable until after you already defined it. for example. you can drag and drop lines from the Command History directly into the Editor window. you should include comments. This is important. only when the script is run. one line after the next. To write a comment. which is MATLAB’s way of saying it will ignore that text when it comes to running the script. Don’t put a space in your function file name. again – if you have already entered content in the Command Window that you know works. MATLAB scripts are saved by default as files with the extension . and finally put MATLAB to use solving linear systems. so to reiterate: the script is executed in the order it is written. so you keep track of them.m. Figure 2: MATLAB Desktop with Editor The contents of the Editor Window are executed in the order they are typed. and the text past it will turn green. We’ll look more closely at scripts next week. type the percent sign. it must be saved.

You should be able to create a matrix equation if you are given a system of linear equations.m2. Seek help in class if you do not figure out how to code this problem! 32 . we will revisit a problem from ENCH 215: In a given plant operation. let the mass flow rates of streams 1-4 be your four unknowns. y. four streams are mixed to give a single fifth stream with a desired composition.First.m4)=constant. The four inlet streams to the mixer and the final product stream have the compositions shown below: Stream Number Composition in mass % H2SO4 HNO3 H2O Inerts 1 80 0 16 4 2 0 80 20 0 3 30 10 60 0 4 10 10 72 8 5 40 27 31 2 Determine the mass flow rate of each individual stream to make 2000 lbm/hr of final product. If you are given a matrix.m3. and z? How did you figure them out? Double-check your solution by substituting those values back into the equations (is there a fast way to do this in MATLAB?). What are the values of x. do you recognize what system of linear equations that matrix represents? You should now be able to solve any matrix equation of the form Ax=b using MATLAB. which is a bit much). For this problem. Your four equations should be of the form f(m1. There are four material balances to write for this problem. which should fully define the problem (no need to do a formal degree of freedom analysis this time – you would have 20 variables and 20 equations. By way of one last example. or if you are given a problem that allows you to develop those linear equations yourself. let’s practice by putting the following set of equations below into matrix form: 2x+3y-5z=9 5x+6y+z=-1 x+2y-z=5 Define the left hand matrix as A and the right-hand matrix as b in MATLAB. and solve this system. so you can turn that into a matrix and solve using MATLAB.

and.1 Practice Problems 1) Below is a chemical engineering problem1 and complete solution to show the order of computations necessary to solve the problem. enter in the Command Window: publish('filename'. and finally displaying the results clearly in the Command Window.8 mol/h Benzene in vapor stream: ybennv=36.4 mol/h 1 Adapted from Felder and Rousseau. Write a MATLAB script that outlines the solution to this problem by defining all constants upfront. The mixture is partially evaporated to yield a vapor containing 76 mol% benzene and a exiting liquid containing 55 mol% benzene.6 mol/h Toluene in vapor stream: (1-yben)nv=11.4 mol/h Benzene in liquid stream: xbennL=28.2 mol/h Toluene in liquid stream: (1-xben)nL=23. Problem: A liquid mixture of benzene and toluene contains 65 mol% benzene. Prepare your MATLAB script as it is required for this class (refer to the Code Standard distributed in class and on Blackboard). save the MATLAB script. determine the molar flowrates of benzene and toluene in the liquid and vapor streams. For a feed rate of 100 mol/h of the initial mixture.m extension of the file when using the publish command). making sure that the Current Directory is the same as the folder where your script is saved. nv=ntotal(zben-xben)/(yben-xben)=47. “Elementary Principles of Chemical Processes. When you are finished. nL=ntotal-nv=52.nv) Solving for nv. zbenntotal = ybennv + xben(ntotal . then solving for each intermediate value in the given order.6 mol/h Back-substituting to get nL.'pdf') where “filename” is replaced with the name of your MATLAB script (do not include the .7.” 3 rd edition 33 .2. Solution: Total mole balance: moles in = moles out ntotal = nv + nL Benzene balance: zbenntotal = ybennv + xbennL Substituting.

y x It is known that the velocity of a given point v(x.y) depends on the velocities at the point to the left v(x-1. the point to the right v(x+1. Define the matrix A and vector b in MATLAB. Consider the grid below. Show your work using a well-commented code in MATLAB. Refer to MATLAB documentation for help with the publish command as needed. which you will then publish to . then solve for the six unknown velocities.pdf format.y). and the point below v(x. and cell structure.y+1). comments. 34 .y- 1) by the relationship Set up a system of linear equations that relates the velocities at the six circled points to each other in the form of a matrix equation Av=b.y). the point above v(x. We want to solve for the velocities at the six grid points in the middle (circled).2) One way to approximate the flow field in a rectangular channel is to partition it using a grid and approximate the velocity at each point in the channel based on the velocities of the four points adjacent to it in the grid. assuming that the velocities on all of the edges is zero. Refer to the Coding Standard on the Blackboard site for rules regarding variables. divided into five lines in the x-direction and four lines in the y-direction.

1 The Six Operations of a Computer All computer functions can be boiled down to being one or a combination of the six following tasks.4. In order to create a successful computer code “from scratch. You must be able to “read” flowcharts and pseudocodes to understand the work of others. Examples include playing a tone or sound and displaying text or numbers.html. Chapters 2-4 in Attaway’s MATLAB: A Practical Introduction to Programming and Problem Solving.” 35 . REPEAT: Perform a task multiple times (loop through multiple iterations). Examples include saving data to a file or defining a variable.3 Algorithmic Thinking Required Reading/Viewing: Chapters 4-6. 2.5. REMEMBER: Storing information to memory. Lots of examples here – adding. DECIDE: Compare a piece of information to another to determine how to proceed. and equality. subtracting. COMPUTE: Perform calculations with information. 9-10. and 13 of the free version of the MATLAB Interactive Tutorial from Mathworks at http://www.” you should know what a computer can and cannot do. repetitions are typically achieved using a “for loop” or a “while loop. some numerical information. or some textual information. and be able to think in terms of conditional statements and loops. Chapter Goals Convert a flowchart or pseudocode into a working computer code.3. you must be able to write them yourself to clearly communicate your ideas with others. If you are particularly uncomfortable with MATLAB. Describe an algorithm in a way appropriate to technical communication. 2.mathworks. Being literate in flowcharts and pseudocodes will aid in your understanding of experimental and numerical methods. Recommended for Further Consideration: Sections 4. a button press. decisions usually involve some sort of “if” structure. In textual computer language.2-4.3 in Pratap’s Getting Started with MATLAB. Examples include loading or opening a file.7 this week. 3. and 2.com/academia/student_center/tutorials/mltutorial_launchpad. In addition to being able to read flowcharts and pseudocodes. Create an algorithm in terms of the basic functions a computer. Examples here include “comparison operators” like greater than. OUTPUT: Writing or displaying information. less than. the six basic operations of a computer: INPUT: Reading information. multiplying. and dividing are the most basic ones. In textual computer language. or prompting the user for some sort of entry – for example. work through Sections 2.

For example: “If the temperature outside is below 32 degrees Fahrenheit. A pseudocode is a textual sequence of information that describes an algorithm -. decisions. This has involved defining variables (input and memory).” When writing out decisions. Section 2. you must conclude the set of commands inside the loop with an “end. While we haven’t explicitly instructed MATLAB to make decisions or repeat a procedure. A repetition in computer program is more typically called a loop. falling precipitation is rain. and displaying the results of those arithmetic operations (output). Notice that the two examples above are different in perhaps slight but perhaps important ways. IF the temperature is not less than 32 degrees. FOR the next ten people in line Let the person into the store A while loop is based on a condition (and. 36 . it is sometimes helpful to indent your text to more clearly show there are multiple possibilities: There is precipitation falling from the sky. and repetition. Algorithms are usually represented in one of two ways – as a list of directions like a pseudocode. we have used MATLAB to solve linear algebraic systems. Otherwise. or a detailed sequence of instructions for accomplishing a task. doing arithmetic with those variables (computation). IF the temperature is less than 32 degrees. then falling precipitation is snow. The most detailed computer algorithms provide a sequence of computer operations broken down to the level of the six fundamental operations. in that way. A for loop is a computer instruction to perform a task a certain number of times. There are basically two “flavors” of loops: the “for” loop and the “while” loop. or in a graphical representation known as a flowchart. THEN it is raining.So far. the truth is the innocent-looking backslash operator that we use to solve the system Ax=b is actually a complicated sequence of computer operations in which the rows and columns of A are manipulated in a particular order according to the values inside that matrix – a complicated but not difficult combination of computations.basically a computer’s “plan of attack” for working with information. A decision (sometimes called a conditional statement) in computer programming is the result of a comparison.” The above examples and indented texts are examples of pseudocode.9 of Pratap discusses ways to save and load data. When working with loops in MATLAB. THEN it is snowing. is kind of a combination of a decision and a repetition): WHILE there is room in the store Let the next person in line into the store Which kind of loop to use depends on the situation.

COMPUTE: Divide the mass by the molecular weight. for example. Express the problem statement in terms of labeled variables.. check to see what the units are. DECIDE: If the quantity is already in moles.1. When you write your own pseudocodes. 3. Enter the flowchart! Sadly. break the process down into the six basic operations. DECIDE: If the quantity is an ideal gas. These more complicated steps to the problem-solving algorithm are examples of subfunctions (or subroutines). written as a pseudocode: Choose a basis. DECIDE: If the quantity is a mass.com will attest. If multiple kinds of units or quantities are given (i. convert them all to one basis. So. DECIDE: If the quantity is a volume. Pseudocodes are sometimes easier for people to use to help write actual computer code. COMPUTE: Use the ideal gas law to convert to moles DECIDE: If the quantity is a liquid or solid. could be broken down into parts to convert every step to moles and written as this pseudocode: For every quantity given. Notice that some steps of this algorithm pretty clearly correspond to one basic operation (“choose a basis” is just inputting a value) while others are much more complicated (“solve the equations” is a series of decisions and calculations) and others are explicitly steps with multiple actions (“if this is true. COMPUTE: Multiply by density and divide by molecular weight. but I have added them above to emphasize that each step is essentially one of these six operations. move on to the next quantity. Perform a degree of freedom analysis. REPEAT the above until all quantities are converted. but for others. Note there are multiple valid responses to each of these. the next section explains how it’s done. If the degrees of freedom is zero. 37 . as a simple trip to ilovecharts.1 Practice Problems For each of the following numerical methods. write equations in an efficient order (avoiding simultaneous equations when possible). a more visual approach to computer codes is necessary. DECIDE: If the quantity is not in moles. do that”). Typical pseudocodes do not explicitly list the six basic operations of a computer. Draw a flow diagram and label all the known and unknown variables. next to no one makes a proper flowchart. Calculate the quantities requested by the problem statement if they have not already been calculated. they should at least be broken down into simple enough parts that you can easily “convert” them into a code suitable for the computer program you are using.tumblr.e. Step 4.An example of an algorithm is something we’ve run through several times in ENCH 215: let’s take the general procedure for solving material balances. Solve the equations. moles and mass). INPUT: Check to see if the current quantity is in moles.

There are multiple ways to denote multiple arrows into one block (the arrows may merge before entering the block or not). decision. only one arrow exits from each block in a flowchart. 3. 2) Determine the tip that should be put on a meal at a restaurant.2 Flowcharts A major reason we took the time to break down computer algorithms into the six basic operations is that they easily lend themselves to flowcharts. Except for diamonds. It’s possible that multiple arrows may point to the same block. or computation. allowing for the tip to be larger if service was especially good.5). the flow of the algorithm. 3) Determine how many terms of the Taylor series expansion for exp(x) around x=0 must be added together such that the error between this expansion and the actual value of exp(0. The basic shapes of a flowchart include the following: The start and end of a flowchart are marked with an oval: Input/output (reading/writing) is represented with a parallelogram: Computations (and sometimes memory) is denoted with a rectangle: Decisions are marked with a diamond: The results of decisions. Step 4 from the problem solving procedure in the last section can be transformed from pseudocode to flowchart as shown on the next page: 38 . and the presence of repeating (loops) is shown using arrows. 1) Compute the quotient and remainder for a division problem in which one number does not perfectly divide into the other. whatever makes the flowchart clearer in any case is always preferred. Flowcharts use differently-shaped blocks to communicate whether a block is an input/output.

(If you work with other students.) 39 . first try to represent what you want to do as a flowchart or pseudocode. When working through computer algorithms. Note that it is not always necessary to break down a command into its most fundamental computer operations – often listing more general ideas (or subfunctions) is sufficient. it is helpful to envision a computer code in this way. if you are stuck. start Are there quantities to no end consider? yes Move to next quantity Read the current quantity Is the quantity in moles? yes no What are the dimensions? mass Divide by molecular weight volume liquid What is the phase? Multiply by density gas Use ideal gas law The purpose of both pseudocodes and flowcharts is to present information related to a computer algorithm in a consistent way that is clear to understand. Sometimes for complicated problems. it is academic misconduct to share computer files. it is fine to share flowcharts and pseudocodes.

Find a flowchart online and redraw it to use the proper shapes/text/arrows. 40 . 2) The internet is full of examples of flowcharts.3.2. Write this strategy as a flowchart. indicating if your guess is too high or too low.1 Practice Problems 1) A classic example in computer programming (and one we will code very soon) is the “game” where one person is thinking of a number and prompts you to guess it. Describe the best strategy for “winning” this guessing game. but rarely are they formatted correctly.

if the Editor is closed) is your “Current Directory. Remember that the Command Window is best suited for one-line operations.5. Chapters 4-6. There Multiple inputs should be separated with can be any number of outputs (even none!) commas. and 13 of the free version of the MATLAB Interactive Tutorial from Mathworks at http://www. Save and load the contents of a MATLAB workspace.” This is the folder from where MATLAB is currently saving/loading files. After a single space. 41 . the Editor should be used. 2.7 this week.3 MATLAB Exploration: Scripts. In order to use commands that operate on MATLAB scripts (like those buttons on the Editor and Publish tabs). and Visualization Reminder: It’s in your best interest to watch the following videos before coming to lab. such as input/output. they must be enclosed in brackets. If there is more than one open parenthesis. and repetitions. Close parenthesis at the end. work through Sections 2. decisions. By the end of this exploration. you should be able to… Write MATLAB functions that require one or more direct inputs and produce one or more outputs. then the input(s). A function is a special kind of MATLAB script that usually requires some sort of input and provides some kind of output.com/academia/student_center/tutorials/mltutorial_launchpad. In the case of more complicated programming techniques. Use commands like disp and plot to display computational results. Today we will operate primarily using the Editor window in MATLAB. Create a loop in MATLAB. If you are particularly uncomfortable with MATLAB. It is also helpful to have read Chapters 2-4 in Attaway’s MATLAB: A Practical Introduction to Programming and Problem Solving or Sections 4.3. Debug MATLAB scripts using built in tools.mathworks. 9-10. and 2. Write a conditional statement in MATLAB. or as a testing ground for a small sequence of actions.input2.3 in Pratap’s Getting Started with MATLAB. the first line in your script has very specific requirements. 2. Your script word function. output. In order for your script to be recognized as a MATLAB function. and it is convenient to use because all lines entered are “remembered” in the Command History.input3) The function script This is the name of your must begin with the function. because many of these techniques require multiple lines to successfully execute! Just above the Editor (or Command Window. Here is the idea: function [output1. You may want to navigate to another folder as necessary.output2] = function_name(input1. Functions.html. must be saved with the same name. the name(s) of the output Immediately after the function name is an variable(s) is (are) given.3. your Current Directory needs to contain the script.4.2-4.

Here are the major differences. cond. we would have to modify the original script itself. scripts. or multiple). Outputs must be inside the script. No specific first line necessary. or in the Command Window.) No inputs or outputs absolutely expected in the May be written to require any number of inputs file. The script is run by entering its name in the Command Window. the mathematical functions sin and exp. assigned using the = operator. When the above script is run. like the matrix/vector creating functions ones and zeros. % FtoC. Now enter the following script into a new Editor window and save it (what should you save it as? Refer to the function declaration description on the previous page if you aren’t sure!): function tempC = convertFtoC(tempF) % Converts an input temperature from degrees Fahrenheit to degrees % Celsius. Script Function Usually written to achieve a specific. No specific last line necessary. It is good programming technique in MATLAB to include the word “end” at the end of your function. (Currently. It is important now to distinguish between a more general script and a function. Inputs or outputs may not be required when and outputs (may be zero. one. tempC=(tempF-32)*5/9. and trace. this is not yet mandatory.m % Converts a specific temperature from degrees Fahrenheit to degrees % Celsius. Inputs the script is run. limited task. Notice that if we wanted to convert another temperature. with the idea of needing it again in the future. then run it. rank. Any variables that are assigned during the running Any variables that are assigned during the running of the script will be posted to the Workspace. Now you will be able to create your own custom functions to serve your needs. tempF=77. Enter this script into the Editor and save it. tempC=(tempF-32)*5/9. Generally run only directly from the Command Generally run only within other functions or Window or using the Run button in the editor.So far in this course. Say that we want to write a simple script that converts a temperature from degrees Fahrenheit to degrees Celsius. we have used functions in passing – MATLAB has hundreds of built-in functions. Very specific requirements for what must be in the first executable line of your m-file. Let’s look at an example. notice that the values for tempC and tempF appear in the Workspace. of a function are used in a “private” version of the Workspace and not posted to the Workspace at any time before/during/after running. Usually written to work for more general tasks. Everything is assigned directly must be specified when running. end 42 . and matrix evaluation ones like det.

3) The number of inputs into your custom function must be the same as the number of inputs you specified in the first line of the function. compute the area and perimeter of a rectangle given its length and width: function [area.perimeter] = rect(length. 43 . end Write and save this program. Try typing this into the Command Window: convertFtoC(77) Now the function should have properly run (if not.If you try to run this function using the Run button in the Editor or by typing “convertFtoC” in the Command Window. the same way there was when we did basic math in MATLAB last week. but notice the differences compared to the FtoC. the outputs are only collected if you specify you want them all (in this case. with no need to edit the function file directly. double-check your m-file to make sure you entered it correctly and saved it as convertFtoC.p]=rect(4.invar3) where the number of inputs and outputs should be the same as that in your function m-file. Let’s put together a quick program to use two inputs and outputs – say. perimeter=2*(length+width). just both) – only in that last of those five command lines did MATLAB store both the area and perimeter to the workspace! In general. then try entering the following lines into the Command Window.m). Which ones run without error? What is the result in those cases? rect rect(4) rect(4.3) x=rect(4. if you call a function that you have written.width) area=length*width. then the line in MATLAB to execute it is [outvar1. A function requires an input to be given directly. you get an error: >> convertFtoC Error using convertFtoC (line 5) Not enough input arguments.outvar2]=function_name(invar1.invar2. If you wanted the result of the function to be stored as another variable. If a custom function gives more than one output. just enter a command like T=convertFtoC(32) We can change the number in the parentheses after the function name and we get different correct results immediately.m script that you wrote: There are no values for tempC or tempF in the Workspace. and instead a value for ans.3) [a. The function we just wrote has a single input and single output.

3) xlabel('This is the x-axis') ylabel('This is the y-axis') legend('Points'.^2. Let’s make a simple plot of y=x2. color. The other issue with MATLAB plots is the labels/axes fonts are tiny. The other option for plotting multiple data sets at once is to use MATLAB’s hold command.y2.y) If you enter just one set of vectors. x and y.x. Choose View → Property Editor in the Figure Window (wait for it to load). but before we move on to more of the basic six computer operations.. Try moving it to the upper left corner by rewriting that last line. The above plot command for three unknown sets of data is equivalent to writing plot(x1. The doc command reveals legend can be a little more interesting: in addition to labeling different plots in order.y2) plot(x3. The most basic call of the plot command first requires that we define vectors that correspond to the independent and dependent variables.':g'. ylabel. click the Font tab. y=x.Now we have explored how MATLAB functions work with inputs and outputs. into the plot command. let’s look at two more kinds of output: MATLAB’s plot and disp commands.'LineWidth'. especially when you copy and paste into Word (use Edit → Copy Figure). etc.y1) hold on plot(x2.x2.y3) and so on. and markers MATLAB uses and see a more complicated plot example). y1.y. In addition.'Location'. but the basic idea is that you can plot multiple data sets at once (as long as the paired vectors are the same length!) by simply entering them one after the other with the same plot command (assuming you have vectors x1.x3. you can use supplemental commands like Location to tell it where to place the legend on the plot. you can specify line type.'Southeast') If you had to guess what xlabel. and bump that font size up to at least 16 points. and legend did.y. % why do we need a dot in front of the ^? plot(x. This instructs MATLAB to leave a current figure open and to plot “on top of” it. you get MATLAB’s default decisions of a solid blue line that basically “connects the dots.'ko'. and markers by typing them in single quotation marks immediately after the y-axis data for a given set (type doc linespec to see the possible line type. color.” You can dress up the plot command with lots of other inputs: plot(x. The plot command can be used in a lot of different ways. You can enter this in a script or in the Command Window: x=0:10. The plot command is used to create figures in MATLAB.y3) 44 . then click on the graph axis.y1. defined first): plot(x1. you’d probably guess correctly.'Line'.

which can be used to save/load the contents of the Workspace (or the “private Workspace” if used within a function).num2str(x)]) Several important things to point out from just this disp line: Text in MATLAB is specified by putting the contents in single quotation marks. Try entering the following lines in the Command Window. there are the save and load commands.The disp command is used to display text directly in the Command Window. MATLAB has a number of related built-in functions related to storing information for use at a later time. MATLAB also has the ability to save/load directly to spreadsheets using the readxls/writexls or readcsv/writecsv commands. If one condition holds. Within MATLAB. We’ll talk a little more about these later. (There is a similar str2double command that converts text to a number… if that text actually is a numeral. you need to make a “vector” of text. but be sure to use save and load as necessary in your work. To convert a numerical variable to a text variable (MATLAB calls it a “string”). these statements are written as follows: if condition disp('this') else disp('that) end The condition is a logical expression that either computes as true or false. This is helpful to show values in the Command Window while a script or function is running. z=isprime(5). The entry format is simply disp('insert text here') disp works also with variable values. and if not we want it to do another. you need to convert that result to text: x=sind(90). x<1. and keep an eye on the Workspace: x=2. MATLAB has a variable type called “logical” that can only take on one of two values: true or false (in the Workspace. You have likely worked with computer decisions before – this is where the idea of an “if/else” statement comes into play. MATLAB will write to multiple lines. you use the num2str command. but it will not mix variable types. disp(['The sine of 90 degrees is '. If you use multiple disp commands.) To display multiple pieces of text with one disp command. In MATLAB. If you wanted to make MATLAB display a sentence announcing the result of a computation. using square brackets. condition=x>3. Another of the six basic computer operations is deciding. y=true. we want our program to do one thing. 45 . they’ll be listed as 1 or 0).

MATLAB will briefly underline it and its corresponding “beginning. though? grade2=grader(1478) If we think about this program the way it is written. what must the first line of your MATLAB file be? It is incomplete below). So. then skip the instructions between else and end. it will display “that”). the instructions between if and else (in our example on the last page.” Try it – click the first end and see that “if” gets underlined. click the second end and see that “function” is underlined. let’s try writing a basic MATLAB function called grader that accepts a numerical value as an input and writes a letter grade as an output (and for practice. what’s going on in that if/else/end structure is MATLAB is checking to see if condition is a logical “1” or a logical “0.) Save your m-file (make sure its name is grader!) and then try using the function in the Command Window (watch the Workspace as always): grade1=grader(1750) What happens if we didn’t get an A. but we need to use the Editor to execute if/else structures. ==. We can have MATLAB check to see if a variable is an integer. MATLAB has a lot of built-in commands that also produce true/false values. and execute the lines in between else and end instead (in our example.Notice that any time a comparison is involved. MATLAB will execute. So really. and the function is finished! Sounds like we need an else.). If you click on the word “end” in your m-file. and many other things – type doc is* into the Command Window for the complete list. like the isprime command. etc. in order. end end (There are two “end”s because the first end is the end of the if structure. end 46 . the result is a variable of the “logical” type. if score>=1700 grade='A'. a character string. If the input is less than 1700. a numeric value. and the second end is the end of the program. In addition. There are lots of different “conditional” operators. it will display “this” in the Command Window). all it does it assign a text value of “A” if the input is 1700 or greater.” If it is a 1. The Command Window is a nice “testing space” for conditional statements. MATLAB skips over the stuff between if and end. function ___?___ = ___?___(___?___) if score>=1700 grade='A'. >. and you’ve been using many of them in math class probably since before you can remember (<. If condition is a 0. else grade='not A'. MATLAB will skip the stuff between if and else.

elseif score>=1500 grade='B'.” when MATLAB is at the “while” line. but “not A” isn’t very helpful. if userguess>number disp('Nope. we’ll use while loops to run a computational procedure until our answer is “acceptable. Later in the course. is done in MATLAB by using loops. as long as the condition corresponds to a logical “1. MATLAB will skip over all the lines from while to end. If you get stuck in an infinite loop. MATLAB allows for multiple if statements at once using the keyword elseif. Repeating. It’s really important to include some instruction between while and end that can potentially change the condition on the while loop.Now try assigning grade2 again. end Can you finish the if/elseif/else structure by adding more elseif lines to assign letter grades from A to F? While conditional statements are useful in making certain decisions in computer programming (if you are running a computer simulation on a reactor at an unrealistic pressure or temperature. where the computer chooses a number between 1 and 10 and prompts the user to guess what it is. or else MATLAB will continue to execute those lines between while and end… FOREVER. Try saving this in your Editor: number=randi(10). they are much more useful when it comes to ending a repetitive task. It would be nice to be able to assign the right letter grade in the right condition. another one of the six basic computer operations. It at least saves a value. disp('I''m thinking of a number between 1 and 10!') while ~guessedright % could also write while guessedright==false userguess=input('Guess what it is: '). The general structure is as follows: while condition do this and that and something to do with the condition end The lines in between while and end are executed in order. % What does this function do? Check the help file! guessedright=false. over and over again. you might as well have a simple if statement to skip over the rest of the program and not waste your time). click in the Command Window and press Ctrl+C on the keyboard.” if score>=1700 grade='A'. disp('You got it!') end end 47 . it''s lower than that!') elseif userguess<number disp('Nope.” A simple example of that is this guessing game. The last condition still just gets the word “else. it''s higher than that!') else guessedright=true. elseif score>=1300 grade='C'.” If the condition corresponds to a logical “0.

end end end 48 . the while condition doesn’t make MATLAB immediately break out of the while loop when the condition changes. or right – there is no fourth option. so unless you are writing a program where you seriously want to prompt the user for an input somewhere in the middle of the program. Notice that even though we changed guessedright to true. Usually you will put an expression there to evaluate (like “guessedright==false”) but if you have a variable that you know is true or false.” It starts by setting index equal to first_value. It is told to display “You got it!” before it gets back to the start of the while loop – in other words. type a double apostrophe (not a quotation mark). Do you understand these details? While (and if) again work by checking if the rest of the line after the word “while” (or “if”) is true or false. and continues to do this until the index exceeds last_value. That’s because MATLAB will execute commands in order. the program still displays “You got it!” afterwards. for index=1:length(vec) if vec(index)>m m=vec(index). Here.” so ~true means false. If you don’t put a “step” on the for line. It’s not particularly elegant (or useful) in complex computer programs. then it adds step to the index and executes the lines again.Lots of stuff going on here. too low. a “for” loop is the way to go. It’s always a good idea to make sure all your if/elseif/elses cover all possible options. the index is MATLAB’s “counter. we could write a custom function that reads every value in a vector and displays the maximum. and instead write for index=first_value:last_value MATLAB will automatically assume a step of 1. then it executes the lines between the for and end. Another nice thing about for loops is you can use the value of index directly in your program. For example. The input command is a quick and dirty way to prompt the user for an input. Try writing and saving this function in a new Editor window: function m = maximumvalue(vec) m=-Inf. which is often what you want to do anyway. it’s better to just write a function that requires the input upfront. In the case that you know exactly how many times you want a loop to be repeated. the guess must be too high. If you want to use the disp command to display an apostrophe. you can just put that variable instead! The ~ operator in front of a logical variable means “not. The idea is very similar to the while loop: for index=first_value:step:last_value do this and that end In the above general formulation.

During your MATLAB adventures so far. red text and sometimes confusing language. try to interpret what it means. one line at a time. when you are computing the error in an iterative procedure (see chapter 6) you probably want to set the initial error to positive infinity. confused. but stop when it gets to the red circle. with their cold. to see how your code is working. From then on. I don’t know how many elements might be in the input vector. This is helpful in “initializing” a variable that you need later – for instance. If there is an error in one of your MATLAB scripts. if you click Run. we all make errors in computer programming. Try the function out! >> maximumvalue([1 2 3]) >> maximumvalue([1 50 -12 0 0 0 7]) Okay. A red circle should appear on the left side of that line. one line at a time. and all the options to the right of the Breakpoints button change. there is button marked “Breakpoints. To set a breakpoint. Debug Mode lets you “walk through” a script. then click “set/clear breakpoint” on the Breakpoints menu. or distraught. Debug Mode becomes active. you must click the “step” button to give MATLAB permission to go to the next line. one more thing this week. Try running the programs we wrote this week in Debug Mode and watch as MATLAB manipulates values in the Workspace. In the Editor.” 49 . Then. MATLAB will run the code. since you never really know how large the initial error might be! You can have MATLAB do some math or evaluate a function directly in the line with the for loop. but I can easily have MATLAB determine its length.” Once you set a breakpoint in a script and try to run it. Those messages aren’t there just to make you angry. all the time. do you see that MATLAB points out which line in your code is causing the mistake? Can you tell why MATLAB stopped working? (Are your variables defined? Did you write a custom function but save it in the wrong folder? Is there just a typo?) Sometimes error messages are just too confusing to understand. but MATLAB has another tool to help you in your quest: Debug Mode. The truth is. When you get an error. In this case. You can exit Debug Mode at any time by clicking “Quit Debugging. I hope you have run into some error messages. click a line in your code.A couple other MATLAB tidbits here: MATLAB recognizes infinity (and negative infinity) as a value.

I know you can make all this stuff work for you. but if you are patient and diligent. 50 . And again.When you’re done. Whew! That was a lot. be sure to “clear all breakpoints” so that MATLAB doesn’t go into Debug Mode every time you use that script. Ctrl+C breaks you out of a function if you don’t want to debug it all. Let’s put it to the test with this week’s MATLAB problem.

5. Demonstrate that you can create a vector of numbers that are normally distributed and that you can visually display them in a histogram. and has asked you to create a new random number simulation script using MATLAB. 1) Your boss at the FCC sends you an email this morning.000 numbers that are normally distributed with a mean of 5 and standard deviation of 4. you can also use a combination of loops/conditionals to achieve the same result. the activation energy of that molecule must be greater than or equal to 75 kJ/mol.] 2) In determining the likelihood of profitability for a new chemical plant design.. histc. The Finance division of the FCC has already spotted you as the jack of all trades that you have quickly become. which is a uniform distribution – not what we want for this simulation!).5. raw materials. Don’t forget to use MATLAB to publish your work. 1. estimate how many of them are negative (which corresponds to a loss of money).) b) Create a histogram of the random numbers that you just generated by partitioning them into bins of width 1 (i. They assume the distribution of actual scenarios is normal. b) Create a histogram of the random numbers that you just generated by partitioning them into bins of width 0.3. Note that the lower limit of your histogram will probably be negative. According to one forecast.0 and 1. c) Out of your 10.1 Practice Problems The randn command in MATLAB generates random numbers according to a normal distribution (the rand function assumes all numbers are equally likely. and processing. you need to compare it to a computer simulation that actually works. 42 and 43. In order for the simulation to predict a successful molecule of reaction.5 and 1.3. [Hint: check out the MATLAB commands hist. etc… then plot them in a bar graph).e. 0. a) Use the randn command to generate 10. but at any time the energy of an individual molecule may be much lower or higher than that. a) Use the randn command to generate 10. a series of complicated random number generations are used to simulate thousands and thousands of possible scenarios for changes to costs of equipment.. In order to make sure that the current software is working correctly. count the number of values between 0 and 0. asking you to troubleshoot their chemical reaction simulation software. you’ll need it for part (b).e.000 numbers that are normally distributed with a mean of 75 and standard deviation of 10. etc… then plot them in a bar graph). 41 and 42.000 numbers. (Don’t display this – suppress it with a semicolon. the Net Present Value of a new business venture has a mean of five million USD with a standard deviation of 4 million USD. If you find the hist-type commands confusing. What is the probability that this investment will lead to a loss? 51 . so you set off to write one in MATLAB. and bar – using one or two of these built-in functions should make your life a lot easier. You may find the hist and/or bar commands to be helpful in generating your solution. which might be good practice anyway. count the number of values between 40 and 41. as well as changes to revenue or the amount of “down time” the plant experiences after starting up.5 (i.

Simply put. 1st edition. 80-90%: 15 students. 70-80%: 20 students. this is the organization and display of data. the three classes of statistical measures. 90-100%: 22 students. and F’s received on an exam is a frequency distribution.3 in Pratap’s Getting Started with MATLAB or Section 13.37. B’s. so you should be able to both read and write probability distributions. 52 . and position. is inferental statistics. Obviously we expect the sum of relative frequencies to be one. The rest of this chapter is organized to discuss frequency distributions. This helps in your technical communication by clearly and concise describing a lot of data at once.1 Descriptive Statistics You’ve probably already worked with descriptive statistics in the past. the use of statistical computations to draw conclusions about a population. Your understanding of probability is crucial to your ability to make statistical claims on an experiment. The other major component of statistics. or relative frequencies of classes. The classes are the letter grades and the frequencies are the number of students receiving those grades. 60-70%: 3 students Sometimes we are interested in percentages.1 Frequency Distributions A frequency distribution is a table that shows a count of data corresponding to specific classes or intervals. Chapters 1 and 3 of Navidi’s Principles of Statistics for Engineers and Scientists. Chapter Goals Describe a set of data or a specific datum relative to that set of data by using an appropriate collection of statistics. In the list above. and the one to which we’ll pay more attention.1. or any other statistics text. which may include measures of central tendency. a list of the number of A’s.1 in Attaway’s MATLAB: A Practical Introduction to Programming and Problem Solving. variation. Your ability to work with probability distributions is crucial to statistical hypothesis testing. These are the frequency values divided by the cardinality. The cardinality of a data set is the total number of entries. For example. or the sum of the frequencies. Compute the probability of a result for a given mathematical experiment. 4. and basic probability theory. 4. C’s. The frequency of a class is the number of data entries in that class. and the relative frequency of the 90 − 100 class is 22 /60 = 0. Create a probability distribution for a numerical experiment. the cardinality is 60. D’s.4 Descriptive Statistics and Basic Probability Theory Recommended for Further Consideration: Section 5.

If the cardinality of the data set is even. there is no mode for that data set. An outlier of a data set is an entry that is far from any measure of central tendency. the data is right- or positively skewed.21 times 32 g/mol for oxygen. in a histogram. the molar mass of each component of air is multiplied by its mole fraction (when simplified. we call a data set symmetric if a vertical line can be drawn down the “middle” of a histogram and the halves are roughly mirror images. One last comment about measures of central tendency: we can compare one measure to another. A histogram is essentially a bar chart with the added specification that adjacent bars must touch. In computing this molar mass.1. pie charts. If the median is greater than the mean. If the histogram appears to be bell- shaped. this is 0. the classes (sometimes called bins) are listed in increasing order on the horizontal axis and the (relative) frequencies are marked on the vertical axis. or. For example.The main graphical display of a frequency distribution is called a histogram. or negatively skewed. to add some qualitative comments to a data set. The mean of a frequency distribution is given by the very same formula. then the data is approximately uniform. The median of a data set is middle entry of the set after all values have been arranged in numerical order.. If the histogram looks roughly rectangular. that the data set will have a “tail” in the direction of which it is skewed. fN is given by where wi is the weight of an entry. We represent the mean of a population with μ and the mean of a sample with ¯x. If the median is less than the mean. Other types of frequency graphs include stem-and-leaf plots. the frequency distribution may be normal–more on that type of distribution later. In a histogram. the frequency of each class is approximately the same. the median is the mean of the two middle values. Depending on your data processing. 4. If no entry occurs more than once. If two (or three. that is.2 Measures of Central Tendency A measure of central tendency is a value that corresponds to a typical data set. we say the data is left-skewed. or more) data entries occur with the greatest frequency. except now f represents the frequency of a data value. or look at a histogram. A weighted mean of N values f1. f2. (Chances are. ….79 times 28 g/mol for nitrogen added to 0. for a weighted mean of 29 g/mol). One final qualitative description of a frequency distribution is its skew. each entry is a mode and we call the set bimodal (or trimodal. actually.) 53 . The mean of a data set is the average value of the entries. The mode of a data set is the entry that occurs with the greatest frequency. you may be able to choose to remove such an entry from the set. all of which do the same thing: present a frequency distribution in graphical form.. A typical use of a weighted mean from chemical engineering is the molar mass of a mixture of gases. and scatter plots. like air. you get the idea).

Take a look at the units on σ2. The deviation of a single entry x in a population data set is the difference between its value and the mean. For a normal distribution. (Note again another example of the heuristic “for all practical purposes. A fractile is a partition of the data set into roughly equal sizes.3 Measures of Variation The range of a data set is the difference between the maximum and minimum values of a set. you can be more specific than this. there is an empirical rule.7 Rule. That’s why we work more with standard deviations than variances.1. 95% within two standard deviations. 54 . when do we know we’re working with a normal distribution? We’ll discuss this in section 4. The third quartile is the median of the data between the median and maximum. One notable disadvantage to working with variances is that they are not very intuitive. 4.4.4. which says that roughly 68% of data lies within one standard deviation of the mean. but the denominator is n − 1 instead of N. where n represents the sample size. If you sum the deviation of all entries in a set. depending on whether you are working with the population or a sample.4 Measures of Position While central tendencies and variations are more useful for statistical computations and inference. and 99.1. What’s a “square dollar?” Does “square inch” carry the same meaning as an area? Not exactly. four is infinity!”) So the question you may have is. which divide the data set into four parts. The standard deviation of a data set is simply the square root of the variance. Most commonly used are quartiles. often called the 68-95-99. The variance of a population is denoted σ2 and computed as where N is the number of values in the entire population. there is a third type of statistical measures called measures of position. but when you know more about your specific probability distribution. We may denote the ith quartile as Q i. It’s denoted s for a sample and σ for a population.7% within three standard deviations. The variance of a data set is computed differently. The second quartile is the median of the data set. you will get zero (and if this is not obvious. The variance of a sample is denoted s2 and is calculated similarly. That’s part of the reason we square deviations in order to get usable measures of variation. that is. x − μ. take a moment to convince yourself). The first quartile is the median of the data between the minimum and the median. For any distribution of data. the Russian mathematician Pafnuti Chebychev proved that the fraction of data lying within k standard deviations of the mean is at least 1 − k −2 provided k > 1. This applies to all distributions.

three quartiles. We want to be able to answer the question. You may have used these numbers in the past to create what is called a box-and-whiskers plot. Q3 − Q 1 . what is the probability that our result is different than the literature (or different than another related result)?” 55 . “Based on our experiment and data.5 Practice Problems 1) Find the mean. The z-score of a data entry x is the number of standard deviations that x is away from the mean. our department’s upper level course in statistics) if you want more background on probability. and standard deviation of the set of integers between 1 and 20. As we’ll see in the next chapter. Another way to do this is to compare your results to literature (we’ll call this a “one-sample test. For the purposes of ENCH 225.2 Introduction to Probability Much like how I recommend for you to take an actual linear algebra class in the chapter of this packet on linear algebra. Perhaps you have computed more accurate “error bars” (plus or minus one standard deviation is sometimes useful. I have included two “optional” sections past this one to hit on concepts to probability that are related but not required for this course. of your senior chemical engineering lab. One way to do this (and what you’ve probably done up to now) is report results as a mean and standard deviation. What is the z-score of the value 9? 3) A data set has a mean of 4 and a standard deviation of 0. the probability computations we care about are all embedded within inferential statistics.1. Finally. I’m going to try to give you just want you need to know to do the experimental analysis required in our core curriculum. mode. that is. we want to be able to quantify how certain we are of a given result. In rough terms.” because you are collecting one set of data and comparing it to an already established value).5. I’m also going to suggest taking engineering statistics (or ENCH 459. 4. and maximum. the most important measure of position is the z-score. The formula is and in many cases the population mean μ and population standard deviation σ can be replaced by their respective sample mean and sample standard deviation.The interquartile range of a data set is the difference between the third and first quartiles. sometimes you need more than that) – and we’ll hit that topic in the next chapter. The five-number summary of a data set is the minimum. What value will have a z-score of -3? 4. or to compare one set of results to another (a “two-sample test”). 2) A data set has a mean of 7 and a standard deviation of 1. sometimes called the standard score. so don’t worry if you don’t know what that is. median. Virtually everything we touch on here will matter in the physical lab component of this course. which I won’t discuss here. or both.2.

The one you’ve probably seen before is the normal distribution. Essentially. Further.09. As is typical in engineering. what percentage of the data has values that are less than or equal to that particular point? For a probability density function fP(x). Also if data is normally distributed with known mean and standard deviation. If a data set is normally distributed. 68% of all data lies within one standard deviation of the mean (do you see why reporting just plus or minus one standard deviation is only sometimes useful?). we will have looked at four different kinds of probability distributions. the probability that x lies between xL and xU is For a normal distribution. The idea is that for any z-score from 0. or consult another statistics book or (for once) a website like Wikipedia. Table B. if you were to choose at random. that function has proven important for a number of applications. You’ve definitely encountered tables like the z-table before. Along the leftmost column is a range of z-values from 0. A brief note on reading your typical z-table. You can check the course files in Blackboard for my table (this is what I will give you for exams).7% lies within three standard deviations. then the most likely observation (single piece of data) you would select. and one we can’t do analytically. you find the appropriate row for the tenths place in the z- 56 . 95% of all data lies within two standard deviations of the mean. and statistics books include numerical tables of integrals of the standard normal distribution. However. and 99. we have a scary looking function to integrate.3 in Felder in Rousseau does the same “read the number off the left and the decimal off the top” thing to help display the vapor pressure of water for a wide range of temperatures. we can determine the exact percentile of any given piece of data – that is. median. and the formula for the standard normal distribution becomes . where μ and σ are the mean and standard deviation of the distribution. The formula for the probability density function of the normal distribution is given by . is the mean and the median. the mean determines the location of the distribution’s “peak. we’d like to standardize and nondimensionalize the normal distribution so that we only have a standard normal distribution to worry about. There is a separate handout in our course website that gives a table of values from this distribution. By the end of this course. So. so it’s been well studied. the normal distribution is symmetric.” and the standard deviation determines how “spread out” the distribution appears. or the bell curve.0 to 3.0 to 3. the mean. we must become somewhat skilled at using probability distributions. For a normal distribution. and mode are equal. Computer programs like Excel and MATLAB also have built-in functions that provide these numerical values. and along the topmost row is a range from .00 to .49.In order to answer this question. we replace the datum x with its z- score z.4. also known as the Gaussian distribution.

3 (Optional Section) More on Probability Theory and Combinatorics An experiment is an action that produces a specific result where this result is not always necessarily the same. then P(B|A) = P(B) and P(A|B) = P(A). the statistical probability will approach the theoretical probability. a collection of some of the outcomes) is called an event. The theoretical probability (or classical probability) of an event E.) The statistical probability (or observed or empirical probability) of an event E is the frequency at which E is observed divided by the total number of observations.49 is 1 (and for values less than −3. For most practical purposes. This result is called an outcome.1 Practice Problem Determine the area of the normal distribution (a) between z=-∞ and z=-2.” is the probability of an event (B) occurring provided that another event (A) has already occurred. The number in this position is the integral of the standard normal distribution from zL = −∞ to the z-score of interest. (b) between z=-1 and z=3.49 and 0. 57 . assuming all outcomes are equally likely. it should be straightforward that the probability of two independent events occurring is simply the product of their probabilities. and E’ = S \ E.) The “Law of Large Numbers” basically claims that if an experiment is repeated enough. 4.score. Two events are called independent if the occurrence of one does not affect the probability of the occurrence of the other. The set of all possible outcomes is called the sample space. then trace to the right to the appropriate column for the hundreths place.2. written P(B|A) and read “the probability of B given A. If A and B are independent. you simply subtract the table value for the positive z-value from 1. if we write the sample space as S and the complement as E’. Use of the complement is helpful when it’s easier to compute the probability of E’ than that of E. Using this definition. the probability is 49/100. The complement of an event E is the subset of all outcomes that are not outcomes in E. (Example: if I flipped a fair coin 100 times and got heads exactly 49 times.49 is 1 − 1 = 0). A subset of the sample space (that is. written P(E). Further. if you need the value for a z-score between −3. A conditional probability. 4. because the normal distribution is symmetric. (Example: the probability of flipping a fair coin twice and getting heads exactly once is 2/4. because P(E’) = 1 − P(E). the integral for values greater than 3. In set notation. and (c) for the region greater than z=1.5. The probability of two events A and B occurring is P(A&B) = P(A)P(B|A). An experiment that produces a single outcome is called simple. is the number of outcomes in E divided by the total number of outcomes.

stated “n choose r” for short. The factorial is also defined for n = 0 such that 0! = 1. For instance. how many seven-digit numbers can we write without repeating a single digit? Since there are ten possible digits to choose from and we are selecting seven. is it different the first time it is used compared to the second time? (Is 1234566 different than 1234566? But I switched the 6’s! Nope. When order doesn’t matter. we can write this permutation computation as 10P7 and computer it according to the following formula. is written and computed as Binomials are covered more in the next section. For example. or figure out the number of socks you need to draw from your drawer in the dark to make sure you have a match. the number of ways we can arrange zero things is one. The number of different permutations of n objects is n!. with n=n1+n2+…+nk). if you consider the definitions in prior sections. given for the number of permutations on n objects taken r at a time: Sometimes the items we want to arrange are indistinguishable.) So. is the product of all integers from 1 to n. you could say that a relative frequency distribution is an observed probability distribution). Sometimes we wish to know the number of permutations on a set where we are selecting a subset of all possible items. as . The factorial of a number n. This is where you’d learn how many different ways you could hand out nine pieces of candy to four people. and by the definition of factorials. what if we wants to count how many seven-digit numbers we could write while allowing for repeated digits? If a digit is repeated. we are computing combinations. and nk are have another type. n2 are of another type. Combinatorics is the mathematics of counting. The factorial is used to compute permutations. we can compute the number of distinguishable permutations on n objects (where n1 are of one type.4 (Optional Section) Computations with Probability Distributions Probability distributions are analogous to frequency distributions (and actually. denoted n!. …. if event A can occur in j ways and event B can occur in k ways. Why do we need to waste our time learning how to count? Because we need to know how to find the total number of outcomes for a probabilistic event. it’s the same. The number of combination of n objects taken r at a time. or ordered arrangements of objects. of course! Fundamentally. 58 . 4. then the number of ways events A and B can occur sequentially is j times k. which are numerically equivalent to binomial coefficients (more on those soon).Two events are called mutually exclusive if they cannot occur simultaneously.

we have a lot of definitions that are analogous to descriptive statistics definitions. P(H) = 0. whatever. repeating 6 times. the sum of all discrete probabilities (or the integral over all continuous probabilities) must be one. If either of these conditions are violated. which are traditionally labeled as “success” S and “failure” F. Denote two outcomes.25. In each trial. 0/1. on/off. say. Second. but it can be heads/tails. and the standard deviation σ is the positive square root of the variance.75. 59 . We will devote our attention to one discrete probability distribution in particular: the binomial distribution. First. the probability P(S) is the same in each trial. P(H)=P(T).1 Binomial Probability Distributions A discrete probability distribution can be visualized as a relative frequency histogram. there are two outcomes. In this case. then the distribution is not a probability distribution. The variance of a discrete random variable is computed by . They are effectively the same thing. In fact.) A probability distribution displays the probabilities of all potential values that a random variable can assume. The variable x represents the number of times heads turns up. where P(x) is the probability that the result x occurs. (More often than not – but not always! –a discrete variable is limited to integers. That is. each random variable must have a probability P such that 0 ≤ P ≤ 1. Example: Flipping a fair coin 10 times. and continuous if the variable is continuous. but they are stated here for completeness. A probability distribution is discrete if the variable in question is discrete. while a continuous variable can represent any real number. 4. The mean of a random variable is also referred to as its expected value (denoted as E[X]) or its first central moment. and can take on any whole number value from 0 to 10. hearts (H) or not hearts (N).4. and x is a whole number between 0 and 6. The random variable x is then the count of “successful” trials. There are two conditions that all probability distributions satisfy. This is the probability distribution of a binomial experiment. P(N) = 0.A random variable represents a number that in turn represents the outcome of a probability experiment. Example 2: Drawing a playing card out of a standard deck of 52 cards and returning the draw to the deck and shuffling between trials. In this case. In this case. the same experiment is repeated for a fixed number n of trials. The outcomes are either heads (H) or tails (T). Such a variable is discrete if there is a finite number possible outcomes and continuous if there is an infinite number of possible outcomes. The mean of a discrete random variable is analogous to the weighted mean of a data set. Each trial is identical. The variance of a random variable is sometimes also called its second central moment (denoted as E[X2]). that is.

a continuous probability distribution is essentially the limit of a discrete distribution as the number of discrete random variables tends to infinity. so we’ll talk about them in those sections. We could plot them all together in a histogram to get a good visual idea of the probability distribution. and the probability corresponding to x (height of bar times width of bar) is nonzero. If this were a math class. the uniform and normal distributions. and the integral of the PDF over all random variables is equal to one. so they are discussed here. For every valid value of x (0. probabilities correspond to ranges of values. The other two. The probabilities for all other values of x are zero (it’s impossible to have 6 heads. probability of failure q = 1 − p. So the probability that the computer program chooses exactly 1. Now consider a second “experiment” where a computer program generates a real number between 0 and 5 inclusive. or -1 heads. the t-distribution. Much like the concept of Riemann sums from calculus. Was that last bit confusing? It will make sense with some examples – I’ve tucked them all in Section 4. or even bell-shaped! More on that in a moment… Using the definitions for mean. σ2 = npq. or 2. so you can have the result for free! The equations become μ = np. Remember that there are two properties to a probability distribution that are still valid here: no point on the PDF takes on a value greater than one. In the same way. 60 .4.3 heads!). you can imagine a histogram (discrete probability distribution) being divided into thinner and thinner bars on the number line until we have a continuous probability distribution.5 is zero.2 Uniform and Normal Probability Distributions There are five kinds of continuous probability distributions that we will use this semester. Three of them. but we’re engineers. 3. In continuous distributions. and x is the number of heads. and standard deviation of a probability distribution. often called a probability density function (PDF). are used nearly exclusively for confidence intervals and hypothesis testing. or 5). we can compute these values for a binomial distribution.In a binomial experiment with n trials. and the F-distribution. σ = . 1. 4. consider the “experiment” of flipping a coin five times. the probability have having exactly x successes is The binomial distribution is simply the collection of all probabilities of all possible outcomes x.5. 2. can be used directly for probabilistic calculations. One major difference between discrete and continuous probability distributions is that the probability of a single value of a variable is different. but the probability corresponding to each value (still the height of bar times width of bar) is actually zero (because the “width” of the bar is now zero). chi-square distribution. variance. the “width” of the bar in the histogram is 1 unit. but the probability that the computer program chooses a number between 1 and 2 would be nonzero. probability of success p. Every real number from 0 to 5 is a valid possible result.4. I’d have you show this result. For example. 4. You may notice for certain values of p and n that the distribution can look symmetric.

5≤x≤7. Remember. p and q=1-p are for your particular problem. the binomial distribution (which. To “convert” a binomial probability distribution into a normal distribution. we have to select a probability on a range of x- values. is discrete) can be approximated as a normal distribution (which is continuous). For a normal distribution. So. as you will recall. where μ and σ are the mean and standard deviation of the distribution. when np≥5 and n(1-p)≥5 this approximation is valid. say P(6. 61 .The uniform distribution assumes that all random variables are equally likely.4. If you can’t figure out what n. which is the value halfway between the maximum and minimum. For a continuous distribution. the better. The PDF is a horizontal line.4). and mode are equal. The main advantage of making this approximation is that we can extend ideas that involve the normal distribution to discrete problems! As a general rule of thumb. the normal distribution is symmetric. This is straightforward (see Section 4. (3) Choose the value of x necessary to answer the posed question. median. μ=np and σ = . we can directly compute the probability P(x=7). the mean determines the location of the distribution’s “peak. This is probably the trickiest part because we have to keep in mind the difference between discrete and continuous probabilities. since the integral (area of the rectangle. there are four main steps: (1) Confirm that np≥5 and n(1-p)≥5. The formula for the PDF of the normal distribution is given by . and the formula for the standard normal distribution becomes .” and the standard deviation determines how “spread out” the distribution appears. we’d like to standardize and nondimensionalize the normal distribution so that we only have a standard normal distribution to worry about. A uniform distribution has a mean equal to its median. effectively) is equal to one. and its height depends on the range of random variables.3 Normal Approximation of Binomial Distribution In the case of a large enough sample size n and a particular success rate p. Further.5).1. we replace the random variable x with its z-score z. (4) Convert the x-value you chose to a z-value. As is typical in engineering. In a binomial distribution where x only takes on integer values. the mean. The normal distribution is the familiar bell curve. 4. but the large np and n(1-p) are. you might not have a binomial distribution! (2) Compute the mean and standard deviations for your binomial distribution. Essentially. and a variance equal to the square of the range divided by 12.

7. we can approximate the mean and standard deviation of the entire population! We’ll look at examples in the next section. 8. “No more than 4” means {0. “At least 4” means {4. 9. if we take n samples of a population probability distribution. then the sampling distribution of sample means is normally distributed regardless of n. 10}. 6. This distinction can be important in discrete probabilities. we can’t know the true mean and standard deviation of a population. which we will not prove. 6. 4}. The standard deviation of the sample means. the mean of the sample means.) Probability distributions make it easy to find this information. and a specific statistic of each sample is calculated we call this a sample statistic.” “exactly. “More than 4” means {5. 5. but we will certainly use. the better the approximation.” “at most. 8. is arguably one of the most important theorems in statistics. phrases like “at least. Say we are performing a binomial experiment 10 times. we call this a sampling distribution of the sample statistic. It states that If samples of size n ≥ 30 are drawn at random from any population with mean μ and standard deviation σ.5 Calculations with Probability Distributions So we can graph probability distributions. Often we are interested in computing the probability that the random variable x is greater than a certain value.4. So what? What are they good for? Well. and other times it wasn’t. because the population is too large for this to be practical. If a population is normally distributed. then the sampling distribution of sample means is approximately a normal distribution. 10}. 4. will be equal to the population mean μ.4. 7. these distinctions don’t matter 62 .” and “no more than” are important to determining our inequality. If we compute the probability distribution of a sample statistic. (Alternatively.4 The Central Limit Theorem We have established that discrete and continuous distributions are related through changing the size of the discretization of a probability distribution. or even that x is between two values. and then we can establish a widely used statistical theorem. denoted σx. 2. The larger the number n. now we can use these distributions in order to perform probabilistic calculations. 2. Notice that sometimes the value 4 was included in our set of interest. 4}. 9. We need to mention just a few more definitions. What the central limit theorem tells us is that if we randomly sample the population and compute the mean and standard deviation of that. 3.4. 1. is equal to the population standard deviation σ divided by . On the other hand. you may ask. The central limit theorem. we may want the probability that x is less than a certain value. The standard deviation of the sampling distribution of the sample means (whew!) is called the standard error. denoted μx. In either case. In terms of a discrete random variable. “Exactly 4” means {4}. Most of the time. When samples of size n are repeatedly taken from a population probability distribution. “At most 4” means {0. 1. 3. What is so important about this theorem. but we haven’t made this particularly useful yet.

9. Either the reactor is operational or not.2335 P(9) = 10C9 0. we want to know the probability that the reactor will be operational 7. The project manager chooses to observe the reactor at random times over the course of a month.7 and q = 0. and choose x = 69.790. Note that if we were asked for the probability that the reactor is operational exactly 7 times. we wanted the value for z = −0. and we want the probability that z > −0. Remark.) Example 3.33 = 0. A random number generator produces some real number between 1 and 10 such that the probability of any number between generated is the same.5438 to get 0. Remark.3.31 = 0.4.11. both np and nq are greater than 5. The project manager chooses to observe the reactor at random times over the course of the day. which is 0.583. so we can normally approximate this. nq = 3 is less than 5. every continuous variable has a zero probability of occurring.4562.6 Probability Examples Here are some examples to finally put all this information to use.5 − 70)/4. what is the probability that the reactor will be operational at least 7 times? Solution 1. What is the probability that the number is less than 5? 63 . because theoretically.in a continuous distribution.6496 So the probability is about 65%.30 = 0.7100. p = 0.5438. Since p = 0. Remark 2. We look up the value for z = 0. Those four probabilities can be computed separately. This is a binomial distribution with a large number of trials (n = 100). This is clearly a binomial distribution.1211 P(10) =10C10 0. we computed that already too–it’s about 27%.780. which means we need 1 − 0. Actually. Example 1. If he checks on the reactor 100 times in one month. this is the probability that z < −0. 54.5438 again. If he checks on the reactor 10 times in one day. and q = 0. or 10 times. 4. By the phrasing of the question.3. We compute μ = np = 70 and σ = (npq)1/2 = 4. A chemical reactor is operational 70% of the time. what is the probability that the reactor will be operational at least 70 times? Solution 2.2668 P(8) = 10C8 0.583 = −0. 8.11.0282 P(x≥ 7) = P(7) + P(8) + P(9) + P(10) = 0.7. which is 0.11.4562. Example 2.5 since we want to include all numbers greater than or equal to 70. Note that we cannot use the normal approximation in this example because n = 10. then added together.11. P(7) = 10C7 0. It is only when we consider ranges of continuous variables that we have a non-zero probability. Then our z-score is z = (69. A chemical reactor is operational 70% of the time. This is our answer.4%. (Remember that the z-table gives us the integral from z = −∞ up to the z we care about.770.32 = 0. However.11. right? So we should take 1 − 0.

**Solution 3. This is a uniform continous distribution. The range of values is 10 − 1 = 9, and the integral
**

from 1 to 10 must be 1, so the PDF is fP(x) = 1/9. Then the probability that x is less than five is 1/9(5 − 1)

= 4/9.

**Remark 3. Even though fP(x) = 1/9, the probability of a single value x occurring is zero, by same
**

application of the formula: 1/9(x − x) = 0.

Example 4. A deck of cards with face cards and aces removed is shuffled and a card is drawn at random.

What is the probability that the card has a value greater than 8?

Solution 4. This is a single event, not requiring a probability distribution. But we can still easily obtain the

answer. Our possible results are discrete, and they are 2, 3, 4, 5, 6, 7, 8, 9, and 10. Of these, only 9 and

10 are greater than 8. Since 9 and 10 are two of the nine options, the probability is 2/9.

**Remark 4. Look for the signs that a probability distribution is necessary! If it’s not explicitly mentioned,
**

or an experiment isn’t repeated, or there isn’t an infinite number of possible results, we may not need a

distribution calculation at all.

**Example 5. The “life expectancy” of a certain brand of automobile tire is normally distributed with a
**

population mean of 30000 miles and a population standard deviation of 3000 miles. What is the

probability that a tire will last less than 25000 miles? More than 33000 miles?

**Solution 5. The z-score for 25000 is (25000−30000)/3000 = −1.66. From the z-table, the probability that z
**

≤ 1.66 is 0.9515. So the probability that z ≤ −1.66 is 1 − 0.9515 = 0.0485, or about 4.9%. The z-score for

33000 is (33000 − 30000)/3000 = 1. From the z-table, the probability that z ≤ 1 is 0.8413. So the

probability that z ≥ 1 is 1 = 0.8413 = 0.1587, or about 16%.

**Remark 5a. Another way to solve this one: remember the 68-95-99.7 rule of thumb. We know that the
**

area under the normal distribution from z = −1 to z = 1 is 0.68, so the area from z = 0 to z = 1 is 0.34. The

area from z = −∞ to z = 0 is 0.5, since the distribution is symmetric about z = 0. So the area from z = −∞

to z = 1 is 0.5 + 0.34 = 0.84 (using the table, we found that it’s 0.8413). Using this rule of thumb can save

time at the cost of precision if you’re comfortable with it.

Remark 5b. We can also compute the probability that the tire will last between 25000 and 33000 miles

by taking the p-value for z = 1 and subtracting the p-value for z = −1.666.

**Example 6. The life of a particular brand of batteries can be represented with a population normal
**

distribution with mean 10 hours and standard deviation 1 hour. What battery life marks the 75th

percentile of all batteries? (What value will only 25% of batteries manage to exceed?)

**Solution 6. The p-value we care about is 0.75, which falls between 0.7486 and 0.7517, the p-values
**

corresponding to z = 0.76 and z = 0.77. So let’s say z = 0.765. Then x = zσ + μ = 10.765 hours.

**Remark 6. When we know the probability P and need the z-score, we usually have to linearly interpolate
**

it from the z-table.

Example 7. Samples of twenty-five of the batteries described in the prior problem are taken. What is the

mean and standard deviation of the life of this sample?

64

**Solution 7. By the central limit theorem, the sample means of a normal distribution are normally
**

distributed no matter what n is. In this case, n = 25. The mean is equal to the population mean, or 10

hours. The standard deviation is 1/251/2 = 0.2 hours.

**Remark 7. We could answer further questions about probability of this sample the same way as in
**

Examples 5 and 6.

**Example 8. One hundred samples of the concentration of a process reactor are taken. These samples
**

have a mean concentration of 2 moles per liter and a standard deviation of 0.01 moles per liter. What is

the mean and standard deviation of the entire reactor?

Solution 8. By the central limit theorem, the mean is 2 moles per liter. The sample standard deviation

σ/n1/2 = 0.1, so σ = 0.01(100)1/2 = 0.1 moles per liter.

65

**5 Introduction to Inferential Statistics
**

Recommended for Further Consideration:

**Sections 4.3, 5.4, 6.1, 6.2, 6.4, 7.3, and 7.4 of Navidi’s Principles of Statistics for Engineers and Scientists,
**

1st edition, or any other statistics text.

Chapter Goals

**Compute confidence intervals (error bars) for a given experimental result or statistic. Error analysis is
**

critical to virtually all experimental settings. It also communicates your understanding of experimental

results.

Create a hypothesis for a given experimental objective.

Make statistical claims related to a set of data using formal hypothesis tests. All scientific and technical

communication about experimental findings requires statistical analysis. You need to understand what

makes a claim statistically significant.

**Descriptive statistics are used to characterize existing data. Inferential statistics make use of those
**

characterizations to make statements regarding a population based on just a sample from that

population. You’ve run into inferential statistics in a variety of ways, inside and outside of science and

engineering. Opinion polls that express a “margin of error” are using similar computational methods to

scientists who are printing error bars on graphs.

If you’ve done any lab work or seen any experimental reports, you’ve probably encountered error bars

on graphs. Error bars denote the probable maximum and minimum value some computed data could

actually assume if an experiment were repeated several times. The more times a researcher successfully

completes an experiment, the smaller these error bars can become. Usually, the report will declare a

point-value estimate of a data computation and include these error bars as an interval-value estimate.

An interval is just another word for a range of values.

5.1 Confidence Intervals

**Margins of error and error bars are examples of confidence intervals. A confidence interval is a range of
**

numbers that is supposed to contain a population parameter (or, more generally, any calculated

quantity) with some predetermined accuracy. The level of confidence 1 – α is the probability that the

confidence interval contains the population parameter. Typical values for 1 – α are 0.90, 0.95, and 0.99

(meaning α is 0.1, 0.05, and 0.01, respectively, in these cases).

**Typically, when reporting experimental results, we are interested in giving a confidence interval on the
**

mean value of a particular finding. Depending on the experiment, it may also be important to compute

confidence intervals on other statistical measures – sometimes, we wish to provide a range of values for

a variation or standard deviation, and in binomial experiments, we may try to bound a proportion. For

the rest of this section, we will run through the math necessary for each of those situations.

66

per the Central Limit Theorem.645. Using this formula for E. if you have some idea of the mean and standard deviation of your data.1. For a given α.5. like x ± E. is the population mean.575.99.” it means some specific mathematical analysis was conducted. Such analysis can include comparing confidence intervals or running a hypothesis test (more on the latter in Section 5. If neither of these statements is true. The width of a confidence interval is determined by the maximum error of an estimate. though. The c-confidence interval for the population mean μ is where E is the maximum error of the estimate. x + E] or as a central value plus or minus the error. 67 . That’s helpful. This would tell you how many samples you need to take (or how many experiments you need to run) in order for your error bar to have a specified width. For Large Samples or Known Population Standard Deviation The critical value xc of a confidence interval is the value of a probability distribution such that the probability that P(−xc ≤ x ≤ xc) = 1 − α. Since the typical values for 1 − α are 0. It’s important to note here that these procedures make one very important assumption: either the variable of interest is known to be normally distributed or the number of samples taken is greater than 30. They are 1.95. We can make statistical claims on virtually anything. since the horizontal axis of this distribution is the z- score. The only distribution we’ve discussed so far for which this applies is the standard normal distribution. respectively. since the population standard deviation is virtually never known. or t. If one or the other is true. 1.9. from the distribution described in the next subsection). The probability that μ is contained within this interval is 1 − α = c. we cannot use these techniques. and 0. 0. where the critical value is denoted zc.1 Confidence Intervals on the Mean Often when you hear that something is “statistically significant. then we can. it’s helpful to remember the critical values zc for these three values. The simplest place to start. the maximum error E is the largest value between the point-value estimate and actual value of a population parameter: When n ≥ 30 we can use the sample standard deviation s instead of the population standard deviation σ. where x is the standardized measure that we’re interested in (this will either be z. from the normal distribution. you should be able to estimate n in the case you have a desired maximum error. We can write confidence intervals using a bracket notation like [x −E.96.2 and beyond). and 2.

0. we need to introduce a new probability distribution.9. 0. we need to account for the case when neither of those assumptions is true.89. and mode equal to zero. The conversions were 0. Ten samples of the conversion of a reactor with unknown population standard deviation were taken.96(0.88. we are attempting to bound the mean of the data set. Example. In statistics.02 were taken.88. we can compute the t-score for a mean ¯x by The t-distribution has many of the same properties as the standard normal distribution: it is symmetric. 0. Of course. The formula for the maximum error E is analogous to the normal case also. you must know the statistical degrees of freedom of your data.88. What is the 95% confidence interval for the population mean conversion of this reactor? Solution. 0. having zero degrees of freedom makes a problem completely defined.012. 0. It’s easy to forget this sometimes! Example. 0. The degrees of freedom for the t-distribution is simply n – 1 in this situation.88. Analogous to the normal distribution.89. 0. just replace zc with tc. Note that statistical degrees of freedom is not exactly the same as the process degrees of freedom we considered back in Chapter 1 (though they are related in spirit). However.89. This is because the normal distribution is symmetric. In chemical engineering analysis.85. The conversions were 0.898]. Since σ is known to be 0.02.87. What we are doing is finding the interval such that the area under the distribution for this interval is 1 − α and the area under the distribution on either side outside the interval is α/2.91.91.02)/(10)1/2 = 0. 68 . the confidence interval is symmetric. since it aims to characterize data using as few measures as possible). Mathematically. having zero degrees of freedom means you have as many data points as you do statistical values to classify those data points (which kind of defeats the purpose of statistics. The t-distribution (sometimes referred to as Student’s t-distribution) is the sampling distribution of sample means ¯x. not the entire data set itself. and therefore.87. The confidence interval is a range of values that should bound a specific measure of a data set.Notice that for the population mean.886±0. we can compute the standard error E directly: E = 1. there is a different t-distribution for every value of the sample size n. 0. and the area under the distribution is one. The mean ¯x of these ten values is 0. In the case of the confidence interval on the population mean. 0. Distribution of the conversions is known to be normal. we have stated that σ is known or n ≥ 30 so that the above definitions and calculations are valid. the degrees of freedom is the number of elements that must be specified for a vector to completely defined. Ten samples of the conversion of a reactor with known population standard deviation of 0.874. For Small Examples and Unknown Population Standard Deviation So far.886. median. 0. 0. 0.012 = [0.9. has a mean. and nonzero degrees of freedom gives us some room to define values (design processes). So we can say with 95% confidence that the population mean conversion is ¯x±E = 0. 0. In order to use the correct t- distribution at any given time.

confidence intervals can be computed on proportions (and therefore any measureable item where fractions come into play. This means we can say with 95% confidence that the 69 .013. tc = 2. You’d think the first people to develop this theory would have been more careful) and the sample proportion as = x/n.252.85. so E = 1.886 ± 0. n = x = 287 and n = n − x = 1024 − 287 = 737.1. n and n must be greater than 5. In a recent Gallup poll of 1024 U. So we can say with 95% confidence that the population mean conversion is ¯x ± E = 0. So now we can compute the standard error: E = 2.28 and = 1 − = 0.88. we will have to use a continuous approximation on a binomial distribution.2 (Optional) Confidence Intervals on Proportions In addition to means. we must compute s as well. we can compute the standard error in much the same way that we did for confidence intervals on the mean. So our confidence interval is ± E = [0. Find the 95% confidence interval for the population proportion of American adults who say their favorite sport is football.308]. 0.0184. adults.0184)/101/2 = 0. To align this idea with the binomial distribution. either an element of that set has the characteristic or it doesn’t. First we note that this is a binomial distribution: either football’s your favorite sport. 0. this turns out to be 0. 0. 0. Solution.96[(0. We also define the variable = 1 − .262.91. 0. yes/no. A proportion can then be thought of the fraction of a data set that exhibits a certain characteristic.72. like mass or mole fractions). In this case. Since σ is unknown. Then we compute = 287/1024 = 0. z c = 1.886. For 95% confidence.0.873.91. Remember that for a normal approximation to be valid. What is the 95% confidence interval for the population mean conversion of this reactor? Solution.028.96. 0. For 95% confidence. we could say that “success” is exhibition of the characteristic and “failure” is the lack of the characteristic. The mean ¯x of these ten values is 0. The terms “success” and “failure” are used in the same way they were in a binomial distribution. 287 said that their favorite sport was football.28)(0. true/false type characteristic means we have a binomial distribution to deal with! In order to compute a confidence interval. we have 9 degrees of freedom. so we’re good. This on/off. so Example.89. 0.899]. or it’s not. Since we have 10 samples.72)/1024]1/2=0. A confidence interval on a population proportion p is then where the error E may be rewritten making use of μ=n and σ = .88. A proportion is a measure of the amount of a set that displays a specific characteristic – typically. We (unfortunately?) denote a population proportion as p (hopefully it will be clear when p is a proportion and when it is a probability. After we have applied the normal approximation to a binomial distribution. S. 5. where now x is the number of observed successes in a sample.262(0.013 = [0.

1. but we will discuss how to measure this variation. but rather right-skewed. In order to do this. 70 . The chi-square distribution has some of the same qualities as the normal and t-distributions: namely. the confidence interval for variances is not symmetric and we can’t simply compute one error value to add and subtract from the mean variance. Since the standard deviation is just the square root of the variance. The probability that the population variance σ2 is within this interval is c. or having one box of cereal taste entirely different than the next!) We won’t discuss how to control variation. However. Here. The same procedure is used to determine confidence intervals for standard deviations. being a squared value. the measured variable x must be normally distributed.proportion of all American adults who say football is their favorite sport is somewhere between 0. the endpoints of the confidence interval for the standard deviation are just the square roots of the endpoints of the confidence interval for the variance. We would like to construct the confidence interval for a variance. A manufacturer wants to be able to produce a large number of the same thing with few to no defects or variations among them. these calculations only work when a specific assumption is valid. since that’s outside the scope of statistics (perhaps something you will discuss in process control?). Looking up values of χ2 is a little more complicated than it was for z or t due to the lack of symmetry in the distribution. and therefore the distribution is not symmetric. The chi-square distribution is used to measure population variation compared to sample variation. but the idea is still the same: we want the area under the distribution within the interval to be equal to 1 − α and we want the area on either side of the distribution in the “tails” to be α/2. 5. right and left. Because the χ2-value is not symmetric. As was the case for confidence intervals for means. The c-confidence interval for population variance σ2 is given as where the two chi-square values. In this case. the integral of the entire distribution must be one. and the degrees of freedom is equal to n − 1.252 and 0. correspond to a given degrees of freedom n-1 and confidence level c=1-α. we need to become familiar with yet another continuous probability distribution.3 Confidence Intervals on Variances Control and measurement of variance is important in manufacturing. (Imagine getting a box of screws with significantly different lengths when they’re all supposed to be the same. obviously χ2 is always positive.308.

Assuming the product weights are distributed normally.89 < σ < 1. The idea behind hypothesis testing is that we want to use statistical data from a sample of the population to make statistical statements about the entire population.798 and the right endpoint is (30 −1)(1.005. We compute the left endpoint to be (30−1)(1. In Chapter 10. 5. and taking square roots. A 90% confidence interval should signify that if you performed this experiment an infinite number of times.2)2/52.2 Single Sample Hypothesis Testing Hypothesis testing is a crucial component of both inferential statistics and experimental design.1.99.2 mg. The sample standard deviation is 1.121 = 3.798 < σ2 < 3. Then we will discuss hypothesis testing on two samples. So 0.4 Practice Problem Since we have not begun physical experiments yet. how many times did the confidence interval contain the “true” mean of 5? (What do you figure is the most probable number of times the confidence interval contains the true mean? Because of the nature of random number generation.366. so here is a demonstration.336 = 0. Hypothesis testing is used to make statistically significant quantitative claims about population parameters.121 and χ2R = 52. We randomly select and weigh thirty samples of a pain medication. we will use our ability to generate random numbers to perform a simulation instead. the area from χ2L to χ2R is 0. and a level of confidence.183. or 0.) 5. what is the 99% confidence interval for the population variance and standard deviation? Solution. Use the built-in MATLAB functions to compute the mean and standard deviation of this set of 200 numbers.99.2)2/13. The area in each tail is half of 1 − 0. 71 . Today we want to get a better idea of what exactly a confidence interval. where we compare a mean or variance to a given value. the confidence interval you compute will contain the “true” mean of the population (in this numerical experiment. and that’s okay. where we compare the means or variances of each sample and make a claim about them. Use MATLAB to do the following one hundred times (Hint: what kind of loop should you use?): Use the randn command to generate 200 random numbers of mean 5 and standard deviation 2.183. For 99% confidence. So we need to be looking in the 0.Example. so χ2L = 13. 0. that mean is 5) exactly 90% of the time. We can say with 99% confidence that σ2 and σ satisfy these inequalities. is.005 columns of the table.78. we’ll extend the idea to multiple-sample testing. Of the 100 times you performed this experiment. We have 30 − 1 = 29 degrees of freedom.995 and 0. and then compute the 90% confidence interval on the mean. your answer may not be exactly that value. First we will consider hypothesis testing on one sample.

If we can. The idea is illustrated in a couple examples below. these two examples “follow the rules” for statistical tests. this can seem a little weird. you haven’t. but ultimately do not lead to useful results. then. If you open the backpack and find your keys. and ρ ≥ k. haven’t you just proven it? The truth is. What are the null and alternative hypotheses for this situation? Solution 1. we may prove that the mean of a data set is greater than a certain value. then you know they were there. As we will see later. Imagine that you’ve lost your keys and you’re convinced your friend slipped them in your backpack as a prank and now they are just lying about it. since it does not include an equality. The null hypothesis H0 is the statement about a population parameter than includes an equality. You may ask yourself. we must explicitly declare two hypotheses: a claim and its complement. 72 . and therefore the claim that does not include an equality.” The claim we actually care about may be either the null or alternative hypothesis. This is because the point of hypothesis testing is that we will try to refute the null hypothesis (we call this rejecting the null hypothesis). But if you don’t find them. For instance. one hypothesis is effectively false and the other is true. you don’t know that they’re not there (maybe they were cleverly concealed somewhere.5 grams. For the three possible null hypotheses listed above. The alternative hypothesis Ha (some textbooks write H1) is the complement of the null hypothesis.A hypothesis test is a process that uses statistical data to make claims about parameter data. which is the claim.5 grams. Do note that I am not saying that we are “proving” anything.82. For a population parameter ρ and a test value k. This way. If a food makes this claim. Either the rate is 82% or it’s not. Hypothesis testing is a little like that. Declaration of which statement is the null one completely depends on where you can write an equals sign. and ρ < k. If you’ve never done this kind of statistical analysis before. If we cannot reject the null hypothesis (we literally call this failing to reject the null hypothesis). Example 1. the respective alternative hypotheses are ρ > k. So H0 is p = 0. A statistical hypothesis is a claim about a population parameter. or that the variances of two different data sets are equal. That makes our null hypothesis that the food has an amount greater than or equal to 0. A university claims that its four-year graduation rate is 82%. if you can’t reject the null hypothesis. possible null hypotheses are ρ ≤ k. ρ = k. what are its null and alternative hypotheses? Solution 2. In a hypothesis test. This is our alternative hypothesis. If you find that evidence. The claim is that the amount is less than 0. or you rushed and overlooked them). then the alternate hypothesis is supported by this data. Nutritional labels in the United States currently allow the reported amount of trans fats to be listed as zero grams per serving if the actual amount is less than 0.92. then we cannot reach any particular conclusion. We read H0 as “H naught” or “H sub zero” and Ha as “H sub a.5 grams. ρ ≠ k. Then Ha is p ≠ 0. You are looking for evidence to prove someone or something is wrong. Example 2.

it is .. As you decrease α. If the test statistic is beyond the critical value (that is. And statisticians have come up with names for the types of mistakes you can make.05. For means. One is noted as the claim. 3) The standardized test statistic and standardized critical value are compared. that supports the alternate). We call them errors in statistics: A type I error occurs when the null hypothesis is rejected and it actually shouldn’t be rejected.10) and perform these four steps: 1) The null hypothesis and alternative hypothesis are formulated. you generally increase β (but not linearly). The critical value is the most extreme value that the test statistic could take on in order to not reject the null hypothesis. A type II error occurs when the null hypothesis fails to be rejected and it actually should be rejected. or thanks to computers. However.05. But your finding the keys exposed them as a liar! Or say that you couldn’t find the keys when they were really there and you should have been able to find them! Both of these mistakes could happen. 0. so you simply assume one (typically α=0. We can design statistical tests to force this value to be a specific probability (typically 0. for proportions. and for variances. proportions.01. The value α is officially called the level of significance when it’s used in hypothesis testing. hypothesis testing works in roughly the same way. it is s2. By the formulation of statistical calculations. Then the test statistic that will assess the validity of the null hypothesis is calculated (if it is not already given). the maximum probability of this happening is α. it effectively separates the “rejection region” of a distribution from the “fail to reject” region. Computing the exact level of confidence or significance is complicated. or χ2-value) of the test statistic. can determine precisely the probability of a type I error. and variances. the test statistic is . 2) The standardized critical value of the test is determined based on the critical level of significance. If you find evidence. if you didn’t find the evidence. Here are the basic steps. 5. then we can statistically reject the null hypothesis (and declare that the data supports the alternate hypothesis ) for that level of significance. and its computation is too complicated for even semester-long statistics courses. 73 . that doesn’t make the thing true. For each case. We’re going to explore hypothesis tests on three population parameters: means. which is just the z-value (or t-value. let alone this one. If you fail to find the evidence. or 0. The probability of this occurring is denoted β.1. Usually you are aiming for the alternate hypothesis to be the claim (because again. or 0. 0.2. so if you can refute it. the point is to refute the null hypothesis.01). it is in the rejection region).1 Method 1: Computing a Standardized Critical Value (α is known) This method of statistical analysis is probably what you learn if you take a basic statistics class (think for business majors instead of engineers). Say that you were searching your backpack for your keys and found them. it just means you can’t prove the thing wrong.then you’ve proven the thing wrong. presented in two different ways using the same examples to show how they are related. Convert this value to its standardized test statistic. but your friend wasn’t lying – they really didn’t put them there as a prank. you fail to reject the null hypothesis. you can reject the null hypothesis.

then we can statistically reject the null hypothesis (and declare the data supports the alternative hypothesis) for the given critical level of significance. or χ2-value) of the test statistic. 2) The critical level of significance of the test is announced. which is just the z- value (or t-value. This is the maximum acceptable probability of making a “type I error” with our test. either by estimating from tables. 5. Values of the test statistics that are greater than the critical value result in a rejection of the null hypothesis (the rejection region is the area to the “right” of the critical value). 4) Interpret the result: conclude whether we reject the null hypothesis or fail to reject it. If the observed level of significance is beyond the critical value (that is. values of the test statistic that are less than the critical value correspond to a rejection of the null hypothesis (in other words. If H0 contains the ≤ symbol. we need to decide how to compute the critical value. separating the “rejection region” of a distribution from the “fail to reject” region. math) majors. but it allows for a more precise conclusion – effectively. it is in the rejection region).) and for variances. The critical value depends on the level of significance of the hypothesis and the degrees of freedom in the appropriate probability distribution. For means. This is converted to the standardized test statistic. engineering. 5.3 Statistical Computations for Hypothesis Tests: An Overview Hopefully from the above lists. The test statistic that will assess the validity of the null hypothesis is calculated (or given). rather than “yes it is” or “no it isn’t. technology. and explain what that means for the given level of significance. the only completely new and potentially complicated part is step 2. then we just compare this value to the test statistic. the probability value comes from a right-tailed test. the probability that your claim is supported. or using computer software to compute it directly. and explain what that means for the given level of significance. Once we know where this value is coming from. If H0 contains the ≥ symbol. it is s2. 4) Interpret the result: conclude whether we reject the null hypothesis or fail to reject it. Remember that basically our null hypothesis will either include a ≤. Finally. One is noted as the claim. In this case.2. or ≥ and that the result of our test will be to either reject or fail to reject this hypothesis. So let’s try and spell out exactly what’s going on. the probability value comes from a left-tailed test. the rejection region is the area to the “left” of the critical value on a number line). =. you will typically take this approach in hypothesis testing. the test statistic is .2 Method 2: Computing an Observed Level of Significance (α unknown) If you take a course in statistics designed for STEM (science. It can be a little more challenging to compute the observed α. 74 . (for proportions. 3) The critical and observed levels of significance are compared.2. it is . the test statistic is used to compute observed level of significance. In all three cases.” 1) The null hypothesis and alternative hypothesis are formulated.

After different examples for different types of tests. Finally. In this case.01. which is zc in this case.2. Test this study’s claim for α = 0. Ok. But we need to convert this to a z-score. You can crunch numbers and reject all the null hypotheses you want. This time. Example 1. Solution 1. z ≤ zc. this will make much more sense after a few examples… but we have to take it a case at a time. The claim is that the mean sleep time μ is less than 56. so z lies in the rejection region. but if you don’t conclude your test by explicitly stating what you’ve just done.01. The next step is to compare to the critical value. We reject the null hypothesis. we compute the critical value. A confidence interval computes the “fail to reject” region for the two-tailed hypothesis test! The final step is key. so it must be the alternative hypothesis. we state the hypotheses. on average. This is a left-tailed test and α = 0. the probability value comes from a two-tailed test. It states that the national average for sleep is 56 hours per week with a standard deviation of 4 hours.33. college students sleep less than the general population and the study’s claim is valid. Let’s walk through the steps: First off. So. This is the z- value where the area under the curve to the left of this point is equal to 0. we’ll compare them all and reiterate the general procedure. which corresponds to a z-value of zc = −2. We use the standard normal distribution (z-distribution) because we are dealing with a calculation about the mean with a sample size greater than 30. There is an immediate connection between this idea and the idea of confidence intervals. 75 . which means values of the test statistic that are greater than the largest critical value or less than the smaller critical value result in null hypothesis rejection (there are rejection regions on other end of the probability distribution).If H0 contains the = symbol. = 54. which is z = (54 − 56)/(4/361/2) = −3. 5. H0: μ ≥ 56 Ha: μ < 56 (claim) Secondly. our test statistic was given to us. how do we compute the critical value? We simply find the value on the appropriate probability distribution (z-distribution or t-distribution for means. then there’s really no point. This does not include an equality.4 Hypothesis Testing for a Mean Let’s start with an example and just make comments along the way.01. A study claims that the average college student sleeps fewer hours than the general public. z-distribution for proportions. chi-square distribution for variances) where the area of the rejection region is equal to α. So. We have sufficient evidence to conclude with 99% confidence that. A sample of 36 students has an average sleep time of 54 hours per week. we interpret the result.

we standardize our test statistic: t = (0. but σ is unknown and n < 30.05. A certain company suggests that use of their catalyst will keep the reaction first order.01. So. Fourth. the reason we used the t-table for this latter example is because of the sample size in our experiment. We have shown that the mean rate constant is statistically different than 0. mark one as the claim.34)/(0. but with a rate constant of 0.34 Second. so tc = 2. Again.5 (Optional) Hypothesis Testing for a Proportion Recall that we computed probabilities for proportions by approximating a binomial distribution as a normal distribution.We’ll quickly discover that the only difference between all these different hypothesis tests is how to determine the critical value. Remember that the t- test is used when the population is normal. When you list your hypotheses. we’ll use the normal distribution again. A pharmaceutical R&D technician claims that less than 20% of adults will be allergic to a new medication in testing.2.f.34 with 95% confidence.131|. We reject the null hypothesis. For hypothesis tests for the mean.34 (claim) Ha: μ ≠ 0. 5. Example. When we computed confidence intervals for proportions. We have a two-tailed test with α = 0. we state our results.05 and d.) Also.33 with a sample standard deviation s = 0.01.34 per second. the value is found by using the z- distribution (for large samples) or by using the t-distribution (for small samples). but the meaning of your result can be quite different. we use the t-distribution.131. we state the hypotheses. 76 . we compare and find |−4| ≥ |−2. Also. Here’s another example of a mean test before moving on to other tests. A certain chemical reactor is first order with a relatively low rate constant. the null hypothesis includes the equal sign and the alternative hypothesis does not. Example 2.131 in the right tail and tc = −2. so our null hypothesis must just be an equality: H0: μ = 0. which contradicts the company’s claim. so t is in the rejection region. You run sixteen trials in a batch reactor using this catalyst and find that the mean rate constant is 0. = 15. we find our critical value. Third.33 − 0. we used the normal distribution. we use the z-distribution. Test the technician’s claim for α = 0. (You can just say that |tc| = 2. Note that the claim may either be the null or alternative hypothesis.01/161/2) = −4. Solution 2. for hypothesis testing with proportions. and if it’s 30 or more.131 in the left tail. Run hypothesis testing to see if this data supports the company’s claim with α = 0. In a random sample of 100 adults. it is found that 15 are allergic to the medication. If it’s less than 30. There is no mention of something being bigger or smaller. First.

= n−1 = 14 and for the left-tailed test.95. we compute the standardized test statistic: z = ( −p)/(pq/n)1/2= (0. We’re following the same five steps repeatedly.571. so z is not in the rejection region.f. Fifth. So we compute np = 100(0. So the critical value is χ2L = 6.05. 5. As before with proportions. then the area in each of the two tails is α/2. we look in the column for α = 0. we conclude that there is not enough evidence at the 99% confidence level to support the claim that less than 20% of adults will be allergic to the medication.2 (claim) Second.2)/[(0.8) = 80 > 5. we need to first make sure that we can use the normal approximation for binomial distributions. If the test is left-tailed. then our rejection region is in the right tail. I hope that the procedure of hypothesis testing is becoming clear. Find the critical value and rejection region for a left-tailed test where n = 15 and α = 0.2 Ha: p < 0.8)/100]1/2 = −1. If the test is two-tailed. We have d. First we state our hypotheses.01.2)(0. We used the chi-square distribution to produce confidence intervals for variances. we look in the column for (1 − α) instead of α. Unlike the tests for means and proportions. and we look in the column for the given degrees of freedom and α.25.15−0. Tests for means and proportions are virtually identical. This means we can use the z-table.6 Hypothesis Testing for a Variance or Standard Deviation The hypothesis testing procedure is the same for variances and standard deviations. and the comparison between confidence intervals and hypothesis tests continues to hold. Fourth. so the critical value is zc = −2. and we use the distribution to conduct hypothesis tests for variances. so instead of doing an entire example. so we need to look in the columns for both α/2 and (1 − α)/2. we note that z > zc. We fail to reject the null hypothesis. Third.2.Solution. Find the critical values and rejection region for a two-tailed test where n = 51 and α = 0. H0: p ≥ 0. If we are conducting a right- tailed test. we’ll just focus on finding the critical values.33. 77 . the tests for variances uses a probability distribution that is not symmetric. Example 1. this is a left-tailed test with α = 0.01. That’s how proportion tests are done.2) = 20 > 5 and nq = 100(0. Example 2. Solution 1. We reject the null hypothesis if our test statistic turns out to be less than this value. where we used symmetric probability distributions. but we need to remember to check that the products np and nq are each greater than 5 before we begin.

Write the null and alternative hypothesis and identify which is the claim. respectively.2. or it may need to be computed as well. variance. we are looking for zc. or σ). So χ2L = 27.991 and χ2R = 79. Step 2. and our chi-square value of interest is χ2L (α will be close to 1). Recall that we can do confidence intervals for standard deviations by making one for variances and just taking the square roots of the endpoints. the tails in question are the rejection regions.005 and also 1 − 0. The same thing is true for hypothesis testing. the standardized test statistics are 78 . Make sure you know what α and n are.Solution 2. Find the critical value. For t-tests. we are looking for zc.f. z-tests for a proportion. = 50 and need to look in two columns for the two-tailed test.490. The nonstandardized test statistic may be given. and χ2-tests. We have d. z-tests for a mean. proportion. but n < 30 and σ is unknown.005 = 0. We split α in half and look in the column for 0.991 or greater than 79. We reject the null hypothesis if the test statistic is either less than 27. and the chi-square value of interest is χ2R (α will be close to 0). we are looking for tc with d. If we are testing for proportions and np and nq are both greater than five.f. now clustering all our options together. If we are testing for means where the population is normal. zc or tc will be negative. There are four possibilities for standardized test statistics. the two critical values for z and t-tests have opposite signs and each corresponds to α/2 instead of α. the critical values will be located in the columns for (1−α)/2 and α/2. = n − 1. Compute the standardized test statistic. or ≥ (left-tailed) symbol. = (two-tailed). we are looking for χ2.7 Hypothesis Testing Summary You should now understand how to do hypothesis testing for one sample for a mean. The hypotheses will always be about some population parameter (μ. The null hypothesis always includes the ≤ (right-tailed).490. In all cases. zc or tc will be positive. For a two-tailed test. If we are testing for variances or standard deviations and the population is normally distributed. p. Here’s that five-step procedure again. 5. If n ≥ 30 (for any distribution) or the population is normally distributed with known σ. For right-tailed tests. Step 1. σ2. For left-tailed tests.995. In the case of the χ2-test. Simply take the square root of your test statistic and critical values if you want (but note that you don’t really have to. since the inequalities will be the same either way). and standard deviation.

and whether it supports the claim or not. c) Boxes of nails are tested to confirm that the standard deviation in length is no more than 0. the standard deviation of this analysis is eight points per hour of preparation. a) Conduct all steps of a formal hypothesis test with α=0. With what level of confidence can it be said that a typical serving has less than 0. Determine the probability that the true mean pH of all such acid solutions is greater than 2.5.10 to determine whether we can claim exam scores go up at all (that is. a) The public water company states that the water contains less than 11 parts per billion of lead.50 grams of trans fats per serving.50 grams of trans fats? 3) The pH of an acid solution used to etch aluminum varies from batch to batch.25 in order for investment into its development is merited. 2) In order for a food product to be labeled as having “no trans fats. Either there is sufficient evidence to say the null hypothesis is false.45 grams per serving with a standard deviation of 0. identify the null and alternate hypotheses for each if put to a formal statistical test.1 moles per liter. the mean pH is 2. they’re the same computations we used for confidence intervals. then reject the null hypothesis.8 Practice Problems 1) For each of the following scenarios. 4) A group of 40 students were asked to report the number of hours per week they spent preparing for a chemical engineering course and comparison against course performance showed that on average. However.4% acetic acid by volume. The FCC’s brand of oatmeal cookies has been sampled 10 times and found to have an average trans fat content of 0.6 with a standard deviation of 0. If the standardized test statistic is in the rejection region (in the tail of the test).3.2. exam scores went up two points per hour of preparation. fail to reject the null hypothesis. Interpret the result. If there is.1 grams per serving. 5.01 inches. then the alternative hypothesis is probably true. d) The mean yield of a novel chemical reaction pathway must be at least 0. Otherwise. or there is not. and explain what conclusion you could reach if you were able to reject the null hypothesis. Step 4. b) A bottle of vinegar is labeled to contain 7. Say what this means in terms of the test.” it actually only must have less than 0. 79 . Compare the critical value(s) and standardized test statistic. In a sample of 20 batches. e) A chemistry lab student claims that the standard deviation in their experimental data is exactly 0. Step 3.and these should look familiar. more than zero points) per hour of preparation.

46 parts per million (ppm).4 2. A sampling of the pool’s chlorine levels at 25 random times during a month yields a standard deviation of 0. 80 .4 1.6 1.8 2 2.b) Determine the smallest possible level of significance α with which we can conclude the increase in exam score per hour of study is greater than zero. 5) A community center reports that the chlorine level in its pool has a standard deviation of 0.61 ppm: 4 3 Frequency 2 1 0 1 1.8 3 3.6 2.2 Chlorine level (ppm) Conduct a complete hypothesis test to determine the level of confidence with which we can refute the community center report.2 2.2 1.

instead. Management says they are cleared to add the label if they can prove their claim with 99% confidence.55 hours with a standard deviation of 0.For each of the following scenarios. c) Find the standardized test statistic and denote its position on the probability distribution. What can you conclude with 90% confidence? 9) FCC management would really like to brag that these paper towels are made with no more than 10% new raw materials – the rest is post-consumer recycled material. Naturally. they need to confirm their caffeine content labeling is accurate. What can you conclude with 99% confidence? (Caution: Unlike the first problem. whose caffeine content averages 39. what should be the claim so that rejecting the null hypothesis means one thing. you sent your lab technician to randomly sample 50 batteries and found the mean reserve capacity to be 1. What can you conclude with 90% confidence? 7) Recent FDA regulations require that the caffeine content of sodas be clearly labeled on each can. e) Interpret the decision in the context of the original claim.2 milligrams with a standard deviation of 7. They want to guarantee that the mean reserve capacity of their SuperLasting Battery is greater than 1.5 hours. b) Sketch or describe the rejection region for this statistical hypothesis on a probability distribution. on average the material is 9.0 mL/sec under a standardized industrial test.32 hours. However. What can you conclude? (While this should technically be treated as a test on proportions. The quality control manager for this cola sampled 30 12-ounce cans of cola. The scientists have already run a set of 40 initial tests and found that the FCC paper towels absorb at an average rate of 10. Fictitious Chemical Company has their brand of FC Cola. no one has made a claim yet! What claim is “actionable” – that is.4 mL/sec with a standard deviation of 0.6 mL/sec. do the following things as you practice formal hypothesis tests: a) Write the null and alternative hypotheses (as mathematical equalities/inequalities) and mark which one is the claim. can we statistically claim that one population has a higher mean salary than 81 . For instance. d) Decide whether to reject or fail to reject the null hypothesis. among 50 samples.5 milligrams.5% new material. To test the claim.3 Two-Sample Hypothesis Testing So far we have used hypothesis testing to compare a sample statistic to a numerical value to make a claim about a population parameter compared to this numerical value. you may do a test on the “mean” percentage. The labeling on a can of FC Cola currently claims a caffeine content of 40 milligrams per 12 ounces.) 5. and in addition to desperately needing a better name for their product. we can also run hypothesis tests to compare two sample statistics to one another to make claims about population parameters. while failing to reject it means another?) 8) The FCC’s new line of paper towels just might absorb certain liquids faster than the competition’s current rate of 10. with a standard deviation of 2%. Their brilliant scientists have somehow come up with a way to measure the amount of new raw material used in a product and find that. 6) The marketing department for FCC wants to make statistically-valid claims for a new commercial campaign for their brand of automotive batteries.

Again. The hypotheses and claims are also a little different. we substitute s for σ in the above equation. n = 100} Solution 1. so the rejection regions are z > 1. We would like to make a statistical claim about the difference between μ1 and μ2. The samples are independent. we have μ1 − μ2 = 0 and 82 . so the expression (μ1-μ2) = 0. Do the results support the scientist’s claim if α = 0. Example 1. If n is large. A scientist claims that there is a difference in the pH of tap water in two different buildings on campus. (The procedure for dependent samples is different and not covered here. or μ1 ≥ μ2. s may be used in place of σ in the above formula. which has parameters μ1 and σ1. This is a two-tailed test with a z-distribution and α = 0. as before. 5.43. The samples must be randomly selected and independent. n = 100} Building 2: { = 6. In the case of two-sample hypothesis testing. s = 1. then. First we state the hypotheses. in general. The alternative hypothesis is the opposite statement.2. which has parameters μ2 and σ2. as always. but the test statistic is computed with the following formula. This is because.another? Can we statistically claim that one product has less variance between batches than another? Can we say that statistically two population parameters are the same? Hypothesis tests work exactly the same as before. First we’ll consider large samples (n ≥ 30) or samples with known normal distribution and known standard deviation.09. μ1 = μ2. Our null hypothesis (no change hypothesis) always includes the means being the same. the computation of the standardized test statistic. The null hypothesis.5.1 Differences Between Means We are given two samples of data. the null hypothesis includes the equals sign. The only significant difference is in that most complicated step.96. Since both samples are large. while Population 2 provides Sample 2.05? Building 1: { = 6.) In this case. and since the null hypothesis always includes μ1 = μ2. we still find the critical value based on α. Also. will either be μ1 ≤ μ2.96 and z < −1. we compute the new test statistic. The results of a random survey of 100 of each building are below. s = 1.3.05. either may be the claim. Population 1 provides Sample 1. the null hypothesis is sometimes also called the “no change” or “no difference” hypothesis. H0: μ1 = μ2 Ha: μ1 ≠ μ2 (claim) Second we compute our critical values.

Third. There is not enough evidence at the 95% level to statistically claim that the pH of the water is different in the two buildings. s = 3000. Indeed. Example 2.3. You are able to obtain records of the most recent installations for two different companies. Note that the five steps of the hypothesis test are followed as usual. If they are. then the computation looks a lot like that for a large sample: (We will discuss how to compare population variances in Section 5. The hypotheses are H0: μ1 ≤ μ2 Ha: μ1 > μ2 (claim). we interpret this result. we have d. Finally. = n1 + n2 − 2 if the population variances are equal. If not. . = min{n1 − 1. Company 1: { = 127500.f. s = 4500. so we fail to reject H 0. there is a test for small sample sizes. A manufacturer says the cost of its control system installation is less than that of its competition. As you may expect by the symmetry of the last few sections of this chapter. n = 14} Company 2: { = 125000. Company 1 and Company 2. The test statistic will also depend on whether the population variances are equal. we compare and see that the test statistic is not in the rejection region. then If the population variances are not equal. n2 − 1}. the only real difference between testing on one sample and testing on two samples is that the test statistic calculation is a little more complicated. n = 16} Solution 2. 83 . With two samples. which we use test when either or both samples has n < 30. then d. Can you support the manufacturer’s claim (α = 0. Recall that the degrees of freedom in a t-test depends on the size of the sample. the hypothesis test for means of small sample sizes is slightly different and involves the t-table instead of the normal distribution table.3.05) if he comes from Company 2? Assume the variances of the samples are actually equal.f.) Let’s look at another example.

5. We compute the sample proportions for both groups: = 0. we must first check to make sure that the normal distribution approximation on a binomial distribution is valid. the only step that has changed a little is the computation of the test statistic. p=x/n). n2p2. so the rejection region is z < zc = −2. Recalling that x = np.701. We’ll compute = (301 + 357)/(4700 + 4300) = 0.073 so we can find z using the above equation: which is in the rejection region.064 and = 0. So we reject H0 and conclude that the claim is true and the medication reduced the proportion of migraines. n1p1. so we can use the normal approximation to a binomial distribution.f.01. 84 .3. The new formulation for the test statistic z is where the average proportions and (recall that for a single proportion. To use this hypothesis test on two proportions.701. so d.05. and with α = 0. The Fictitious Pharmaceutical Company is conducting a study to test the effectiveness of a new migraine medication. Once again. So we reject the null hypothesis. This is a left-tailed test with α = 0. and n2q2 are all greater than 5. Example. A control group (Group 2) of 4300 subjects took a placebo. which is in the rejection region.2 (Optional) Differences Between Proportions Much like the case of the previous two-sample tests.083.We’ll assume the variances are equal. We have enough evidence to conclude that Company 2’s mean installation cost is less than that of Company 1. the tests for the difference between two proportions is largely similar to the test on one proportion.2 = 28. we can easily tell that all values of concern are greater than 5. The hypotheses are H0: p1 ≥ p2 Ha: p1 < p2 (claim). that is. 301 reported having a migraine within the week of the study. so the rejection region is t > 1. = n1 + n2 .33. we have a right-tailed test with tc = 1. and 357 reported having a migraine within the week of the study. Of the 4700 subjects taking the medication (Group 1). Our test statistic is . n1q1. At 99% confidence. can we conclude that the medication reduced the proportion of migraines? Solution.

Example. Again. and d. with each page corresponding to a different α. the similarities between the one. the F-distribution is the represents the distribution of their ratios.10.and two-sample tests for means and proportions do not carry over to two-sample tests for variances.D. A new PID controller has been installed on a heat exchanger such that the time necessary to reach a desired temperature has a smaller variance. since there are two samples involved. we mentioned that the t-test changes depending on the assumption of equality of the variances of the samples. the variance of 10 sample runs was 144 square minutes. there are hypothesis tests for differences between variances. F-distributions are essentially presented as a three-dimensional table. the degrees of freedom of the numerator (sample 1). the degrees of freedom of the denominator (sample 2). While the probability distribution used for two-sample variance tests is new and different. F-distributions depend on the degrees of freedom of a sample. There is not enough evidence at the 90% confidence level to conclude that the new system reduces the variance in times.D = 21 − 1 = 20.44. we have two different degrees of freedom.96.f. With the new system. can we conclude that the new system statistically reduces the variance of the system? Solution. and have a mean value of roughly 1. As you can guess.f. We have α = 0. We choose s21 = 144 since it’s larger than 100. relabel your samples so that this is true) and F>1. the variance of 21 sample runs is 100 square minutes. 85 . We use a different probability distribution entirely to investigate variances. like other probability distributions. (The chi-square distribution is used for another set of hypothesis tests called “goodness of fit” tests. the formula for the F-value (the test statistic for this hypothesis test) is simply where s1>s2 (if not. always positive. but that particular test is outside the scope of this course.D. If we use α = 0. and d. Our hypotheses are H0: σ21 ≤ σ22 Ha: σ21 > σ22 (claim). Looking up this value in the F-table.3.f. Our test statistic is F = s21/s22 = 144/100 = 1. If σ21 and σ22 are the variances of two populations.f.N. Further.N = 10 − 1 = 9. In mathematical formula. which we denote d. F-distributions. So the old system is System 1 and the new system is System 2. we obtain a critical value of Fc = 1. however. With the old system. d. and d. You’ll see that F-distribution tables are printed on multiple pages.3 Differences Between Variances In the means section.10. So we fail to reject the null hypothesis. it makes up for that by simplifying the hypothesis test procedure just slightly. Unfortunately. this means F = s21/s22.f.) The F-distribution is the sampling distribution of ratios of variances. they are right-skewed. have a total integral of 1. The rejection region is F > Fc. d. Like the related chi-square distribution. which is not in the rejection region.5.f.N. since there are three values of importance: α.

1) In 2000. the EPA claimed that the average American generates at least 4. c) Find the standardized test statistic and denote its position on the probability distribution.92 g/cm3 with a standard deviation of 0.77 5.66 5. a technician tested the water hardness in 19 randomly selected streams in the greater Fictional area and found a standard deviation of 15 grains per gallon.4 Practice Problems For each of the following scenarios. which is definitely not optional. do the following things as you practice two-sample hypothesis tests: a) Write the null and alternative hypotheses (as mathematical equalities/inequalities) and mark which one is the claim.3 pounds with a standard deviation of 1. while ten samples of the new plastic have a mean density of 0.3.1 g/cm3.0 pounds of waste per day. Can you report that the standard deviation is statistically equal (with 95% confidence) to 16 grains per gallon? What is the 95% confidence interval on the population standard deviation? How are confidence intervals and hypothesis tests related? 3) The new plastic used in the FCC’s sandwich baggies must have the same density as the previous plastic in order for consumers to not detect a change in quality.69 3. e) Interpret the decision in the context of the original claim. Can you support the EPA’s claim with 95% confidence? 2) As part of a water quality survey.81 4.) 86 .08 g/cm3.93 (Technically we should probably use the hypothesis test on proportions for this problem.42 5. you found the mean waste generated per day is 4.) 4) Six plants had their carbohydrate concentrations (in wt%) measured in both the shoot and the root. You will reach the same conclusion if you use the hypothesis test on means.2 pounds.25 4. d) Decide whether to reject or fail to reject the null hypothesis.51 3. The following results were obtained. b) Sketch or describe the rejection region for this statistical hypothesis on a probability distribution. What is the probability that there is a difference in mean concentration between the shoot and the root? Plant A B C D E F Shoot Carb Concentration (wt%) 4.5.65 4. but I am holding true to those sections of the notes being optional. With what level of confidence can it be said that the two plastics have different densities? (You can assume equal variances to save some time. Twelve samples of the old plastic was found to have a mean density of 0.75 Root Carb Concentration (wt%) 3. In a random survey of 10 people.47 4.91 4.93 g/cm3 with a standard deviation of 0.

5th or 6th edition.6 Iterative Programming Applications Required Reading/Viewing: The MATLAB Data Fitting and Working with Nonlinear Equations video at http://www. Chapters 3.html . and then we see what MATLAB tools are at our disposal. often. sometimes they can be quite difficult or even impossible to find. we are also searching for the solution to the equation f(x)=0. 5-7 and 13-14 of Chapra and Canale’s Numerical Methods for Engineers. Create an iterative method to solve a nonlinear equation. then what are you doing here trying to use a numerical technique to do 87 . This chapter is broken down into a few main parts – first we explore ways to solve the system f(x)=0 in general. Solving Nonlinear Equations (about 19 minutes).3 and 5.com/academia/student_center/tutorials/computational-math-tutorial- launchpad. Of course. Appendix A. While you are certainly well versed in obtaining analytical solutions to such algebraic equations. they go through an algorithm that incorporates conditionals and loops. Chapter Goals Describe the inherent numerical error involved in computer methods. though sometimes that function is now the derivative of another function). these techniques are performed repeatedly until a specific error tolerance is met.6 in Pratap’s Getting Started with MATLAB. many cases this mathematical equation can be rearranged to be of the form f(x)=0 for some scalar or vector function f and variable x. A lot of computational techniques boil down to finding the solution to a mathematical equation numerically – and what’s more. in many.2 of Felder and Rousseau’s Elementary Principles of Chemical Processes. and so techniques have been developed to harness the power of a computer to do the tedious work for us. The true error of a numerical result is the difference between the numerical solution and analytical solution of a specific problem. In most cases. then we extend the idea to optimization problems (where.mathworks. Recommended for Further Consideration: Skim Sections 4. determining such an error is impractical – if you went through all of the work finding the analytical solution to a problem. provide a much more detailed description of both root finding and optimization problems. The common thread for both of these classes of techniques is that they are generally iterative – that is. 3rd edition provides overviews for many different numerical methods for root finding.

Use the previous solution in some computation to find a new “current” solution. Compute the new approximate error. or even keeping track of multiple error computations to make sure the error is actually decreasing with each iteration. Typically.” One sample version of pseudocode for most of these iterative methods is as follows: Start with the problem and an initial guess at the solution to the problem. 88 . expressed below. we will use the true error. we will need to use an approximate error in determining the effectiveness of our numerical procedure. In the few cases where it is possible and appropriate. More often. or the relative true error. if the error is growing with each iteration. Report the current solution as the numerical solution to the problem. Since the point of iterative methods is to get closer and closer to a final answer. Substitute the solution back into the problem to make sure the problem is truly solved. it is possible it may never be met with the current iterative procedure). In an iterative method.the same thing? True error is helpful in investigating numerical techniques. we are repeatedly refining our estimate of this value. Set the current error to some large number. We may need to keep that in mind when writing MATLAB code to solve specific problems. We keep track of the relative approximate error to inform us when to stop repeating our iterative procedure because our solution is “good enough. so we can define approximate error as the difference between our current and previous approximations. The idea is that our best estimate of the “true solution” is actually our latest approximation. to make judgments in this chapter. only the parts in italics change from method to method! Certain methods may include additional programming elements to ensure the iterative method is successfully approaching a solution to the problem. In most cases. the ideas behind iterative methods are similar to those of an informed trial-and-error procedure. each iteration is designed to get us closer and closer to the actual value. The numerical methods are devised so that they converge to a solution – that is. and our relative approximate error as Notice in our error definitions that things can get dicey if our true solution or current approximation is near zero. While the current error is greater than the desired approximate error. This may include counting the number of times a new “current” solution is found (if after hundreds of computations the desired error criterion is not met. Specify a desirable approximate error. It might be worthwhile to keep track of the error in each step of your method. Once the current error is less than or equal to the approximate error. Label the current guess at the solution as the “previous” solution. or trying simple test problems with a known solution to see exactly what is going on. then our solution is diverging (instead of converging to an answer).

1. 6. At the minimum value. difficult. f(x) is positive. If f(x) at that value is positive. for some value near the solution to the problem. and so we turn to computers to give us a numerical approximation to the solution of the problem. Say we are given a minimum and maximum bound on our function. At the maximum value. An open method. then there must be a value between there and the maximum where f(x)=0. You have probably intuitively already dealt with this kind of method before – for example playing a “high-low” game where you are trying to guess a number and you are told whether the number is higher or lower than your guess. in most cases. then we know there must be a place between the minimum and that value where the function crosses the y-axis. where the column vector b is all zeroes.1 Root-Finding Methods A root finding method is a computational procedure for solving any equation of the form In general. Likewise. (It might be the reverse.1 Closed Methods The basic idea behind a closed method is to start with a range of values and systematically reduce the width of this range until it is acceptably small. Otherwise if the sign of the function is different from the sign of the function at the maximum. then. Here. We will consider each in turn. just in the opposite way discussed here. typically the analytical solution is tedious. if f(x) at the chosen value is negative. The simplest version of a closed method is actually very much related to the “high-low” game. this equation may be for a scalar or vector value x – and in the case of a vector value x where the function f is linear. Set the chosen value as the new maximum. f(x) is negative. then. Set the chosen value as the new minimum. 89 . If the sign (+ or -) of the function is the same as the sign of the function at the maximum. but usually requires an initial “guess” at the answer before seeking a better solution. we can see from the graph that f(x) is negative.6. we are solving equations like those from Chapter 2. As is the case for problems we want to solve numerically. effectively providing a range of values for which to search for the solution. Evaluate the function at this chosen value. provides no such bound.) Next we choose a value in between the minimum and maximum. and f(x)=0. a closed method is a procedure that starts with some kind of bound on the solution. In this case. f(x) is positive. this idea will still hold. And so our first closed method is revealed. let’s assume x is a scalar value but that f(x) is a nonlinear function in x. or impossible to obtain. There are basically two classes of root-finding methods – open methods and closed methods. Choose a value between the current minimum and maximum. and for some value on the other side of the solution. If you are trying to solve the function f(x)=0.

Note that one drawback to closed methods of this type is that the function f(x) needs to pass through f(x)=0. which is actually very similar to the linear interpolation method from the last section.1.The error computation for all closed methods is generally the same: once the range of values (its maximum minus its minimum) is sufficiently small. in which case instead of solving the equation f(x)=0. Now. In the case of a function like f(x)=(x-3)2. and substituting it into g(x) to get a new current value: The major drawback for this method is that it will only work if the absolute value of dg/dx is less than 1. since the width of the range is exactly halved every time. relabeling it as your previous guess for x. In open methods. the derivative of the function is used to extrapolate to that new value instead: 90 . Often times when solving a complicated problem. the procedure can end. it requires fewer iterations than bisection to get a tight range on the solution to the problem. or for you Latin enthusiasts. these closed methods will fail because f(x) is non-negative for all values of x. the chosen value is simply the median of the minimum and maximum values.2 Open Methods The idea behind an open method is to start with an initial guess and use slightly more complicated mathematics to work toward a solution. relative approximate error is used as the error computation. you rearrange the function to find a solution to g(x)=x.4 is slightly rearranged to obtain a chosen value of The benefit of this approach is that for some functions. In bisection. The two most popular choices are bisection and linear interpolation. In that case. One straightforward method is successive substitution. but the iterative method to find the newest “current” solution can vary. One of the most popular open methods is the Newton-Raphson method. only instead of using two points to interpolate to a new value. there are multiple ways to form g(x). the “regula-falsi” method). The method then simply involves taking your current guess for x. but it can be difficult or even impossible to find a g(x) that meets this specific criterion. 6. In linear interpolation (sometimes also called the “false-position” method. the numerical equation needs to be redefined or another root-finding method must be implemented. The benefit of this approach is it is straightforward – easy to compute. the only part left to decide is which value between the current minimum and maximum to choose. the equation from the start of section 7. and also easy to tell exactly how many iterations of the procedure are necessary to obtain a solution within a desired error.

the formula looks like a rearranged version of the linear interpolation method from the last section. depending on the initial guess.One immediate drawback to this method is that the function’s derivative must be known. In a few chapters. where the linear interpolation method would break down. The main difference is that the secant method can work even if all function values are of the same sign. it pretty much is. and in truth. should they be necessary in a Newton-Raphson style procedure. you can compromise and use a numerical approximation on the derivative instead. then there is slightly less computation to do for every single iteration. If the only issue is not knowing a function’s derivative. Using part of the definition of the derivative. It is also possible. we will look at more complicated approximations to derivatives. and your formula for the new current value is This is referred to as the secant method. 91 . it’s important to build in an extra bit of code to check and make sure the error between iterations is not growing. If you look closely. Therefore. we can select some small h and get If you just let h be the difference between your previous two guesses. that the Newton-Raphson method will not find a solution.

or types that are more directly applicable to multivariable optimization methods. if that derivative is easily determined. compute the gradient of the function and then take a “step” in that direction by multiplying the gradient by some value h and adding this to the initial guess. then using the Newton-Raphson method to solve f’(x)=0 is relatively straightforward. Another option is to use an interpolation method. In ENCH 442. Using an initial guess. so I will refrain from getting too carried away with this course packet.2 (Optional Section) Optimization Methods There are basically two types of iterative procedures we can perform to find the maximum or minimum values of a function: types that are directly related to the root-finding methods of the previous section.6. Using root-finding methods to find the maximum or minimum of a function comes from the idea that at these points. we will spend more time discussing optimization methods. Something to look forward to? 92 . a quadratic interpolation method can approximate f(x) and be solved to find the x value where the interpolation function reaches its maximum or minimum. You can iterate on this procedure until further computations no longer improve your best guess for the function’s maximum or minimum. The most basic method for multivariable optimization (aside from some brute-force method like randomly guessing) uses the gradient of a function. the derivative of f(x) must be zero. Much like the linear interpolation method can approximate f(x) and be solved to find the x value where the interpolation function is zero. So.

6.3 MATLAB Exploration: Applications of Loops and Conditionals

Reminder: It’s in your best interest to read the following before coming to lab.

**Skim Sections 4.3 and 5.6 in Pratap’s Getting Started with MATLAB or Chapters 5-6 in Attaway’s
**

MATLAB: A Practical Introduction to Programming and Problem Solving.

By the end of this exploration, you should be able to…

**Write an iterative procedure to implement the bisection method with MATLAB.
**

Write an iterative procedure to implement the successive substitution method with MATLAB.

Write an anonymous function in MATLAB.

**This week we will use MATLAB to implement the iterative methods discussed earlier in this chapter of
**

the notes to solve equations of the form f(x)=0 or g(x)=x.

So far, we have just talked generally about a simple equation where x is a single scalar value. Let’s walk

through an example:

The volume of liquid in a spherical tank is given by the formula

3r h

V h 2

3

where V is the volume, h the height of water in the tank, and r the tank radius. If r=3 meters, to what

height must the tank be filled so that it holds 30 m3?

An iterative method is sort of like a “guess and check” procedure – with an initial guess (or two) for h,

we can evaluate V, and then change our guess, and see if we’re getting closer or not. In this case, there

are some obvious physical limits on h – what are they? (Hint: the tank is a sphere.)

Minimum h:

Maximum h:

And, evaluated at those extreme values, what is the volume of the liquid in the tank?

Minimum v:

Maximum v:

**Since 30 is in between those minimum and maximum values, we are in business! We can continue to
**

guess and check until we find the correct value for h.

Let’s first try by using the bisection method. If we have a “high” guess and a “low” guess that bound our

solution, first we need a formula to find the midpoint between the two:

93

And then we need to evaluate our function at that midpoint. We will redefine either our “high” value or

our “low” value with the current midpoint, depending on the value of the function at the midpoint – but

what do we do when?

We will set high = midpoint in the case that…

We will set low = midpoint in the case that…

For the bisection method, we will continue until the range of possible solutions (the difference between

“high” and “low” is acceptably small. Say, for instance, that error=high-low and

error<10^-5

So we’ll have to remember to build in our loop (for or while?) a condition to check this “error” size.

Let’s try putting it all together. Can you fill in the partially completed MATLAB code below to implement

the bisection method for this problem?

%sphericaltankvolume.m

r=3;

hlow=__?__;

hhigh=__?__;

_____?______; %hint: need to initialize the while loop condition!

**while _______?_______
**

hguess=_____?______;

v=pi*hguess^2*(3*r-hguess)/3;

if _____?_____

hhigh=hguess;

else

hlow=hguess;

end

_____?______; %hint: need to reevaluate the while loop condition!

end

disp(['The height of liquid in the tank is ',num2str(hguess),' meters'])

Remember to hit Ctrl+C from the Command Window if you find yourself stuck in an infinite loop. If all

works well, you should get a height around 2.03 meters.

94

Let’s try a more complicated problem that will require user input as it works. Read the following

problem and think about how you might try to find the velocity for the problem below (once we have

velocity, volumetric flow rate is just velocity times cross-sectional area).

**The siphon shown is fabricated from 2 in. internal diameter (i.d.) drawn aluminum tubing. The liquid is
**

water at 60°F, which has density of 1.94 slug.ft-1 and kinematic viscosity of 1.2 x 10-5 ft2.s-1. Using

MATLAB, compute the volumetric flow rate through the siphon. How sensitive is the solution to the

length of the tube?

The velocity (V) at the tube outlet is given by:

0.5

2 gz1

V

1 K ent f L L

D bend D

**where g is gravitational acceleration, z1 is the height of the water surface, Kent represents losses due
**

to the tube entrance, f is the friction factor, L/Dbend represents frictional losses due to a 180°bend,

and L/D is the ratio of length to tube diameter. The following quantities are also known:

Kent = 0.78

L = 10 ft

L/Dbend = 56

z1 = 8 ft

e/D=0.0003

f is a function of Reynolds number and tubing roughness (e/D) as given in “Figure 8.12” on the next

page.

95

96 .

.3f ft^3/s \n'.12: '). and it depends on the Reynolds number. according to the formula on the x-axis of the chart! This calls for successive substitution. fprintf('Reynolds Number = %4. we need to read it from the graph. end Q=vout*A.5. 97 . we need to know the velocity. vout) fprintf('Volumetric Flow Rate = %8. while error>0. In order to know the Reynolds number. and friction fact that satisfies our problem! % iterative. Reynolds number. The idea is that with each cycle.3e \n'. Re) fprintf('Velocity = %5.3e \n'. use it to compute the next value. Re=D*vout/visc. and so on.12 : ' ). In order to find the friction factor. Re) fnew=input (' Input the corresponding f value from Figure 8. %% Display results fprintf('==== Results ===== \n') fprintf('Reynolds Number = %4.3e \n'. f) % %% Begin while loop to iterate and find vout error=Inf. we will be closer to the true solution to the problem – a set of values for velocity.. Q) Of course. fprintf('Reynolds Number = %8.001 % Now calculate the velocity at the tube outlet vout=((2*g*z1)/(1+kent+(f*(LoverDbend+(L/D)))))^0. it’s much more likely that we would be using a computer to solve a problem that doesn’t require our constant input at each iteration.4f \n'. use that to compute the next value. we need to know the friction factor. fprintf('f = %8. fprintf('f = %8.3f ft/s \n'. Reguess) f=input ('Input the corresponding f value from Figure 8. We need to guess an initial value somewhere. I’ll give you some practice problems to address this.m % MATLAB Iterative Solutions Lab Exercise % %% First define all known parameters % . f=fnew.In order to compute the velocity.4f \n'. % (you need to fill this part in – watch your units!) % %% Guess initial value of Reynolds Number & find "f" Reguess=input ('Input a guess for the Reynolds number: '). fnew) error=abs(fnew-f).

Sometimes in MATLAB we want to use a simple custom function repeatedly in a numerical method (like the Newton-Raphson or secant methods). in the spherical tank problem. You can then evaluate the volume for any combinations of n. The notation is as follows: anonymousfunction=@(inputs)function_using_inputs. T.*T. MATLAB has two functions. >> idealV(1.273. would simply become v=volume(hguess). Used properly. and P. we first want to transform it into an equation f(x)=0: 98 .P)n./P. For example. Like the name implies. as long as this anonymous function is declared somewhere before the while loop of our bisection method problem.08206.One other item to look at this week is the anonymous function. MATLAB will return a value of the independent variable that sets the function equal to zero. volume=@(h) pi*h^2*(3*r-h)/3 Then. But rather than spend the time it takes to open a new editor and the space it takes to save a dinky one-line function file. The syntax for fzero requires a function and an initial guess. anonymous functions can save a lot of time and prevent unnecessary errors.*0. you can build that function directly into the Command Window or script you are currently using. that were created specifically to solve equations of the form f(x)=0. The line we wrote before v=pi*hguess^2*(3*r-hguess)/3.4024 The nice thing about anonymous functions is that MATLAB has a number of built in functions that accept them as inputs. Consider this rearrangement of the ideal gas law: idealV=@(n. Taking one final look at our spherical tank problem. Note that you must enter them in the same order you declared them in the function. we could evaluate v(h) directly in MATLAB. This function is nothing complicated and can be written in one line of MATLAB code. It’s also possible to write anonymous functions with multiple inputs. While we are talking about root solving.1) ans = 22. fzero and fsolve.T. we could have written a simple anonymous function to compute v: r=3.

then you must pose the problem as a vector problem and use fsolve. >> Vtarget=30. 3r h h 2 V 0 3 Hopefully that wasn’t a stretch. 99 . you can bound the problem like we did ourselves. >> fzero(Vfunc.0269 If you want. If you have multiple unknowns.0269 The fzero command works only for scalar equations.1) ans = 2. But then we can write this as an anonymous function in h and give MATLAB a guess to solve it: >> r=3. MATLAB will then know you are looking for an answer between the upper and lower bound: >> fzero(Vfunc. Check the MATLAB documentation for more information.[0 6]) ans = 2. instead of putting in a single initial guess. >> Vfunc=@(h)pi*h^2*(3*r-h)/3-Vtarget.

6 kg/m3. viscosity 0. ρp and ρf are the densities of the particle and fluid.893 Pa·s) in a centrifugal separator. r is the particle radius.1 Practice Problems 1) Write a MATLAB Program to solve for the terminal velocity of coal particles (specific gravity 1. 100 . When the separator is running. Perry’s Chemical Engineer’s Handbook reports the following piecewise relationship: for for for for The formula for the Reynolds number using the notation established in this problem statement is where μ is the viscosity of the fluid (please report the units you used for the value in your report). g the gravitational acceleration. and in the conclusion. comment briefly on your computer code.) The drag coefficient is a function of the Reynolds number. In the results section. reiterate the problem and its solution. For a spherical particle at terminal velocity. diameter = 0. For this problem. the gravitational acceleration is thirty times the acceleration due to gravity at sea level. (In your report. one for estimate of velocity) including all the iterations performed in a successive substitution method until you are able to compute the velocity to the nearest mm/s. The terminal velocity of a spherical particle is given by where vt is the terminal velocity.8.6. respectively.208 mm) in water (density 994. generate a two-column table (one for iteration number. and C D is the dimensionless drag coefficient. please also specify the units for the values you used for these terms.3.

or the secant method to solve for R for fractional conversions of X from 0. so you offer to solve the equation for him by writing a MATLAB script that implements an iterative root finding method.) Then compare your results to those from using fsolve directly in MATLAB. (Tip: not all root-finding methods are created equal! Some are much faster to run than others. If your results are not in agreement (within some reasonable tolerance or numerical error of your choosing). 101 . The reactor achieves a particularly low conversion. You remember fondly your days in ENCH 215 and propose recycling the unreacted material. For this particular reactor the best choice for the recycle fraction is related to the desired outlet conversion X through this function: Your supervisor has no idea what to do with this. mixed with fresh feed. so of its outlet a fraction R will be recycled.2) After your brilliant work figuring out the reaction rate for the bioreactor. such as bisection. the division supervisor asks you to take a look at another reactor they are trying to make run more effectively. so all he writes is The reactor is achieving a particularly low conversion.01.95 in increments of 0. This engineer is not particularly great at communication. adjust your “stopping criterion” in your iterative method until they are. regardless of what temperature or feed is supplied.85 to 0. So impressed with your intuition. and run through the reactor again. linear interpolation. the supervisor tasks another engineer with crunching some numbers to determine the relationship between recycle rate and overall system conversion.

7 Curve Fitting Required Reading/Viewing: Chapter 12 of the free version of the MATLAB Interactive Tutorial published by Mathworks at http://www. Recommended for Further Consideration: Section 5. y). The MATLAB Data Fitting and Working with Nonlinear Equations videos at http://www. 7. 1st edition. supplies further discussion and practice problems for material.2 in Pratap’s Getting Started with MATLAB or Section 15. Being able to do this for any kind of equation requires an understanding of more linear algebra concepts. Chapters 2 and 8 of Navidi’s Principles of Statistics for Engineers and Scientists. which we may write as ordered pairs (x. but allows you to create “best-fit” curves and understand the error involved. Regression and interpolation both have their places in engineering and experimental design.mathworks.html . Construct a regression line for a set of data.mathworks. Being able to interpolate data is critical to your ability to read data from tables or estimate unknown values for a sparse data set. We say that x and y are positively correlated if y increases with increasing x and they are negatively correlated if y decreases with increasing x.com/academia/student_center/tutorials/mltutorial_launchpad. Use regression and interpolation appropriately for a given situation. 3rd edition provides a very brief overview for finding the least-squares linear fit to data. 102 . provide a much more detailed description of the material covered here in Sections 7. Chapter Goals Communicate the meanings of correlation and causation.1 Correlation and Causation A correlation is a relationship between two variables x (independent) and y (dependent). 5th or 6th edition. Chapters 17-18 of Chapra and Canale’s Numerical Methods for Engineers.1 in Attaway’s MATLAB: A Practical Introduction to Programming and Problem Solving.html.com/academia/student_center/tutorials/computational-math-tutorial- launchpad. Construct an interpolating spline for a set of data.4. Appendix A. Know when to use which method.3 through 7. Understanding these concepts is important to making valid statements on sets of data.1 of Felder and Rousseau’s Elementary Principles of Chemical Processes. Introduction to Data Fitting and Working with Nonlinear Equations and Data-Driven Models (about 29 minutes).

The correlation coefficient is always between −1 and 1. The closer |r| is to 1. We could say that the independent variable x causes y. y causes x.) Ha: ρ ≠ 0 (There is a significant correlation. the prices of corn and the prices of dairy products are positively correlated and have a cause-and-effect relationship. 7. The population correlation coefficient is denoted ρ. it’s possible that two variables could be correlated and have no cause-and-effect relationship. but there is no cause-and-effect relationship there (gas isn’t more expensive because you are older. Either x causes y. is different than a “good linear fit”). but different people have different opinions on the matter. Now. But first. or x and y are just coincidentally correlated. and a negative sign suggests a negative correlation. you’ve probably heard rules of thumb about good R2 values. The average annual price of gasoline and your age in years are positively correlated. also. like CO2 concentration in the atmosphere and the average temperature of the earth. one more definition. and it is two-tailed: H0: ρ = 0 (There is no significant correlation. could have a cause-and-effect relationship. Other correlated data.1 Practice Problem Brainstorm at least five other example of pairwise data where one variable is correlated to the other. please note. If you’ve worked with R2 values in the past. For example. Causation (or causality) is a term used to denote a directional relationship between two variables.The sample correlation coefficient r is a measure of the “strength” (likeliness) and “direction” (positive or negative) of a linear relationship between x and y.) Note that by the formulation of this hypothesis test. It does not “prove” that the population parameter ρ is close to 1. y). but one variable is not caused by the other. 103 . We will consider just one type of hypothesis test. however weakly or strongly.2 Hypothesis Testing for the Regression Coefficient Remember that hypothesis tests deal with the population parameter (here. There are basically four possibilities for correlated data (x. some third variable (or combination of a bunch of variables) cause both x and y. ρ) based on the sample statistic (r). Its formula is where n is the number of data pairs. the “stronger” the correlation. however. we can apply hypothesis tests to determine precisely what r (or R2) value is “good enough” to claim correlation (which. but it allows us to make a statistically significant claim that the variables are correlated. Naturally. 7. rejecting the null hypothesis means that it’s extremely likely that the population parameter ρ is not zero.1. The R2 value provided by trendlines in Excel and MATLAB is the square of the correlation coefficient r. and you are not older because gas is more expensive).

the less often you’ll actually find a regression for it. it’s theoretically possible to find least-squares regression for an infinite variety of different functions. including combinations of polynomials.3 Regression Regression is one of two major classes of curve-fitting techniques (the other. [I mean to put a graphic here eventually. but it aims to minimize the error between the function and all points in a data set. so we’ll get back to that thought a bit later this chapter.4). In this section.. yi) is the difference between its measured value and its fitted function’s value: And we are seeking the parameters of commonly known functions (for example. to characterize the data).For this hypothesis test.f. we are finding the parameters for a given function that result in the smallest value for the square of the residuals. the residual e i for a given data point (xi.” It only helps to show whether the data is correlated at all or not. a slope and an intercept. 7. The regression work in this class will be least-squares regression. though. The critical value is found same as always using α and d. we’ll quickly look at the most basic functions with which to perform regressions – polynomials. A stronger hypothesis test is to declare what the exactly value of the slope of a regression line is – this is a detail that requires knowing what the variance of the slope is. coefficients of polynomials) that result in the smallest sum of squared residuals. interpolation. However. I want to stress that this test does not tell us if the linear fit for the data is “good. I’ll draw what I mean in class. = n − 2. Typically. we use the t-distribution with n − 2 degrees of freedom (why n-2 and not n-1 like other uses of t-testing? Because linear regression uses two parameters. then we reject H0. and trigonometric functions. In a least-squares fit of a function to a data set. The aim of regression is to find a defined continuous function that represents a set of discrete data. is considered in Section 7.] For a regression function y=f(x).. the more complicated the function. exponents and logarithms. then. The test statistic is If the test statistic t is in the rejection region (remember this is a two-tailed test). 104 . that the value of r or R2 that is “acceptable” to show a correlation depends on the number of data points. where x may be a scalar or a vector value. We can also note. This function may not pass directly through the points in a discrete data set. Once more. or the errors between the function value and the given data set.

) This gives us two equations and two unknowns to solve for! Using a few identities having to do with summations. which means it passes through one critical point (where the derivative of the function with respect to ai is zero). we can rewrite these two equations as 105 . corresponding to its minimum value. but we can factor that out of the sum. we are solving for the values of a 0 and a1 where (Notice that we had to use the chain rule to take the derivatives – the xi outside the parentheses in the second equation is the derivative of a1xi.) To minimize the sum of squared residuals (SSR). So. SSR is a quadratic function in both cases. A line has two parameters: its slope and intercept. we need to express this value algebraically. You have almost certainly encountered this kind of curve fitting before – it is exactly what is performed when you add a “trendline” to data in Microsoft Excel. effectively. The linear least-squares fit for a set of data is the line that minimizes the sum of the squares of the residuals of the data.7. One way to write this sum is In order to find the parameters a0 and a1 that minimize the SSR. we need to temporarily think about this sum as a “function” of those very parameters. in both cases. We will define our general linear least-squares fit as where a0 is effectively the y-intercept of the line and a1 is its slope.3. a negative one appears. (We will use a-values with numerical subscripts instead of the usual b and m in order to extend this idea to higher-order polynomials in the next section.1 Linear Regression The most basic polynomial is that of a line.

so to make it more general. a second way of computing this coefficient is where TSS is the total sum of square error of the dependent variable (y.1. Sometimes any r2 value that allows us to make a statistical claim about the linear dependence of the data (see the previous section) is “good enough. Especially as we begin to look at more complicated regression formulas. 0.9. it should become apparent that there is usually no reason to strive for a certain r2-value. it depends on your specific application. 106 . One important note about the coefficient of determination is not to rely on it to make unwarranted claims. The major drawback to the above equation is that it is specific to linear regressions. You can enter the appropriate values for the sums of the data values and solve this 2×2 linear system. If the regression equation represents zero improvement in describing the data (versus just using the mean value). In fact. 0.” Other times. The formula that is most convenient for computational methods was given in Section 7. but may be more convenient in some cases if expressed as on the right: Formulas for the coefficient of determination are pretty easy to implement with a spreadsheet or computer code that makes use of built-in sum commands or loops.95. then r 2 is 0. seeing r2-values of exactly 1 may simply be an indication that you have as many data points as you do parameters (a straight line will always connect two points! A quadratic equation will always connect three points!). There is no hard and fast rule for what value of r2 is good enough. This means that the regression equation explains 100% of the variation in the data.99. but this exact problem appears often enough that the solution is already widely known algebraically in multiple forms: There are two main ways to describe the error associated with a regression line. or even 0. in this case) – that is. we may seek specific coefficients of determination – say those that are greater than 0.These are sometimes referred to as the normal equations. the value of r2 is 1.8. The one you are probably already familiar with is the R-squared value. more formally called the coefficient of determination. because the SSR is zero. the sum of squared differences between each point and the mean: If the regression equation is a perfect fit.

The standard error of a regression function is analogous to the standard deviation of a data set. The quantity n-m-1 represents the degrees of freedom of the regression – it is the number of data points minus the number of parameters we are fitting the data to. more on that in a little bit. because we can use the standard error in part to determine which independent variables are the most significant contributors to the regression. we can also approximate the standard deviations on the parameters using the following formulas: Before we move on to more complicated regression equations. is a sort of measure of the “spread” of the data around the regression function. below. Table 1: Common Linearizations in Chemical Engineering Systems Original Equation Linearized Version 107 . then. but m represents the dimension of the independent variable vector x. but you may encounter many more examples. we have only considered the case m+1=2. we should consider the idea that many regression equations can be transformed into linear equations – especially if those regression equations have only two parameters. Recall that the standard deviation is a measure of the “spread” of the data around the mean. n is still the number of data points. but for a simple case of one independent variable (x) and one dependent variable (y) related by the expression y=a0+a1x. You have seen some of this already in your work plotting data on semi-log and log-log data. Currently. We’ll have to stick to this general way of computing the standard error for generic linear regressions. The standard error. So. Here.Another measure of the “goodness of fit” for a regression equation is the standard error of the estimate. Some examples of common “linearizations” in chemical engineering include those in Table 1. meaning the regression function has two parameters (a slope and intercept). This value becomes more important in the case of multiple regression.

as long as we are not trying to extrapolate out of the range of our data. Consider an example from back in your ENES 101 and/or ENME 110 days. The c=100(1-α)% confidence intervals on a0 and a1 are where the critical value tc is chosen assuming a two-tailed distribution (so divide α by 2) and n-2 degrees of freedom. That means you can also compute confidence intervals on regression parameters. the same way you would for confidence intervals on the mean. is the calculation of the test statistic: where a00 is the numerical value you are comparing a0 to. but the standard deviation of those regression parameters. it can be computed with the formula where When it comes to hypothesis testing.3. The only step that is slightly different.2 Confidence Intervals and Hypothesis Testing on Linear Regression Parameters In the previous section. We can also compute the confidence interval on a predicted response. once again. the procedure for regression parameters is exactly the same as it is for one-sample hypothesis testing on the mean. when you are seeking to find the Hooke’s Law constant for a spring or a beam. 108 . The formulas are almost the same as before. The object is subject to a weight w and the length of the beam d is measured.7. The data is in Table 2. Let’s check out an example. I gave you some formulas to compute not just the regression parameters for a linear regression. except the standard deviation calculations already have sample size built into them. If we want the c=100(1-α)% confidence interval on the quantity a0+a1x.

19 2.80 Assuming d=a0+a1w and applying the equations from Section 7.6 5.: Measured Lengths of a Beam Under a Load Weight Length (in) Weight Length (in) Weight Length (in) Weight Length (in) (lbf) (lbf) (lbf) (lbf) 0.0 5.Table 2.46 2.68 0.59 0.6 5.61 0.8 5.0 5. those standard deviations on the regression parameters: The 95% confidence interval on the spring constant a1 would be The 95% confidence interval on the length of the beam subject to a load of 1.40 3.2 5.8 5.47 3.1.01 1.61 3.8 5.2 5.6 5.06 1.4 5.25 2.24 2.13 1.8 5.14 1.16 2.12 1.6 5.4 5.2 5.75 0.57 3.2 5.4 5.3. The standard deviations on a1 and a0 are given after we compute the correlation coefficient and the standard error of the estimate: Now.4 lbf would be 109 .0 5.4 5.0 5.53 3.

The idea behind polynomial regression extends directly from what brought us linear regression. 7.5 we will apply a more useful theory that does the work in this section in a better way. if we so desire.1 and α=0. we could conduct a one-sample hypothesis test on a regression parameter. and rearranging them to a linear system. You may be able to detect a pattern that is starting to emerge: 110 .Finally. I can – and will – expect you to be able to do polynomial regression. we know this is between α=0. so it is like that we fail to reject the null hypothesis and cannot support the manufacturer’s claim at a reasonable level of confidence.25 (or we could use MATLAB or Excel to get the exact value). I just would rather you use the technique from that later section.3. The test statistic would be If we look at the Critical t-value table. Let’s first simply add a quadratic term to our regression equation: Now our sum of squared residuals is and we can once again write normal equations after finding the derivatives of SSR with respect to the three fitting parameters ai. setting them equal to zero.3 (Optional-ish) Polynomial Regression The reason this section is “kind of” optional is that in Section 7. Say a manufacturer claims that the spring constant of this beam is at least 0.3.215 in/lbf.

we can apply some linear algebra theory to give us a general guideline to find the least-squares fit for any regression formula – one that is relatively easy to complete using MATLAB. It is possible that being off by even a tiny percent in one data point could completely change the least-squares polynomial fit to a set of data. The same formulas for the sum of squared residuals.5 we will apply a more useful theory that does the work in this section in a better way. Multiple regression still seeks to find the “best fit” equation for a set of data y=f(x).3. More importantly. but there are three reasons that we’ll stop right here: We seek regression equations of higher-order polynomials much less often than we do for linear equations. and standard error of the estimate apply for polynomial regression. There is a more effective way to summarize all least-squares regression equations that will account for higher-order polynomials and more complicated functions. to boot! 111 . I can – and will – expect you to be able to do multiple regression. extending this idea to cubic polynomials and beyond. TSS. the matrix that results from our system of linear equations is growing in condition number. except instead of having a scalar value. total sum of squares.4 that solutions to ill-conditioned matrix equations are extremely sensitive to measurement error.4 (Optional-ish) Multiple Linear Regression The reason this section is “kind of” optional is that in Section 7. it’s possible that these equations will get more ill-conditioned as we allow for larger vectors x. Fortunately. our regression equation becomes Now each data point consists of three values: two independent variables x1 and x2. Recall from Section 2. Much like polynomial regression. We could keep going. We can set up an appropriate matrix equation and solve it for these values.3. For a vector of length 2. and sy/x. but the normal equations for this case are Once again. x can now be a vector. plus the dependent variable y. because there is a different x1 and x2 value for each data point.We have three equations with three unknowns (our fitting parameters). the same formulas apply for SSR. Note that m is equal to the order of the polynomial. The subscripts in our general problem formulation get a little messy here. I just would rather you use the technique from that later section. 7.

Now representing everything as vectors and matrices.yi) provides one equation of the form and if we collect all those equations inside a matrix. f2=x2. The only requirement of the theory that follows here is that your regression equation be of the form listed at the start of this section – that is. the normal equations are 112 . we have so we can write the sum of square residuals (differences between what’s predicted by the least-squares fit and the actual data points) as The solution that minimizes SSR.7. We can generalize our formula for the sum of squared residuals by first writing a matrix equation that captures all of our data. but y is a scalar.5 General Linear Least Squares Theory The three kinds of regression equations we have considered so far are all specific cases of this more general regression function: where. Then we are simply trying to find the values for the parameters ai that minimizes the sum of squared residuals. f2=x2.…fm=xm The functions fi can simply be any function of your independent variable(s) x that you believe are important to your fitted curve. m+1 is the number of parameters necessary to describe the regression function.…fm=xm Multiple Linear Length of vector x f0=1. keeping consistent to this section. is the solution to the normal equations. f1=x. using Y to represent the vector of y-data.3. it is a linear combination of your functions. f1=x Polynomial Order of polynomial f0=1. Each set of data (xi. f1=x. Note that x may be a scalar or a vector variable. Z to represent the matrix of function evaluations. Table 3 shows how our prior three sections fit into this general formulation: Table 3: Comparison of Least Squares Regression Cases Regression m Functions Linear 1 f0=1. same as before. and A to represent the vector of parameters.

the slope) and the sample variance is computed as above. The elements on the diagonal of this matrix correspond to the variances on the regression parameters: where sy/x is the standard error of the estimate from before. we just multiply by the inverse of ZTZ to get the final result: Whew! That is a lot of math in a short amount of space. so to solve for A in this matrix equation. also. so it’s only our responsibility to understand the final result. This equation is in the same form as our examples from linear algebra. If you need to apply a level of confidence to the slope or intercept of a line. 113 .e. The matrix (ZTZ)-1 is a very useful matrix for understanding our regression equation and how well it fits the data. the more dependent the two parameters are on one another. The larger the covariance. and some practice problems. The degrees of freedom is n-m-1.. The covariance of parameter ai-1 and aj-1 is MATLAB and Excel both have some built in tools to help with all of these computations. If the covariance for two parameters is zero.where a superscript T represents the transpose of a matrix – the result if you were to write all the columns of Z as rows of Z instead. and it can be potentially confusing if this is your first foray into linear algebra. The covariance is a statistic that describes the dependency of one value on another. it means that the parameters are completely independent from one another (and it may be important for both parameters to exist in your regression). The off-diagonal elements of (ZTZ)-1 are related to the covariances of the regression parameters. as we’ll explore through the upcoming exploration. These variances are necessary to perform a hypothesis test or to compute confidence intervals on regression parameters for regressions more complicated than linear ones. you are doing a test on data whose sample mean value is the parameter of interest (i. Fortunately it’s really easy to make MATLAB do all this hard work for us.

1 9. because you were comparing your experimental results from last time to the literature2: Dissolved oxygen concentrations in mg/L for various temperatures and chloride concentrations T.03 8.7.4 5 12.1 9.) (c) Use your regression to estimate the concentration of dissolved oxygen in water with chloride ion concentration 5 g/L and temperature 17°C. So they set out to do some experiments and obtained the following results: Temperature (°C) 0 5 10 15 20 25 30 Solubility (mg/L) 14.4 Plot the data to confirm that it looks linear enough.6 Practice Problems 1) While working on the SuperLasting Battery.0 8. degrees Celsius 0 g/L chloride 10 g/L chloride 20 g/L chloride 0 14. the researchers at Fictitious Chemical Company realized they were accidentally hydrolyzing water from a solution. and give them an appropriate regression formula for the solubility of oxygen in water as a function of temperature. 2 Chapra and Canale.09 8. you need to know the maximum solubility of oxygen in salt water at different chloride concentrations and temperatures.” 5th edition 114 . but you could also write a brief m-file and publish it.56 6.9 11.8 11.1 8.6 12.17 7.35 25 8.20 You should derive a predictive equation for dissolved oxygen concentration in water as a function of temperature and chloride concentration based on the data table you have.3 10.46 6.8 12. You just so happen to have a table of that data in front of you.3 10.2 7. (a) Write out the regression problem in the form of an overdetermined linear system.08 20 9. (b) Use MATLAB to solve this linear system with the backslash operator.9 11.85 6. One piece of information they are interested in obtaining is a relationship between the temperature of water and the solubility of oxygen in it. (Show your work so they can follow it!) 2) For a project. Print out your work.73 30 7.3 10 11. “Numerical Methods for Engineers.3. which lead them to consider other applications of their work.3 10.26 7. (The easiest way is to do this problem entirely in the Command Window and print out your results from there.96 15 10.

But the model isn’t even linear.6 8.5 2. “Numerical Methods for Engineers.9 To see if you have the right model. After explaining the situation to you.1 2.” 5th edition 115 .8 1. find the fitting parameters α0 and α1.5 0.4 5. so you’ll have to find a way to linearize it first! You are asked to report back to the supervisor with your findings: (a) What are the values of kmax and cs that minimize the sum of squared residuals for this data? Don’t forget the units! (b) What is the correlation coefficient for this model once you have processed the data so that the reaction rate constant is part of a linear equation? Statistically determine whether this processed data is truly linear with a formal hypothesis test. 4) A child’s systolic blood pressure P (in mmHg) and weight w (in lbf) are approximately correlated by the equation For the data below. 3) The bioreactor that you helped investigate on your first day of work for Fictitious Chemical is not working as expected. They come back to you with the following data: c (mg/L) 0.5 4 -1 k (day ) 1. and estimate the systolic blood pressure of a child weighing 100 pounds. you realize that the mathematical model they are using to simulate the growth of algae is nonsensical. so you propose a new model for the reaction rate constant3: k max c 2 k cs c 2 In order to verify that this is the correct model. and the supervisor of the division has come to you for help.3 7. w (lbf) 44 61 81 113 131 P (mmHg) 91 98 103 110 112 3 Chapra and Canale. you’ll have to figure out how to determine the coefficient of correlation for this model. you ask the biochemists over in research and development to put different concentrations of algae in five test tubes and determine the reaction rate constant for those samples.

58 2.32 a) Write out this regression problem in the form of an overdetermined linear system.5) The FCC Finance division has determined that a good approximation for the manufacturing costs (less fixed expenses) for a specific product is of the form where x is the “sales level” (dimensionless) reported by Marketing. you’ll need the 100(1-α)% confidence interval for the quantity a0+a1x. with the temperature T (in degrees Celsius) and percent yield y recorded each time. The sales level and manufacturing costs from different times in the past year are in the table below. 6) A chemical reaction is run 12 times.5 2.1 3.4 3. x (dimensionless) 4 6 8 10 12 14 16 18 c (thousands of dollars) 1. Publish your work. Plot a graph of the eight data points together with the regression curve.8 4. b) Use MATLAB to solve this linear system. The summary statistics are as follows: The model of a linear regression equation would be y=a0+a1T. Compute the least-squares estimate for a0 and a1.8 3.08 2. To do that last part. the standard error of the estimate sy/T. and the 95% confidence interval on the mean yield at a temperature of 40°C. the 95% confidence intervals on a0 and a1. given by the formula where 116 .

t (seconds) 0.1 0. velocity. (Hint: think back to the equations of motion from first-semester physics.8 0. Explain the units on each parameter ai. c) Use MATLAB to find the general linear least squares regression parameters for this experiment.0. the object is released from rest and its distance from the top of the plane (in meters) is measured every 0.95 It is desired to fit this data to the model h=a0+a1t+a2t2. The data for these lakes is below: Lake x t1 t2 t3 1 730 152 198 91 2 760 173 201 81 3 850 166 202 69 4 840 161 202 72 5 720 152 198 91 6 730 153 205 91 7 840 166 204 70 8 730 157 204 90 9 650 136 172 47 10 850 142 218 59 11 740 151 207 88 12 720 145 209 60 13 710 147 190 63 (a) Fit the model to the equation x=a0+a1t1+a2t2+a3t3.7) In an experiment to estimate the acceleration of an object down a ramp.46 1.9 1.) b) Write the overdetermined matrix system Za=y whose solution vector a are the fitting parameters. The mean data are presented in the following table. 8) It is hypothesized that the thickness of lake ice in millimeters (x) in winter is a function of the number of days per year of ice cover (t1).. the number of days the bottom of the lake has a temperature below 8°C (t2).89 2.0 h (meters) 0.27 0.2 0.7 0.4 0. Interpret your results.1 to t=1.3 0. (b) For the fourth fitting parameter a3.39 2. a) Explain the physical relevance of the three fitting parameters in terms of position. 117 .07 1. find the observed level of significance for testing the null hypothesis that the parameter is equal to zero.47 0.5 0.. Find the 95% confidence interval on a2 and interpret this result.1 seconds from t=0.73 1.10 0. and acceleration.6 0. and the average snow depth in millimeters (t3) for a set of lakes in Minnesota.03 0.

40 4.78 (a) Explicitly use the equations at the top of page 106 in the Course Packet to determine the slope.09 1. define the “Z matrix” and “y vector”) to solve for the unknown coefficients in your regression equation. 118 . (c) Conduct the hypothesis test on correlation to determine the level of confidence with which we can say there is any linear correlation at all between these two variables.02 2. Weight (lb) 5890 5340 6500 4800 5940 5600 5100 5850 Variability in braking distance (ft) 2.) Measurements for several individuals are given in the table below. Be sure that your work can be clearly followed – it’s not sufficient to just print out a plot or even a spreadsheet of values (unless this spreadsheet makes it clear how each computation happens).31 2.92 2.09 2. H (cm) 182 180 179 187 189 194 195 193 200 M (kg) 74 88 94 78 84 98 76 86 96 A (m2) 1.88 2.H).11 2. 10) On average. intercept.15 2. each raised to a certain (unknown) power.72 2.92 2. (b) Confirm your results using either the built-in functions or plotting tools in Microsoft Excel. (This product is also multiplied by some unknown constant.53 2.16 2. (b) Transform this nonlinear equation into a linear one and apply General Linear Least Squares theory (that is. the surface area A of an individual person is related to the product of their mass M and height H. 9) The weights of eight vehicles and their variability in braking distances when stopping on a wet surface are presented in the table below. no matter how weak it may be.02 2.31 (a) Propose the form of the nonlinear regression equation A=f(M. Be sure to correctly select the independent and dependent variables. and R2 value of the linear regression of this data.32 2.

That’s the approximation for the first derivative of a function (and this interpolating function is starting to look a lot like a Taylor series!).y1).y0) and (x1.y0). The giant fraction in the last term of the quadratic polynomial is the second finite divided difference. we write f(x)…? Ah. and (x2. Interpolation is a useful skill to have when data is limited but you would like to estimate a value based on what data you already have. for two data points (x0. interpolation often aims to find a specific data value given the existing data set. the fraction above is the first finite divided difference of a function. The most common methods of interpolation involve finding a polynomial that passes through a given set of points.7. typically denoted f[x1. which aims to find a function to describe an entire data set as best as possible. Unlike regression. (x1. to interpolate for some value x between x0 and x1.y1). The formula for interpolating using a second-order polynomial that passes through three data points (x0.x0]. is Notice that this quadratic interpolation has the same first two terms as the linear interpolation – only the third term is new. You have already used interpolation techniques before – linearly interpolating between entries in the steam tables. Does the form of those fractions in the interpolation polynomial look familiar? Maybe if instead of writing y. which is a technique that finds functions that pass directly through every available data point. which itself is the finite divided difference of two first finite divided differences: 119 . the equation of the line that connects these points is So. yes. for example. to estimate a value at a condition in between points in the table. More officially. this formula provides the corresponding y-value.y2). For example.4 Interpolation and Splines The other form of curve fitting is interpolation.

**The pattern continues, and the nth order polynomial that interpolates n+1 points from (x 0,y0) to (xn,yn) is
**

then the sum of a number of terms involving divided differences:

There are some dangers with blindly fitting data to whatever order polynomial you like. It’s possible that

an interpolation polynomial of high order will predict an unrealistic data value, for one. Also, since an

interpolation polynomial is designed to pass through every point, there are two important implications

to remember: (1) you cannot have two different y-values for the same x-value, and (2) the coefficient of

determination, r2, is 1 by definition. A nonsense polynomial will still have an r2 of 1.

The one nice thing about interpolation polynomials is that it is easy to add another data point and

increase the power of the polynomial to connect through all data points. Your values x 0, x1, … xn do not

need to be in any particular order – there is exactly one nth order polynomial that passes through n+1

points (the number of parameters is the same as the number of data points, or in other words, the

degrees of freedom for an interpolation problem is zero).

**Another type of interpolation commonly encountered in engineering is multiple interpolation – usually
**

double interpolation. You’ve likely already run into this concept using data like the superheated steam

tables, where data is presented as a function of both temperature and pressure. If the specific

temperature and pressure are not given in your table, you must interpolate in both directions.

Mathematically, for a linear interpolation, it makes no difference if you interpolate across temperatures

first or pressures.

**More generally, if we assume we have a set of data points of the form (xi,yj,zij), where z is a linear
**

function of both x and y, one way to perform double linear interpolation for a value between the points

(x0,y0,z00), (x1,y0,z10), (x0,y1,z01), and (x1,y1,z11) is to use the formula

though this is one of those cases where it’s probably either to just “do” the interpolation in both

directions instead of relying on a clunky formula.

**Back to single interpolation now. Instead of using a single polynomial to pass through every data point in
**

an interpolation (can you imagine doing that for a column of values in a steam table? Yikes), it’s much

more common to interpolate using a spline. A spline is a piecewise continuous function that passes

through a collection of data (it gets its name from the thin, flexible drafting tool that helps to physically

draw smooth curves through points). The most common types of splines are linear and cubic.

**A linear spline is basically a series of linear interpolations between every two data points – a series of
**

straight lines that “connect the dots.” The obvious benefit to constructing a linear spline is it is simple. If

you have a table of data, need a data point between entries, and have no better information to go on, a

simple linear interpolation between the two closest points is your solution. One major detriment to

linear splines is that they are not continuously differentiable, but instead result in undefined derivatives

at most every data point. Further, linear splines are not particularly useful for approximating integrals of

a function that fits a data set (more on that in section 8.1).

120

**A cubic spline is a series of cubic interpolations on each cluster of four points, but with three extra
**

stipulations about these cubic polynomials: the first derivatives of the spline at each “knot” (place where

one cubic polynomial ends and the next begins) must be the same for both cubic functions; the second

derivatives at each knot must be the same for both cubic functions, and the second derivative at the

very first point and the very last point must be zero. The major benefit to a cubic spline is that it is a

smooth, continuous, uncomplicated curve – easy to compute, and easy to take the derivative or integral

of with usually an acceptable amount of error due to approximation. One major detriment is that cubic

splines take a bit of work to compute – but this is easily remedied by using a built-in tool of a computer

program like MATLAB.

7.5 Interpolation versus Regression

We have basically considered two types of curve fitting strategies, but each appears to have its own

applications. So when is it best to use which type of curve fitting? I’m not sure that there is always an

obvious answer, but there usually is.

The nice thing about regression techniques is they can reduce a large data set to a function and a small

number of parameters. Instead of having to carry around a lot of data points, you just have to carry

around that small set of parameters. Regression techniques are appropriate for problems with large

degrees of freedom. Regression helps to visualize overall trends in data, while potentially “smoothing

out” any outliers or error in measuring the data to begin with.

**Interpolation is convenient when trying to deduce additional data or information within already existing
**

data. Instead of trying to capture the behavior of the overall data set, you are more interested in

“locally” predicting a specific data point within that data.

**Both interpolation and regression can be sensitive to errors and outliers, though perhaps interpolation is
**

more sensitive because of the requirement that fitted curves pass through every point. Both

interpolation and regression can be abused and misused – the common use of computing r2 values can

be misinterpreted for a regression, and the use of an r2 value in an interpolation is meaningless (because

it is always 1!). It can be tempting to increase the order of polynomials in regression and interpolation to

seek a better “fit” to the data, but in both cases, this can result in the polynomial predicting values

outside the actual range of the data.

**Neither interpolation nor regression should be used to forecast or extrapolate data. In very rare cases, a
**

poorly obtained data set could even miss details for a function within the range of the data. Information

that is obtained from curve fitting is still empirical – that is, based on experiment – and should not be

treated otherwise.

121

7.5.1 Practice Problems

Explain whether each set of data should be treated with an interpolation or a regression and why.

**1) You have collected data for the vapor pressure of a novel chemical as a function of temperature
**

and want to determine the Antoine equation coefficients.

2) You have a table for the vapor pressure of water for various temperatures, but need the value of

the vapor pressure for a temperature that is between two temperatures in the table.

3) You need a value of the enthalpy of steam in the steam tables for a temperature and pressure

that lies between entries in the table.

4) You have data for the specific heat capacity of a novel chemical as a function of temperature

and want to include it in Table B.2 of Felder and Rousseau.

122

html . because there are going to be times this semester where Excel can accomplish the same tasks as MATLAB.mathworks.com/academia/student_center/tutorials/mltutorial_launchpad. Perform regression and interpolation in Excel and MATLAB. The table below contains many of the descriptive statistics you can calculate using either tool. A=[1. you should be able to… Compute descriptive statistics in Excel and MATLAB. By the end of this exploration. That said. Rather than ignore that fact.html. This week is a little different. and you are welcome to select the software that helps achieve that goal. Let’s practice with some smaller data sets to get you a feel for how descriptive statistics work in both Excel and MATLAB.mathworks.4. and again. The MATLAB Data Fitting and Working with Nonlinear Equations videos at http://www.7.6 Excel and MATLAB Exploration: Statistics and Curve Fitting Tools Reminder: It’s in your best interest to watch the following videos before coming to lab.2. this can be tedious. The purpose of this course is to be able to perform certain tasks using a computer. Chapter 12 of the free version of the MATLAB Interactive Tutorial published by Mathworks at http://www. Section 5. I want to you be aware of your options.5]. Versions of Excel before 2003 severely limit the number of columns you can have in a spreadsheet.3. First let’s create a single column vector in both Excel and MATLAB and compare the statistical functions that are built into each program.2 in Pratap’s Getting Started with MATLAB or Section 15.1 in Attaway’s MATLAB: A Practical Introduction to Programming and Problem Solving. Check to see that you get the same results with each tool! 123 . Microsoft Excel has limitations compared to MATLAB that may be significant when it comes to large data sets. for large data sets. Most actions in Excel will require being able to highlight selections of cells. Create histograms using Excel and MATLAB. Introduction to Data Fitting and Working with Nonlinear Equations and Data-Driven Models (about 29 minutes).com/academia/student_center/tutorials/computational-math-tutorial- launchpad. Perform inferential statistics tests in Excel and MATLAB.

124 . Function MATLAB Excel Sum of a data set sum(vector) =sum(cells) Mean of a data set mean(vector) =average(cells) Median of a data set median(vector) =median(cells) Mode (check documentation to mode(vector) =mode(cells) see how program deals with multiple modes) Standard deviation of a data set std(vector) =stdev(cells) Z-score zscore(vector) will return a Need to enter formula manually. Where MATLAB and Excel differ is in their treatment of matrices (as opposed to vectors) Create a matrix with 2 columns and 5 rows in MATLAB and in Excel: B=[1 2. 7 8. 3 4.Recall for Excel that.” the notation is first cell:last cell. vector of zscores corresponding to each element in the vector Minimum min(vector) =min(cells) Maximum max(vector) =max(cells) Range range(vector) Need to subtract min from max. The steps necessary to make them are similar but just different enough that we’ll spell them out separately. for example. 5 6. wherever it says “cells. for the table below. that would be A1:A5. Now in Excel you would type. 9 10]. And try the commands in the above table once more. What is the difference between using MATLAB and Excel for matrices? What could you do in either program to get them to give you the same result? Excel and MATLAB both have tools that allow you to create histograms. A1:B5 to designate all of the cells in the above screenshot. For the example on the previous page.

which was not done yet in the Figure below. in columns A and B. If you hit OK. Figure 3: Making a Histogram in Excel To make the histogram in Excel. and 90. you prepare the data by entering it into the spreadsheet. For example. the data is in the A column and the bins are in the D column. Excel puts “gaps” in between each column in the graph. according to the listed “Output options. you are preparing Excel to count your data into six ranges: Values that are less than or equal to 50. Figure 4 shows. but you can reduce this Gap Width to zero by right-clicking the data and choosing Format Data Series. you’ll want to remove the unhelpful legend and title from the graph. 60. a bin value is the maximum value for a range of data. Values that have not been counted yet that are less than or equal to 90. if your bins values are 50. or in a new Excel file). Values that have not been counted yet that are less than or equal to 80. the result. By default. Values that have not been counted yet that are less than or equal to 70. of course. In Figure 3 below. Then. a table will form on another sheet (or.In Excel. Values that have not been counted yet that are less than or equal to 60. Your input range should hold your data and the bin range will hold the bin values.” you can change the output options to put it on the same sheet. 70.” In Excel. 80. select Data Analysis from the Data tab. Then the data can be plotted using the Column Chart option from the Insert tab. then choose Histogram. Values that have not been counted yet (and therefore must be greater than 90). 125 . and then in another location on the spreadsheet. you enter “bin values.

use doc to read up on the necessary commands. and see if you can’t create the same graph as you did in Excel. Because one skill we are trying to develop this semester is the ability to adapt to modern tools.Figure 4: Histogram Plot in Excel Try recreating the histogram above. so first see if you can generate a histogram from memory. try to generate the same histogram as used in this example using MATLAB. 126 . is nicely versatile – you can use it to both save the bins/counts and to plot the results. histc. Some helpful commands include hist. (hist. if needed. but of course. and bar. in particular. depending on how it’s used.) You should have used these already for a homework problem last week.

So we’ll just look at the ttest command here: MATLAB: [h. Excel is much more limited.2. but the results are presented differently. or right).tail. left.p]=ttest2(x. you just compare the level of confidence and the p-value. vartype means “variance type. When it comes to inferential statistics. The two arrays are those samples. Excel and MATLAB instead figure out the α-value that corresponds to the actual test statistic. Excel is great for two-sample tests.mean. but MATLAB allows for more customization than Excel (weirdly. For our course. unequal variance assumption).tail) %(one-sample test) [h.vartype) %(unpaired two-sample test) Excel: =ttest(array1.alpha. The notation is very similar to MATLAB.p]=ttest(x. Recall that we would use the level of confidence α to determine a critical test statistic (by looking it up in a table). which is a computation that is too complicated for me to expect you to do “by hand” in this course. or 3 (unpaired. but not so much for one-sample tests). Paired tests are done when there is a direct one-to-one relationship with the data in the two samples (for instance. Then we would compute the test statistic (the mean of the sample) and compare the two. The commands for z-tests and t-tests are actually really. when two-sample tests are needed. the story is similar. The inputs are as follows: x is the vector of sample data (y is the other vector of sample data in a two-sample test). which is a logical value 0 (fail to reject null hypothesis) or 1 (reject null hypothesis). But then. 127 . so for example.alpha. Type is either 1 (paired).array2. the ttest command gives multiple outputs.tails. Excel and MATLAB both get the jobs done in their own way. Excel only performs two-sample tests.” that is.y. Where MATLAB also makes that decision for us and returns a 0 or 1. If you don’t tell MATLAB to save them all. It does not distinguish between left and right tailed tests because it just computes the p- value of a hypothesis test (more on that in a second). the only difference between ztest and ttest is whether you want to use the normal distribution or t-distribution (see the discussions in section 5.p]=ttest(x. mean is the mean you are testing for (the value in the null hypothesis). Does that make sense? They’re analogous. are the variances equal or unequal. equal variance assumption). In MATLAB. Reject null hypothesis if x<xc is the same as reject null hypothesis if p<α. checking the temperatures of the same five systems at two different points in time).y. alpha is your level of significance. you’ll only get the first output.When it comes to descriptive statistics. You have to enter the string equal or unequal in this place.type) In MATLAB. The second value is the probability of observing the sample mean if the null hypothesis is true.alpha. The p-value is used in hypothesis testing slightly differently than the way described earlier in this text. and tail is a string that describes what kind of –tailed test it is (both. much like the p-value in the MATLAB version of the test.4 to remind yourself if you forget the difference). really similar. Tails is the number of tails (1 or 2). Excel gives only one output: the p- value. 2 (unpaired.tail) %(paired two-sample test) [h. we are almost always doing unpaired tests. Excel makes you interpret the p- value yourself. instead of comparing the critical test statistic and the actual test statistic.

0.7068. 0. 0. 0.0108.3 have the tests that you’re looking for.6325.4).6873.3.alpha) %two-sample test Excel: =ftest(array1. Try these out using Excel or MATLAB.y.9299 The true viscosity of water is 0. (Hint: sections 5. 0.array2) Again. Perform a statistical test to determine if the experiment agrees with this value. 0.2.4271. 0. MATLAB: [h. 0.Testing for variances is similar to means.7245.p]=vartest(x. MATLAB does both one.5180.and two-sample tests. 0.alpha. 0.8020. The results of ten experimental trials are below (units of cP): 0. First you will have to perform a test to see if the variances are equal or not (why?) and then you can use those results to test the means.6096. 0.tail) %one-sample test [h. 0. 0.7392.7255.6849. And the computer will do the math for you – you just need to pick the right hypotheses and interpret them!) 128 . Excel just computes a p-value.9565.8364.653 cP.7947 You are asked to determine if the mean values of the two sets of experiments are statistically equivalent. 0.6406. 0.7939. Excel only does two-sample tests. 0. (Hint: you may want to refer to section 5.variance.3. The inputs are the same as they would be for means.1 and 5.p]=vartest2(x. 0. 1.5222. according to your preference and/or the program’s capability: A group of experimenters have been trying to measure the viscosity of water.6467. A second group of experimenters has this set of trial results (same units): 0. MATLAB will give one if prompted for a second output but otherwise just gives a 0 (fail to reject null) or 1 (reject null).

and tell it to add a trendline. you’ll get a screen that looks like this: You should first compute the actual error in your error bars. You can also add (very important!) error bars to data points in Excel.s) 129 . It takes three inputs: a vector of x-values. When you choose to format error bars (chart layout → error bars →more options). and the order of the polynomial: [p.s]=polyfit(x. In Excel. The vector p is the set of coefficients for the interpolating polynomial.x. this isn’t particularly difficult – you plot your data as a scatter plot. and it’s convenient because we can use it without having to do all the error analysis by hand: [polyy.n).delta]=polyval(p. The polyfit command will give you the coefficients for a regression polynomial.The other statistical tools we’ve discussed this week involve interpolation and regression. You can customize the trendline to be a polynomial or logarithm or a few other functions.y. you have four constants in the polynomial! Of course it’s going to pass directly through them. a vector of y- values. you just turned your “regression” into an interpolation). then choose “Specify Value” in this menu. right click the data. Adding a trendline in Excel by default assumes a linear regression. You can also have Excel display the equation and R 2 value on a chart (don’t forget R2 is meaningless if there are zero degrees of freedom – if you have four points and connect them with a cubic polynomial. I strongly advise against using Excel’s default options (some variant of the “standard error” computed in both directions). The structure s is information that we can feed back into MATLAB for error analysis using polyval. MATLAB gives us a little more room to play and to do error analysis.

but here is what you would type for the above problem.3.1 Your results should look roughly like this: 70 70 data 60 regression 60 50 50 40 40 30 30 20 20 10 10 0 0 -10 0 1 2 3 4 5 6 -10 0 1 2 3 4 5 Recall that for more complicated regression problems (see section 7. or “spline” if you want a cubic spline.The value delta is the standard error for the data points.ydata.6 27. then add a trendline or use polyfit as appropriate. Confirm that this vector p matches the coefficients found using polyfit.2 40.2 40.ones(6. please make sure you understand it: x=0:5. This is more important for non-polynomial functions. (Why 1.96*delta against x. you can plot polyy+1. The word in the “type” should be “linear” if you want a linear spline. MATLAB will also compute spline interpolations using the interp1 command: y_i=interp1(xdata.6 27. but in general you shouldn’t need a very high order polynomial.x_i. y=[2.96*delta and polyy-1. since MATLAB has polyfit.1 7. you should have one more point than the order of the polynomial.x'. 130 .9 61.^2)'.96?) To do polynomial interpolation in Excel or MATLAB. after all.7 13. Excel is more limited than MATLAB in the order of the polynomial. p=z\y.9 61. and then use the backslash operator in MATLAB.1]'.5) that you should set up a customized overdetermined linear algebra problem to solve. If you wanted a 95% confidence interval on the estimates at each data point.1 7. z=[(x.1)]. Now for some practice: Use Excel and MATLAB to plot the quadratic regression line and error bars for the following data: x 0 1 2 3 4 5 y 2.'type') This command will compute interpolated values y_i corresponding to values x_i (x_i can be either a scalar or vector) given actual values xdata and ydata.7 13.

0.3 36. 37.7.6 37 37. c) Fit a cubic spline to the above data and plot it together with the data (but not the other regression line) as a plot separate from the plot requested in part (b).3 37.0 a) Determine the coefficients of the slope and intercept of a linear regression that fits this data (T is the independent variable). 36.4 39. d) A group of experimenters tried to determine the solubility of salt at 50 degrees C and in six trials came up with values of 36. and 37. 36.4.8. b) Fit a linear regression line to the above data and plot it together with the data and error markers for a 95% confidence interval at each data point.5.0. 131 . 37.8 36.2 g per 100 g of water.0 36.6. Perform a statistical test using a computer function to determine if the experiment is in agreement with the literature.8 38. Temperature (degrees C) 10 20 30 40 50 60 70 80 90 Solubility (g per 100 g H2O) 35.1 Practice Problem The following data is from Perry’s Handbook for the solubility of sodium chloride in water (g NaCl per 100 g water) as a function of temperature.

All the effort you devote to remembering different techniques – separation of variables.3 of Felder and Rousseau’s Elementary Principles of Chemical Processes. 23. 132 . superposition. variation of parameters – is instead replaced with making sure you write your differential equation a certain way. Solve systems of first. Being able to numerically estimate a derivative is critical to complex problems.com/academia/student_center/tutorials/computational-math-tutorial- launchpad. Numerical Solution to ODEs. and process control. 3rd edition summarizes the two most basic methods of numerical integration. your differential equations course). solving these sorts of problems numerically tends to be a lot easier than solving them analytically (the methods you learn in MATH 225. Introduction to Solving Ordinary Differential Equations. 25. Integrals pop up all over chemical engineering – in solutions to material and energy balances. some of which we’ll even discuss in this course. Then you can entrust that equation to any number of numerical methods – methods that. We then devote the rest of this chapter to solving systems of ordinary differential equations. There’s something about solving differential equations that causes a lot of people to shut down. annihilators. In this section.mathworks. Chapter Goals Numerically determine the integral of a function. Derivatives are likewise frequent guests in chemical engineering applications – effectively anywhere dynamics are involved. heat and mass transfer. Numerically determine the derivative of a function. just to name a few. Chapters 21. provide a much more detailed description of the material covered in this section of the course notes. Solving First-Order Systems (about 36 minutes). and sizing of chemical process equipment like tanks and reactors. Appendix A. we review some techniques for computing integrals numerically and for approximating derivatives for when that is important. chemical reactions. are virtually always the same.and second-order differential equations numerically. Understanding the capabilities of programs like Excel and MATLAB will be very important to knowing what problems you can solve. The truth is. 5th or 6th edition. determination of enthalpy differences for a temperature change. you should be aware of approaches that may involve numerically computing integrals and derivatives and using linear algebra.html .4 in Attaway’s text. once you’ve coded them. so especially in fluid dynamics. In the case of boundary value problems. Recommended for Further Consideration: Section 5.8 Numerical Integration and Differentiation Required Reading/Viewing: The MATLAB Solving Ordinary Differential Equations videos at http://www. and 26-28 of Chapra and Canale’s Numerical Methods for Engineers.5 in Pratap’s Getting Started with MATLAB or Section 15.

but more formally. some process control schemes integrate information over time in order to help predict the next setting for valves controlling flow processes. (meaning there are n+1 points where the function is known).1 Integration Methods Integration of functions crops up from time to time in chemical engineering applications – in your transport classes. The area under a linear spline between two data points is the same as the area of a trapezoid. in chemical kinetics. classify the methods you probably already know. where you used equally sized rectangles and just read the value of the function at specific points to estimate their areas. and we can factor that part out of the summation. x2.8. This concept is even more crucial for the more complicated integration formulas. we’ll briefly.” or “midpoint” rules. x1. the trapezoid rule approximates f(x) with a linear spline.4). dealing with multidimensional problems usually means integrating a balance equation over a certain area or volume. Most integration rules are actually based on splines (recall section 7. we can write the trapezoid rule as If our x-values are evenly spaced. then all the values of xi-xi-1 are the same. Since splines are typically linear. xn. you have probably already discussed the most common numerical integration techniques – for example. Here. most of the “work” in deriving these formulas is actually from curve fitting! For a given function f(x) with known values at x0. we can approximate that area by breaking it up into a bunch of rectangles using the “left-hand. and throw a couple more into the mix. In calculus.” “right-hand. which condenses the above formula to Note that if you are writing your own computer code or using your own spreadsheet to compute this sum. In chemical process safety. …. Written in terms of sigma notation. integration of specific functions leads to theoretical reactor sizes. and so. 133 . considering the integral of a function as the area under a curve. integrals are used in risk assessment to estimate the effects of industrial accidents. polynomial. or trigonometric. this can be written as a loop or a series of the same computations copied repeatedly and then summed at the very end. and the integrals for such functions are trivial to compute analytically.

the rate of reaction has been determined to be a function of conversion4 as the following: 4 Adapted from Fogler. value of n needs to be even. after all.1 Practice Problem A hippopotamus digests food in two phases – autocatalytically in its stomach. Note that since Simpson’s 1/3 rule is drawing a number of quadratic equations connecting each set of three points. In this case. for evenly spaced values of x. Simpson’s 1/3 rule comes from fitting quadratic equations to sets of three points (as opposed to linear equations to sets of two points) and then integrating under each parabola.Instead of using linear splines on the function f(x). X0 is the reaction conversion at the start of the reactor (not necessarily zero – especially in the case of “reactors in series. is a little more complicated to display: Simpson’s 3/8 rule is a similar idea. This result.1. it’s possible to model the intestines as a tubular reactor. Xf is the reaction conversion at the end of the reactor. it’s possible to assemble quadratic splines or cubic splines to fit the same data points. For a typical hippopotamus digestive system. using every four data points to fit a cubic polynomial and integrate under that. C0 is the initial concentration of reactant (moles per volume). and r is the reaction rate (moles per volume per time).” and in this case the intestines are in series with the stomach). where there is a known relationship between reaction conversion X and volume V: where Q is the volumetric flow rate of material through the reactor. Since digestion is a chemical reaction. 8.” 3rd edition 134 . “Elements of Chemical Reaction Engineering. n must be a multiple of 3. followed by catalytically in its intestines.

Assuming that 25% of the digestion takes place in the intestines (so the other 75% took place before entering them).2.1. the error for this approximate is always on the same order as h itself. or the entries of the rows of Pascal’s triangle. the error in this approximation is typically about as large as h.2 Taylor Series and Numerical Derivatives Back in section 6. your first estimate will usually be the appropriate finite divided difference.15 m3 and processes 0. It is not saying that X0=0. Regardless of the order of the derivative. Unfortunately. or we can look toward more complicated computations for the same h. Isn’t math cool?) 135 . the first through fourth finite divided differences are (The coefficients in front of the function evaluations might look familiar – they’re the binomial coefficients.13 m3/day of grass. Approximations on derivatives are generally determined from the Taylor series of a function: If we truncate this series after the second term on the right.4. We can improve upon this approximation by making h smaller. Notice also that this function is identical to the first finite divided difference from section 7. To have them all in one place.This typical hippopotamus has intestines of volume 0. numerically determine the final “reaction conversion” of the grass.75! What is it saying?) 8. rearranging it gives us the familiar formula at the start of this section. easiest way to approximate a function’s first derivative. we briefly talked about using the “definition” of the derivative to give us an approximate value for the derivative of a numerical function: This is probably the quickest. (Note: Carefully read this problem. When approximating high-order derivatives.

this can become particularly small!): When would we ever need to approximate the derivative of a function? In chemical engineering. use of numerical derivatives often accompanies a more complicated problem. if a temperature profile is already known. if you take the average of a forward and a backward approximation. In the formula below. 136 . When there is enough information to do so.These divided differences are “forward” approximations of the derivative because they use points after the point where you want the derivative. the error of the approximation is on the order of h4 (and since h is less than 1. then use those two different locations to approximate the other derivative. On a related note. In each of the following formulas. for a function f(x.y). For boundary value problems. here are the first and second centered divided differences: These formulas below are also based on centered divided differences. x and y are interchangeable – it (virtually always) doesn’t matter which direction you take the derivative first. often numerical approximations of the derivative are necessary to enforce a boundary condition (it is just as likely that the heat flux – related to dT/dt – at a boundary is set at a fixed value. which is not really that different from a regular derivative. Mixed partials are just a little more complicated. but it’s the same idea as the rest – basically first you approximate the derivative in one direction at two different locations. but include more terms and are more accurate. as the temperature itself would be fixed). such as solving for a concentration or temperature profile of a system. You could likewise solve for “backward” approximations using points before the point where you want the derivative. For example. differentiation is necessary to compute heat flux. using such centered finite divided differences is the best way to approximate a derivative. For example. It’s also possible that a numerical approximation of a partial derivative is necessary. you obtain a “centered” approximation.

whenever a system is not at steady state. probably. Compute the new value for xi+1 at time ti+h as xi+1=xi+dx/dt*h. the result is a differential equation. compared to your previous experiences. we will almost always use “built-in” differential equation solvers to work through problems. The only difference between these various methods is the way this approximation is computed. and obviously that’s basically the entire point of your differential equations class. The solution to this differential equation depends on the initial value of the independent variable x 0. In practice.x) and a value for x at a certain time t. Set the value of ti equal to ti+h. dx/dt is used to approximate the trajectory of x at some future time t+dt. so just to reiterate: x is now the dependent variable that is subject to the independent variable t (usually representing time). The major work for you will be setting up the differential equation in a way it can be solved – so first. The basic form of this equation is where here x is the dependent variable and t is the independent variable. let’s see how it’s done in general. 137 . We are doing something a little different here. In some cases. The general pseudocode for the R-K methods is as follows: Set the initial value for the dependent variable x and independent variable t. the way a chemical reaction proceeds. A first-order ordinary differential equation is an equation that includes only up to the first derivative of a function in its formulation.8. Here. the way a piece of chemical engineering equipment performs between the time it is started up and the time it reaches steady state. it is possible to solve a differential equation analytically – you probably have at least a little bit of experience with this in calculus. we will not be using any of those methods at all. The class of solution methods discussed here are the Runge-Kutta methods. before diving into how to set up more general problems. Each of these methods works in basically the same way: given a differential equation dx/dt=f(t. Set the final value for the independent variable t and the time step size h.3 First-Order Ordinary Differential Equations Systems of differential equations arise all over the place in chemical engineering – in the differential form of a balance equation. but rather implementing numerical methods to find an approximate numerical solution for a system. Solving such differential equations gives insight to the transient behavior of a system – the way a flow rate changes as a tank is drained. Repeat until the final value of t is reached: Approximate the derivative dx/dt over the span of ti to ti+h.

2 Higher-Order Runge-Kutta Methods The idea behind the higher-order R-K methods is that the derivative dx/dt can be better approximated by using more computations to get there. MATLAB solvers implement anywhere from second-order to fifth-order R-K methods in many of their built in ODE solvers. Note that for Euler’s method.t+h]. the function takes on the form where n is the order of the method. The general idea is. the values ai are typically prescribed constants. Euler’s method uses the most basic function =f(t. h. while fourth-order methods have error on the order of h4. of course.Much like in the root-finding chapter. At reduced by reducing the step size.xi). that the error can be Euler’s method using MATLAB. before sharing some higher-order computations to achieve more accurate results. t. The “order” of the numerical method employed indicates the approximate total numerical error used in applying that method – the first-order method (Euler’s method) has error on the order of h (to the first power). here we will look at just two methods.1 Euler’s Method You probably have encountered Euler’s method in some of your introductory math or engineering courses: what better way to approximate the derivative over the range of [t. the only major difference between techniques is one part of the iterated method.3. we can estimate the value for xi+1 (the value of x at ti+1=ti+h) as What Euler’s method offers in its simplicity is often Let’s go to the Video! overshadowed by the small step size necessary to achieve a reasonable solution. 8. and h (and usually the ki’s that come before it). t+h] than by simply evaluating it at the current value of x and t? Given the current value of our independent and dependent variables. a1=1 and k1 is just f(ti. ti and xi. The error in Euler’s method is on the order Click here for a demonstration of of the step size. First we will look at the most basic way to approximate the derivative. but that also means a lot the Mathworks website.x). given current value xi at time ti. and the subfunctions ki are increasingly complicated expressions using x. 8. using Euler’s method. the next value xi+1 can be found as where the function is an approximation on dx/dt over the entire range of [t. For higher-order methods. which is a typical second-order method with the k-functions as follows: 138 . you can more iterations to get to your answer. This means.3. starting with the modified Euler method. also download a version of this implementation.

a1=0 and a2=1. If we have just two differential equations. we can rewrite our dependent variable x as a vector: The R-K methods do not significantly change. but then the next x-value only directly depends on k2. What is happening in the modified Euler method? Basically. the derivative of x is estimated at this halfway point. The most traditional version of Runge-Kutta methods is the classical fourth-order method. Then.ti+1].In this method. but the number of computations necessary to implement them grows. and this is used to approximate the derivative of the function over the range of [ti.4 Systems of First-Order Ordinary Differential Equations If we are solving multiple differential equations simultaneously. It’s probably easiest to show what’s going on by using the modified Euler’s method to solve a system of two differential equations: 139 . and these k-functions depend on both x1 and x2. which seems in most cases to strike a good balance between computational intensity and acceptable numerical error: Notice that the first two k-functions are the same as the modified Euler’s method. instead of just using the estimate of the derivative directly at xi. This means that the function k1 is indirectly used in the computation of xi+1 – notice that k1 is needed to evaluate k2. k-functions must be developed for both x1 and x2. 8. this estimate is used instead to predict a value halfway between x(ti) and x(ti+1).

which turns out to not be very likely. in order to solve it as an initial value problem we would need to know the value for both x and dx/dt at the same value for t. to turn our one second-order equation into two first-order equations: 140 . we are actually solving a boundary-value problem instead. The types of boundary-value problems we will cover here are just second-order differential equations. Notice that z2 is by definition dx/dt. but instead of knowing the initial value on both x and dx/dt at t0. In this particular case. like this: We only know how to numerically solve first-order differential equations. so z3 being dz2/dt means it corresponds to d2x/dt2. This is because the general form of an nth order differential equation is and can be rewritten as a series of first-order equations by making a series of substitutions starting with x=z1.5 Boundary Value Problems The Runge-Kutta methods are procedures for solving an initial value problem – that is. If the differential equation we are trying to solve is a second-order equation. any order of differential equation of the form here can be transformed into a system of first-order differential equations. given a differential equation and a value for the dependent variable(s) at a specific value of the independent variable.It is also possible to break down a higher-order differential equation to a system of first-order differential equations. and so on. like z=dx/dt. 8. Only the nth equation resembles the high-order differential equation we started with! With these substitutions. but often we are given x for two different values of t instead. we can numerically solve the differential equation over a range of the independent variable. like here: we know the value of x at two different times t. so we make a substitution. We do require two specific conditions defining the relationship between t and x.

141 . and you should become somewhat familiar with both. Report the current solution as the numerical solution to the problem. or other weird stuff. If we guess two different values for the initial condition of dx/dt and record the values of x(tf) for both guesses. and dx/dt with no weird multiplications. x. (Now the “problem” is “we don’t know the initial condition on dx/dt is. exponents.dx/dt) is a linear combination of t. If our guessed value of the initial condition on dx/dt is the correct guess. Now we have the initial value on x. we can linearly interpolate or even linearly extrapolate to find the correct guess on dx/dt. Does this sound vaguely familiar? The shooting method is just a root-finding method in disguise! Start with the problem and an initial guess at the solution to the problem. Label the current guess at the solution as the “previous” solution. then the trajectory should pass through the point (tf.1 Shooting Methods The term “shooting method” comes from the idea that we will guess an initial condition on dx/dt.The methods we’ve covered only let us numerically solve differential equations where we have an initial value completely defined.xf). but not on z. then see what x is at t=t f. (See how much closer our “current” x at t=tf is compared to the “previous” x. then “take a shot” to see where the trajectory goes. Use the previous solution in some computation to find a new “current” solution. Set the current error to some large number.x. we guess a different initial condition and go again – that is. its derivative with respect to t! How do we figure out a value for z at t=t0? There are two major approaches for solving boundary value problems. While the current error is greater than the desired approximate error. we keep shooting. Finite difference methods convert a differential equation into a linear algebraic system.) Once the current error is less than or equal to the approximate error. then the shooting method gets even easier.) Compute the new approximate error.”) Specify a desirable approximate error. Shooting methods essentially combine trial and error with the ODE solving methods like R-K methods to find a solution. trigonometric functions. until we hit the target point. logarithms. And you are reasonably familiar with root-finding and matrix equations! 8. If not. (Solve our differential equations using our guess on dx/dt.5. Substitute the solution back into the problem to make sure the problem is truly solved. If our differential equation is linear – that is. if f(t.

If x’’(t.) If x’’(t.x) is a nonlinear function... then we need to use special techniques to numerically solve this system of n equations and n unknowns.2 Finite Difference Methods A finite difference method converts our differential equation into a linear algebraic system. then we can also analytically solve this system – you probably learned how to do this in calc 1 or 2. but for some such equations.. (But also. if the second derivative is linear. the differential equation must be true. xn=known x0=known x1=? x2=? At each point. but I call them out a bit separately because x0 and xn are also known. this equation with three unknowns is true: Technically. h is the “distance” from point to point. We begin by approximating the range of our independent variable t by breaking it into n evenly-sized discrete pieces of “size” h: . so these two equations only have two unknowns: Collectively.5. t0=0 t1=h t2=2h tn=n·h . Only instead of using the differential equation outright. and so it can be seen that the value of x at every point ti depends on the value of x at ti-1 and t1+1. The MATLAB solver best equipped for this is fsolve. then we can numerically solve this system with a single matrix equation.x) is a linear function. Since we know the value of x at the initial and final value of t. we use an approximation using the second centered divided difference: In this formulation. this equation is also true for i=1 and i=n. 142 . you may also be able to get away with an iterative root-finding method. this means we have a system of equations to solve! For i=2 up to i=n-2.8.. we have n equations with n unknowns. and then were reminded about it in the first week of differential equations.

8. which are approached in an entirely different way than analytical solutions. The anonymous function that we write needs to be specified as a function of both the independent and dependent variable. The units on dx/dt are then micrograms per hour. It is also helpful to have read Sections 5. Plot in three dimensions in MATLAB.x) 143 . and 0. whether both are in the equation or not. Unlike your differential equations course. Say we initially have 1 mcg of bacteria at time t=0 and we wish to use this mathematical model to predict the biomass over 24 hours. Numerically solve steady-state partial differential equation problems.5 and 6. we will rely on built-in MATLAB programs to solve differential equations for us.com/academia/student_center/tutorials/computational-math-tutorial- launchpad. in that order. numerical solutions exist where analytical ones do not! Let’s start with a simple example of a differential equation with one independent variable and one dependent variable. the most condensed way to solve this equation requires two lines of code: >> dxdt=@(t. Solving First-Order Systems (about 36 minutes). By the end of this exploration.1). you should probably plot it: >> plot(t.html . so if you want to see it. The result is now stored in two vectors. which we used last week. Numerically solve boundary value problems of ordinary differential equations. so be careful! For example. This week. In many cases.x]=ode45(dxdt.[0 24]. The MATLAB Solving Ordinary Differential Equations videos at http://www. but the quickest is to take advantage of anonymous functions.3*x*(1-x/10).3 in Pratap’s Getting Started with MATLAB or Section 15. t and x.4 in the Attaway text.x)0. consider the logistic growth equation for bacteria confined to a specific space: where x is the biomass of bacteria in micrograms. Introduction to Solving Ordinary Differential Equations. >> [t.mathworks. Numerical Solution to ODEs. you should be able to… Numerically solve initial value problems of ordinary differential equations. In MATLAB.6 MATLAB Exploration: Differential Equations and Advanced Visualization Reminder: It’s in your best interest to watch the following videos before coming to lab. There are multiple ways to solve this in MATLAB.3 is the growth rate of the biomass per hour. we focus here on numerical solutions.

A cylindrical tank of cross-sectional area 3 ft2 is originally filled to a height of 4 feet. A valve below the tank is opened. The general format is [indep_var. This is true even in cases like the logistic growth example – did you notice that the equation dx/dt is a function of x only? But that we still included (t.dep_var)expression.x) in the function call? That’s because we have to. The function may be written as an anonymous function or as an m-file in the same folder as your Current Folder. 10 8 6 x 4 2 0 0 5 10 15 20 25 t Now let’s break down the ode45 command. h is the height.2 ft/s2).dep_var) output=expression. resulting in an area of 0. dep_var]=ode45(function.dep_initial) though I strongly encourage you to doc ode45 to learn about other possible inputs and outputs. and g is the acceleration due to gravity (32. there is something particular about this function: it must be written as a function of both the independent and dependent variable (did you just read that on the last page? It is important).) Function: ode45 call: 144 . What is the level of the tank as a function of time? (How long should you integrate dh/dt? You can just guess and check for now. %if you forget this . Or an m-file function output = func(indep_var.[indep_initial indep_final]. func=@(indep_var. you will be sad because MATLAB will %be calling this function up to eleventy kabillion times Try it yourself: the differential equation modeling the height of an ideal draining cylindrical tank is where A is the cross-sectional area.01 ft2 through which fluid may flow. Either way.

145 . who.m)[3*m(1)-3*m(1)*m(2). or more equations. but derivatives of mass (or moles or concentration) with respect to time! Let’s work our way there with another kind of material balance: the population balance. it’s probably easier to write a short m-file. It’s also probably pretty confusing to do it as an anonymous function (but it is definitely doable). the mathematical model is accumulation = generation – consumption. Here. If this system is not at steady-state. For this example m is a vector of 2 values. but if we had more terms.m) dm=[3*m(1)-3*m(1)*m(2). -m(2)+m(1)*m(2)]. Try programming the above system of two equations. which would be m(1) and m(2) in MATLAB. so long as you understand it.1. or as an anonymous function dmdt=@(t. integrating it from t=0 to t=10. how many times have you had to write exactly one material balance to solve a problem? If you are dealing with a problem that is not at steady-state. to any number of values. or constants that we wanted to define and/or vary first. If this is your first time doing this. can only be generated (through growth and/or birth) or consumed (through actually being eaten or some other method of death). more complicated terms. the anonymous function isn’t too bad. as you might expect. A predator-prey model tracks the mass of two different species (the predator and the prey). in a closed system. Here is this vector equation in both forms: function dm = dmdt(t. we will have a system of differential equations to solve – for instance.2 and m2=1. you will have to specify initial values for the entire vector. The ode45 call varies slightly – can you guess how? Since the dependent variable is now a vector. those accumulation terms are not zeroes. This idea extends. it’s not obvious.More often than not. Whatever you choose to get the job done is fine. ODE solvers in MATLAB solve systems of differential equations by expressing them as a single vector differential equation. starting at initial values m1=1.-m(2)+m(1)*m(2)].

Energy fluxes are derivatives of temperature. which have constant temperatures of T1 and T2. In between. so we obtain this second-order differential equation: where T is temperature (we’ll use degrees Celsius). Let’s consider the temperature profile of a long.01 for h’. thin wire: Ta T1 T2 The wire is attached to two surfaces. 437L. you’ll look at considerably more complicated geometries and energy transfer scenarios. and h’ is a heat transfer coefficient (in this case. With no generation/consumption terms. a combination of the thermal conductivity of the wire and the convective heat transfer coefficient between the wire and the air). the wire is exposed to the atmosphere. there is just flow of energy into or out of the wire.4 m1 1. we need to transform it into a system of first-order differential equations. but this one is pretty straightforward. and 485L (and already this semester in ENCH 225!).4 for the general formulation if you need it) before looking on to the next page… 146 . but temperature is changing with location.2 m2 m 1 0. x is position along the wire (in meters). We’ll use a value of 0. and that is when we are trying to solve a higher-order differential equation. In ENCH 427. which has ambient temperature Ta=20 degrees C. Try it yourself (see section 8.4 that there is another way we could encounter a vector differential equation.8 0 2 4 6 8 10 t Recall from section 8. What are the units on h’? To solve this equation numerically. 1.

one for T (now y(1)) at x=0. try a guess of z=9 °C/m and use ode45 to solve for T as a function of x from x=0 to x=L. we need two initial conditions. Let’s call our vector y so that y(1)=T and y(2)=z. so we need it to increase faster. (h’ is 0. 147 . This is going to be very much like the two-variable biomass model from earlier in this exploration. If you plot temperature versus position. and you try the second one… Since we have two equations. Try a larger value of y(2) for x=0 and see what happens. T and z. because MATLAB needs to solve this system simultaneously . But we don’t have that. Try it: for a wire of length 10 m. We will guess a value for z at x=0. Define your function and constants: Write the ode45 call: [x. T=T1. and we have It might be confusing that we have two variables. we’ll have to guess again. you’ll see that the temperature is always increasing. Then dz/dx is the same as d2T/dx2.y]=ode45( See what T is at x=L by proving the last value of the first column of y: disp(y(end.01 and Ta=20 °C) with two wall temperatures T1=40 °C and T2=200 °C. We know at x=0. which represents dT/dx) at x=0. then we guessed z correctly! If not.as a vector differential equation. which changes our equations from those above to what? I’ll do the first one.Our second-order equation can be written as two first-order equations if we define a variable such as z=dT/dx. T=T2. If T=T 2.1)) % this is the last element of the first column Your result is less than 200 °C. T=T1. and one for z (y(2). Then we will look at the value of T at this point. At x=L (the length of the wire). So we turn to the shooting method. then use ode45 to solve our equations up to x=L. Instead we have two conditions for T (y(1)) at two different x’s! At x=0.

T(4). Which solution do you trust more? How could you change one method to make the result look more like the other method? 148 . Take the lines of code that you used just now to solve this system of equations and turn that into a short function m-file where the function’s only input is your guess on the initial condition. and Ta are all constant values. We’ve written a code that does some computations. and T(8). but let’s take a moment to think about what we’re doing. Then use one of the root-finding methods (perhaps bisection. this is a linear equation! If we write this for each discrete value x. T(6). and what we care about is that the value of the temperature at x=L is a certain value… This is a root finding problem! The “function” we are trying to solve is more complicated. though linear interpolation is fastest in this case) from last week to figure out what the correct value of z at x=0 results in T=200 °C at x=10 m. you’ll find that they mostly agree. which means it’s time to break out the linear algebra. squares. and keep integrating this function. Try it: Using Δx=2 m. The other approach to solving boundary value problems is to “discretize” the independent variable (usually into equally-sized length. or cubes) and approximate the function using the approximations for derivatives given earlier this chapter. but definitely code-able in MATLAB.4. and 8 m.6. this means rewriting the differential equation as an approximation that holds at each discrete point: Since Δx. h’. For the problem we have been considering. we have a system of linear equations. write out the equations for the above differential equation approximation using x=2. What would the equations be at x=0 m and x=10 m? You should be able to write this as a matrix equation and get a result for T(2). If you plot this “discretized” solution against the shooting method solution.You could keep guessing z-values at x=0.

08 0. it plots a surface if you give it the right inputs.V) If you just type surf(V). For the volume data given in the matrix V.mat from the Lab Documents folder on Blackboard. The surf command is useful for these kinds of three-dimensional plots. but for practice just plotting. the temperatures range from 50 °C to 800 °C in increments of 50 °C.04 0. what happens? Can you see the difference? In the Figure Window. The pressures range from 10 bar to 500 bar in increments of 10 bar.06 0. download the matrix of data volumes.02 0 800 600 500 400 400 300 200 200 100 0 0 149 .Now for our last exploration topic: 3-D visualization. You will plot the solution of a two-dimensional partial differential equation for this week’s deliverable. then load it in MATLAB and plot it for a visualization of the steam tables that depends on pressure and temperature. you can plot a surface with the correct values on the axes: surf(P. This allows you to position your plot in a meaningful way to most clearly display your results. In the case of solving a system with multiple independent variables and one dependent variable. it can be helpful to plot a system in three dimensions. If you need a 3D plot for a report. Once you have created vectors for T and P. remember to properly label the axes as well! 0. there’s an icon with a cube surrounded by a circular arrow – that’s the Rotate 3D icon. As you might guess from the name.T.

say t=0 to t=100. but don’t know the name of the function that does it! Typically.z) 100 80 60 40 20 0 1 0. there is a distinct x. If you want to just plot those ordered triplets of values (x. you can also search for any words. and z value. to use MATLAB’s help/doc commands to explore functions that are new to you. 150 . one such system of equations would be x=cos(t) y=sin(t) z=t for some range of t. For every value of t.It’s also possible that your plot is a line. Remember.5 -0. For example. y.5 1 0 0. That happens a lot in parametric equations (remember being able to plot things in polar coordinates in math class? It’s a lot like that). If you have the MATLAB help browser open. can you figure out why? Talk this through with me or your teaching assistant. if you know what you want to do. then you should use the plot3 command: plot3(x. This should wrap up the majority of the abilities you are expected to have using MATLAB in this course.5 -1 -1 If your plot looks different than mine above. so do give MATLAB’s help browser a chance before running off to consult The Google.z) for all values of t.y. but in 3-D. to plot a coil in 3-D.y.5 0 -0. the MATLAB help browser contents are also the first thing that pops up if you do an internet search for a certain technique in MATLAB (Mathworks hosts all this information on their website). when in doubt.

1 Practice Problems 1) Your coworker found out you know a little something about a tubular reactors and so she was wondering if you could help her with her latest work assignment of modeling a reaction through a narrow tube. A value of r=1 corresponds to the end of the vessel. You may assume that the initial value of dT/dr is a positive value. 0.6. In the above equation. 151 . You will need to implement a nonlinear equation solver (root finder) for this problem. A value of T=1 corresponds to a 100% increase in the original absolute temperature of the vessel contents. The reactant should enter the tube at a concentration of 0. but there should be zero reactant at the other end of the tube.3 moles per liter. 0. 0. The tube’s length is 2 meters. As before. the flow of material from high to low concentration. in this model. Be careful! The equations needed to implement this method are not linear.8. k is the reaction rate constant and D is the diffusivity. determine the normalized temperature difference as a function of normalized position using the shooting method. 1}. 2) The steady-state temperature profile in a cylindrical vessel housing a combustion reaction can be described using the following equation: where r is the normalized position in the vessel (dimensionless) and T is the normalized difference in absolute temperature (also dimensionless).05 per second. (Note: your guess for the value of dT/dr at r=0 is important – there are actually TWO solutions to this equation? Can you find them both?) 3) Use the finite difference method to resolve the above problem by discretizing the vessel into positions r={0. She has determined a model for the steady-state concentration of reactant c as a function of distance down the tube x and remembers something about a shooting method. the first-order chemical reaction takes place in a comparable amount of time to chemical diffusion.6. If the ends of the vessel (both r=0 and r=1) are held at a constant T=0.4. 0. Show her how to use the shooting method to find the concentration profile down the tube (concentration as a function of distance) and visualize it using MATLAB. However. and the reaction rate constant is 0. but doesn’t know what to do from there.2.8. there are two possible solutions to this problem. the diffusivity is 1.5x10-2 m2/s.

1}. 1. c) Use the fsolve function in MATLAB to find the solution. 5. b) Using every single combination of initial conditions x1={0.2.4. it is known that y=0 at x=0 and y=1 at x=1. 5. (It will look sort of linear. 0. Explain what you observe in steady state solutions as α is increased. 4. d) Take your plot from the previous problem.) 6) Use the finite difference method to approximate the solution to the same differential equation used in the previous problem for x={0. The differential equation is where sinh is the hyperbolic sine (the function for this in MATLAB is. 0. then plot x1 versus t and x2 versus t on the same graph. but it isn’t exactly. unsurprisingly.8) to one another. sinh). and in the same plot.6. b) Plot y as a function of x from x=0 to x=1. c) Repeat part (b) for α=2. plot these four points as markers on the same plot. b) Define an anonymous vector function in MATLAB that collects your four equations from part (a). 4. 152 . Write each equation in the form f(x)=0. For this problem. 1. so follow these steps: a) Write (by hand) the four nonlinear equations that relate y(0. and 4. y(0. 3. 2.2). On a separate graph. 3.4) The dynamics of a bioreactor with two species competing over the same space are described by the system of equations a) Using α=1 and an initial condition of x1=x2=5. y(0. Explain how what you see in this graph relates to the Newton-Raphson root-finding method to find the steady-state solution to the above system of equations. 6} and x2={0.6). Does it make sense if the parameter α describes the amount of space species 1 needs to survive? 5) One of the earliest test problems for the shooting method uses an equation that describes the confinement of a plasma column under radiation pressure. Use the shooting method to do the following: a) Determine the value of dy/dx at x=0 (It is known to be between 0 and 10). 6} – that’s 49 different initial conditions altogether – integrate the above system from t=0 to t=10. 2. 0. but plot all 49 lines on the same graph.4). 0.8. plot x1 versus x2. Plot only x1 versus x2 for each initial condition. 3. integrate this system of two equations from t=0 to t=10. This is not a linear problem. and y(0.

assuming initial concentrations c1=0. (b) Plot c1 (abscissa) against c2 (ordinate). 153 . so that the file runs as normal but I can see what you did). please ALSO copy it over to the published m-file (and comment it out. (a) Plot all three concentrations on the same graph with time as the independent variable. (c) Plot all three concentrations against one another in a 3-D line plot. use the figure command (type the word “figure” as a separate line just before the new plot) to let MATLAB know you want all three plots viewable simultaneously. To make multiple MATLAB plots appear in the same published file. If you save the ODE function as a separate m-file.7) Use the ode45 command to integrate this system of three chemical species in a closed reactor system from t=0 to t=1000 s.003577 gmol/L. c2=0. and c3=5.99524 gmol/L.028481 gmol/L.

Your findings from dimensional analysis can save a lot of time in the laboratory – if. you may find that doubling the pressure and density of a system simultaneously yields no change in the system you are studying!). we will use some of these numbers to illustrate the method of dimensional analysis so that you are able to perform the technique itself. Table 4: Examples of Dimensionless Numbers Important to Fluid Dynamics Dimensionless Number Formula Reynolds Euler Froude Weber 154 . it might be illuminating to vary them in specific ways to test a range of Euler numbers instead (and. and sometimes those ratios are not particularly intuitive (see Table 4 below). it’s probably because that person is credited with applying dimensional analysis and conducting experiments related to chemical engineering phenomena in areas like fluid flow.9 Dimensional Analysis and Similarity Recommended for Further Exploration: Chapter 7 of Fox and McDonald’s Introduction to Fluid Mechanics. energy. the behavior of a system often depends on specific ratios of the system properties. Chapter Goals: Explain why rendering equations dimensionless is an important skill to have. When you encounter a “dimensionless number” with a person’s name attached to it. Conduct dimensional analysis for a given system and describe what quantities in that system could be varied to completely explore that system experimentally. Some dimensionless numbers specific to fluid flow are in Table 4 below. This section of the course notes is a very concise summary of the material found there. In this course. and/or momentum. Armed with knowledge from dimensional analysis. for instance. and pressure of a system may vary. Dimensional analysis is a tool that crops up in several chemical engineering applications that helps us uncover trends in theoretical and experimental analysis that would otherwise remain hidden. you are studying a system where the density. 6th edition or newer. Virtually any book on transport phenomena has at least a section of a chapter on dimensional analysis. you can characterize otherwise complicated systems by uncovering relevant dimensional numbers and conducting experiments that deliberately vary these numbers. heat transfer. or mass transfer. In many applications of conservation of mass. volume.

Likewise. 5) (optional) Use the results of data correlations to evaluate existing systems or design new ones. length. Since this tube is cylindrical. Step 1. Step 2. length. sometimes “length” means the diameter of something spherical or cylindrical. z) instead of rectangular (x. So here’s one for size: Let’s consider the pressure-driven flow of a Newtonian fluid in a tube for a reasonably high pressure so that the fluid flow is turbulent. V is velocity. This technique can be a tricky one to understand and master. because you need to know what you’re taking the density. We will choose characteristic length D and velocity V in order to render our equation dimensionless. and the result is a characteristic pressure of 155 . pressure. 3) Scale all variables in the governing equations by the characteristic quantities. and σ is interfacial (surface) tension. P is pressure. μ is viscosity. This will yield dimensionless equations in which dimensionless groups appear. and the best way to get better at it is to work through some examples. velocity. and gz is the component of the gravity vector parallel to the z-direction. The units may vary. L is length. The characteristic quantities are constants and they must be representative of the system. and in a cylindrical tube.. μ is the viscosity of the fluid. we’ll have to work with polar coordinates (r. this is usually a combination of differential equations and boundary conditions. but the important thing is that they all cancel. z) ones. ρ is density. Take care in using these groups.1 Rendering Equations Dimensionless The general procedure for dimensional analysis is as follows: 1) Select the equations relevant to the system you want to model. θ. we’ll assume a system at steady-state and a long tube. Note that D has dimensions of length. g is acceleration due to gravity. all the fun is in the z- direction only: where ρ is density. 9. and V has dimensions of length per time.In the table above. The values of the dimensionless groups (numbers) determine the properties of the differential equations. time). we can create a characteristic pressure with our velocity in mind. To simplify the equations we have to work with. y. pressure-driven flow of a reasonably- behaved fluid is dictated by the Navier-Stokes equation. 2) Select characteristic quantities with which to scale the variables in the equation (for example. In fluid mechanics. and just look at flow in the direction of the tube. In this case. What’s relevant here is each of these numbers are ratios and they have no dimension. For instance. It is important to be able to identify any relevant dimensionless numbers that describe a system because they can be used to inform us on the behavior of a system by studying a related one. of. etc. 4) Design and conduct experiments at a reasonable scale to develop data correlations for the system of interest. vi is fluid velocity in the i direction. so we should define a characteristic time as D/V and not some other arbitrary expression. Select the relevant equations for the system.

That’s six different constants that have a bearing on our system! And some of those constants are really hard to change. with a little bit of algebraic rearrangement. This means you have to “solve” the dimensionless variable equations for the original variables. there are a lot of different constants at play: length and radius of the pipe. while the Froude number is a ratio of the inertial forces to gravitational forces. we can design something reasonable and use data from that experiment to make valid claims on larger or smaller systems. Step 4. your ENCH 425 instructor should consider this with you in the fall. Say we wanted to test the effects of each of these variables by setting them to a mere 4 different values each. In this case.. don’t worry about how we determined which characteristic quantities should be expressed how. or we can use others’ results on scale models. 156 . gravitational acceleration. If for two different systems. velocity. We now reformulate all of our variables in dimensionless form. we get. We call that dynamic similarity. which we’ll note with asterisks: Substitute these variables into the original equation. Dimensional analysis and dynamic similarity also give us one more very important insight into experimental design: we can use it to drastically reduce the amount of work necessary to characterize a system. the two systems are mathematically identical. This may not look like much of an improvement from our original equation. If we need to know about the operation of an apparatus. Dynamic similarity can be used in two ways. then substitute them into the governing equation. the dimensionless boundary conditions are the same. and density.ρV2. we can take advantage of dynamic similarity to “scale up” or “scale down” a process – rather than conduct experiments on a very large or very small apparatus. Experiments can be conducted by paying attention only to these two dimensionless groups. (For now. Even if we could change all six of them easily. performing dimensional analysis reveals there are really only two values that dictate the behavior of our system. viscosity. The other important use of dynamic similarity is data correlation. That means there are 4x4x4x4x4x4=4096 different combinations to try – and that’s only running one trial of each experiment! On the other hand. For one. In the example walked through here. then the two systems are governed by the same conservation of momentum equation. we can conduct experiments on it. the values for Re and Fr are the same. If on top of that.) Step 3. The Reynolds number is a ratio of the inertial forces of a fluid to its viscous forces. we can build a scale model and experiment on that. but notice that two distinct ratios of constants have clustered together now that the equation is entirely dimensionless! Those two ratios are given in Table 4: they are the Reynolds number and Froude number for the system. we’ve reduced our experimental load down to just 4x4=16 different kinds of trials. the Reynolds and Froude numbers. Even continuing with the lazy idea of only varying these numbers to 4 different values. the number of experiments needed to study a system would be enormous.. If we don’t have the apparatus.

Unfortunately. pressure drop. b. This expression must be dimensionless. fluid viscosity. must make the dimensions cancel in all cases. not every system has an obvious system of equations that describe its phenomena. The selected quantities should cover independent combinations of units. we seek to find dimensionless combinations of the core quantities with each non-core quantity in turn. which can help discern dimensionless groups for much more general problems. In most cases. – but the theorem also requires that the quantities q are linearly independent in terms of the fundamental dimensions u. length L. There are 3 fundamental dimensions we are working with: mass M. Let’s consider the flow of an incompressible fluid through a circular pipe with no gravity effects. In terms of an “equation” on the dimensions. This means. There is a more general procedure. and time t. the q quantities can actually be expressed in terms of fewer fundamental dimensions if posed a particular way. length. velocity v. There are other “rules of thumb” to consider in this analysis. let’s select diameter d. these “fundamental dimensions” are exactly what you would figure – mass. The three dimensionless groups are all products of the core quantities raised to some currently- unknown power. or that system is so complicated that rendering it dimensionless is the last thing we want to do. One way to write such a relationship is to say that one parameter is a function of the other two: We then select 3 of the 6 quantities to help us completely characterize the system. Example 1. length is L. For example. just to finish this example. Let’s see what we’re talking about with some examples. we have 157 . etc. From our previous discussion.2 The Buckingham Method When at all possible. so there is a function that relates these three parameters. So for now.) The Buckingham Pi Theorem states that the relationship among q quantities or variables whose units may be broken down into u different fundamental dimensions may be written as a function of q-u independent dimensionless ratios. which we’ll get to in a little bit. Next.9. and density is M/L3. The number of dimensionless parameters or Π parameters is q-u=6-3=3. we mentioned that there are six different values that we could possibly change to study our system: pipe diameter. pressure drop is M/(Lt2). pipe length. velocity is L/t. time. or Π parameters. so some combination of a. and c. The dimensions on diameter is L. so it doesn’t make sense to choose both diameter and length. in a few cases. So the number of quantities we are working with is 6. fluid velocity. it’s generally best to render a governing equation dimensionless in order to discern the dimensionless groups relevant to a particular engineering problem. and density ρ as our “core quantities” that appear in every dimensionless group. and fluid density. known as the Buckingham method. viscosity is M/(Lt). (It can also help in uncovering important characteristic quantities in the case of rendering an equation dimensionless as in the previous section. for π1.

b. and a=0. who knows.) 158 . L. we get which is the Euler number! We can repeat this idea for the other two Π parameters. and t need to sum together to be zero. So. b. it’s been shown. So. squared. in cases where the length is significantly larger than the diameter of the pipe. L.where the equal sign in brackets represents that this is more an evaluation of units or dimensions instead of an actual equation. and c for each fundamental dimension. the inverse of the Reynolds number. These two equations should satisfy. for some other values of a. This is just because the Buckingham theorem only points out what ratios drive the behavior of a system. Substituting these back into our expression for π1. so we don’t even really know how those ratios come into play – they could be inverted. But there’s no way to know that without doing those experiments first! (Or I guess you could consult a book or this course packet. which gives us l/d as a dimensionless group. a=-1. we get a=b=c=-1. which results in 1/Re. we find our relationship summarized in three dimensionless groups: where you may note that I just report the Reynolds number Re instead of 1/Re. raised to a decimal power. and c: For π2 we obtain b=c=0. M. the exponents on M. incorporating length and viscosity. For π3. b=-2. and t: By inspection we see that the solution is c=-1. the ratio l/d is a negligible factor in fluid flow experiments. The only way to find out is through experiment! And through well-designed experiments. We can then write one equation in terms of a. but where is the fun in that.

one at a time. and the average “height” of the roughness. using the Buckingham method. or temperature T (but just for completeness. 5) Set up “equations” in terms of the dimensions. and luminous intensity). The first example is very similar to the one we already considered – see if you can do it using the six steps before reading through the entire worked-out problem. electric current. 159 . both as core quantities). and some length are almost always chosen as core quantities. Some fluid mechanics books suggest using force instead of mass as a fundamental dimension in the process of this check step. especially if you are new to using this method. so they are the “core quantities. There is a small chance. length L. for example. ρ. when you are able to show the quantity has no effect on the system. We seek a set of dimensionless groups that can be used to correlate experimental data. the other fundamental dimensions are moles. again. so do not include quantities that would be considered the dependent variable in an experiment (for example. Step 1 is taken care for us in the preceding paragraph: we have seven quantities involved: P. that using the fundamental dimensions will not result in a system of independent equations. Let’s see two more examples in action. or experimentally. we’ll still find dimensionless parameters. l. fluid velocity v. viscosity μ. 3) Write out the dimensions of all q quantities in terms of the u fundamental dimensions. Note that we are explicitly stating that pressure depends on the rest.For a general situation. here is the recommended six-step procedure for determining the Π parameters: 1) List all q of the dimensional quantities involved. Almost always these are mass M. is just a proposed set of dimensionless quantities that are related. 2) Select the u fundamental dimensions. but they may not completely characterize our system. That’s why. they will eventually drop out – either mathematically. The pressure drop P in this pipe depends on the pipe length l. you must “swap out” one or more fundamental dimensions with independent combinations of them. Likewise. Consider the steady flow of an incompressible fluid in a “rough” pipe. density ρ. diameter d. Solve for the exponents on the core quantities for each equation by making sure all the dimensions cancel out. or length and volume. The relationship among these parameters must be determined experimentally. viscosity is rarely (but very occasionally it is!) a core quantity – it’s just “known” from experience not to be involved in multiple dimensionless groups for the same system equations.” No core quantity should have dimensions that are the same or merely a power of another (so don’t include multiple lengths. e. and e. multiplying the core quantities raised to unknown powers together with each of the remaining quantities – there will be q-u equations because there are q-u dimensionless groups. the “result” of dimensional analysis has been known for ages. In that case. velocity. 4) Choose a set of u dimensional quantities that includes all of the fundamental dimensions. In most fluid mechanics problems. These quantities will all be combined with the remaining quantities. μ. time t. 6) Check that the groups obtained are indeed dimensionless. and so the choice in core quantities is based on what’s already known in the field. The core quantities may appear in every dimensionless group. If we neglect to include all the relevant quantities. however. d. If we accidentally include irrelevant quantities. pressure). The result of the Buckingham method. density. Step 4 is probably the most frustrating. v.

we list the dimensions: P [=] M/Lt2 l [=] L d [=] L v [=] L/T μ [=] M/Lt ρ [=] M/L3 e [=] L Step 4 is to select the core quantities. Check by using force. Step 6. length. and a=0 and the first dimensionless parameter is P/(ρv2). We expect there to be q-u=4 dimensionless groups. and d. This is the same equation for dealing with both the length and the roughness height. The result is b=c=0 and a=-1. By inspection. so our last two dimensionless groups are l/d and e/d. and time as the fundamental dimensions. v. 160 . or 1/Re. length L. length.For step 2 we will select mass M. so we have four equations to write and solve. All three values are -1 so the dimensionless quantity is μ/(ρvd). the result is c=-1. since we used mass. b=-2. We choose ρ. For step 3. and time to find the dimensionless groups. each using the non-core quantities once. since those are the usual choices in fluid mechanics. and time t as the three fundamental dimensions.

and σ. length. and surface tension σ. If we were to write a matrix of the dimensions of our core quantities (similar to the way we were doing chemical compounds back in Section 2.So. a meniscus forms inside the tube. Consider the “capillary effect:” when a small tube is dipped into a pool of liquid. we would have to resort to experiment. γ. Step 1: our quantities are h. and time as the fundamental dimensions.5). γ. b=-1. Unfortunately. this confirms that we have found 4 related dimensionless groups. meaning there is only one dimensionless group. c=1. The height of this meniscus relative to the surface of the liquid. So which result is the correct one? The problem arises because our choice of fundamental dimensions is not independent. Step 3: the dimensions for each quantity are h[=]L d[=]L γ[=]M/(L2t2) σ[=]M/t2 Step 4: we need to choose 3 core quantities. d. we get this matrix: 161 . specific weight. Step 5: the equation is One obvious solution is b=c=0 and a=-1. that’s not the only solution – we could also solve this system with a=1. length. seems to depend on the tube diameter d. since we said P is the dependent variable: In order to figure out what this functional dependence is. h. and we can say the dimensionless group involving pressure is a function of the rest. We are looking for the dimensionless groups to help us guide an experiment. and time as fundamental dimensions gets us into trouble. This next example is a case where choosing mass. Step 2: we choose mass.

A length will definitely come into play. then force probably will. That means the other dimensionless group is σ/(d2γ). Experience tells us that if mass doesn’t work in dimensional analysis. and σ. and either γ or σ will work this time – I’ll choose γ but it might be good practice for you to try it with σ. This matrix is not of full rank. Step 5 is to write out the equations: Here b=0 and a=-1. Step 4: we need to choose 4-2=2 core quantities. and there will be two dimensionless groups. Here a=-2 and b=-1. Step 2: we choose force. So the dimensionless group is just h/d. Since we wound up using force in the analysis. you would get a matrix of full rank. d.This is not an independent system of equations – notice that mass and time appear exactly the same way in two of our dimensional quantities. Step 6: Check that the groups are dimensionless. So we really only have 2 fundamental dimensions. so we choose d. length. If you were to do similar analysis on the core quantities from our previous examples. Step 3: the dimensions for each quantity are h[=]L d[=]L γ[=]F/L3 σ[=]F/L Notice that time doesn’t come into play now. So we begin this problem again… Step 1: our quantities are h. γ. and time as the fundamental dimensions. let’s go back to using mass as a dimension to check: 162 .

What are the other dimensionless groups that arise when using the Buckingham method? 3) For unsteady-state heat conduction in a solid. its diameter D. and location within the solid z (same dimensions as length). the following variables are proposed to affect the process: material density ρ. acceleration due to gravity R. 9. Two systems are geometrically similar when they have the same shape and all linear dimensions of the systems are related by the same constant scale factor. its mass density ρ. and if two systems are mathematically identical.This confirms the two dimensionless groups that govern this system. 163 . 2) The maximum pitching moment cmax (dimensions are ML2/t2) that is developed by the water on a flying boat as it lands is presumed to depend on the following variables: α. This is because knowledge of dimensionless groups gives us insight into the underlying mathematical model for a system. the length of the hull ρ. Determine the dimensionless groups that relate the variables. material thermal conductivity k. time t. and the applied force F. Two flow systems are kinematically similar when the velocities at corresponding points only differ by a constant scale factor (and stream patterns related by a constant scale factor). so it’s off to conduct experiments to find what the actual functionality is for the equation 9.3 Similarity In the motivation and description of rendering equations dimensionless.1 Practice Problems 1) The fundamental frequency n of a stretched string is a function of the string’s length L. material specific heat capacity cp. the mass of the boat L. length in the dimension of heat transfer L. There are two other types of similarity that are important to consider when constructing experimental prototypes: geometric similarity and kinematic similarity. we mentioned the most important reasons for the approach are to be able to correlate data and to be able to “scale up” or “scale down” a process to a desired scope. If two flows are kinematically similar. and represent two dimensionless quantities that affect cmax. they are also geometrically similar. the angle defining the altitude of the boat m. Suggest a set of dimensionless parameters relating these five variables. the radius of gyration of the boat The variables α and β are dimensionless already. the angle made by the flight path of the boat with the horizontal β. the density of the water g.2. they give rise to dynamic similarity.

which must be equal: Solving for the unknown v. we get 53.03 lbm/ft3) flowing past it at a rate of 8.0 meters would occur on the breakwater of the shore at a velocity of 8. as well as the water density and viscosity. Relevant properties that affect drag force include the torpedo diameter. storm waves of amplitude 2. What will the drag on the actual object be? Since the flows are similar. then data measured from a model flow may be related quantitatively to conditions in an experimental prototype. the dimensionless groups should be equal.0 m/s. so Solving for the unknown force. viscosity. cross-sectional area.07657 lbm/ft3. In reality.57x10-4 ft2/s. ρ=64. what is the equivalent model velocity? If the drag experienced by the model is 10 lbf. If the actual torpedo is expected to reach a velocity of 20 knots.9 lbf.69x10-5 ft2/s. If dynamical similarity exists.44 ft/s. we obtain 157 ft/s. ρ=0. For dynamic similarity. what will be the actual torpedo’s drag? 2) You have landed a part-time job doing special effects for a very low-tech independent film and needs a 360:1. flows must be geometrically similar and have all the same values for each independent dimensionless group. μ=1. All dynamically similar flows are kinematically similar (but not necessarily vice versa). all functional dimensionless groups need to be the same. and velocity. We have enough information here to compare Reynolds numbers. according to the following dimensionless group functionality: The full-scale object we wish to use in the field is 12 inches in diameter and will be subject to seawater (μ=1. two flows are dynamically similar when they have force distributions that differ only by a constant scale factor but otherwise related in magnitude and direction. The drag F on an object is related to the diameter of the object and the fluid density. and velocity.58 lbf. Example. At what air velocity should we subject a model that is 6 inches in diameter to have dynamic similarity? For air.More formally.0 scale model of a storm on a seashore. You figure that the variables that will be relevant between the scale model and reality are wave length. 164 . To achieve dynamic similiarity. 9.1 Practice Problems 1) A 1/6-scale model of a torpedo is tested in a water tunnel to investigate its drag force. amplitude.3. So we subject the model to a air velocity of 157 ft/s and measure its drag to be 5.

thermal conductivity also appears in multiple dimensionless groups. μ. Determine the dimensionless groups that predict the behavior of this process. and acceleration due to gravity. and if in reality a tidal period is 12 hours. what properties would need to be adjusted instead? 165 . cp. Is there a set of extrinsic properties you can adjust so that the process is mathematically similar? If so. velocity. period.) What should be the size (amplitude) and speed (velocity) of the waves in your model? If you need the model for time-lapse footage. k. ρ. what is the tidal period for the model? 3) Fluid under turbulent flow with a velocity v inside a pipe of diameter d is subject to heat transfer through the pipe wall. The heat transfer coefficient h is a function of the variables d. what are they? If not. (Experience with analysis suggests using length and acceleration as the core quantities for best results. Suppose you want to predict the heat transfer behavior of a fluid whose viscosity is twice that of water. This is a rare case where you will want viscosity to be a core quantity. and v.

Conduct statistical analysis on experiments with repeated trials to make meaningful observations and conclude with useful results. we are nearly ready to put all of our knowledge to work in a series of laboratory-based experiments. 1st edition. but instead we work on developing our understanding with a working theory. and ethics. and provide one last set of statistical tools as they related to your design of experiments. 166 . but rather whether or not the experimental results are consistent with the hypothesis.3 of Navidi’s Principles of Statistics for Engineers and Scientists. we are talking about scientific theory. or an accurate and predictive description of a phenomenon.10 The Scientific Method and Experimental Design Recommended for Further Consideration: Sections 9. professional literature. a theory is a hunch or an idea. Note also that theory has distinctly different meanings in non-technical and technical writing – in “plain” English.1 The Engineering Method and the Scientific Method The scientific method is a common staple to science projects. 10. technical communication. etc.. here. Here we will motivate the experimental work we will be doing in the coming weeks. It is a formal distillation of the process of scientific inquiry: Formulate a question (What are you trying to learn?) Formulate a hypothesis based on that question (Based on current experience. Design an experiment with specific intentions for manipulating certain inputs and replicating trials. Very rarely in science do we stumble upon a new scientific law. or any other statistics text.1-9. especially those that incorporate “science fair”-style projects. Armed with considerable ability to perform numerical computation and statistical analysis. what do you expect to happen?) Develop an experimental plan (What will you do to explore the hypothesis? What data do you need?) Predict the result (What results correspond to the hypothesis being correct or incorrect?) Conduct the experiment (How should data be collected? How much data is enough?) Compare prediction to experiment (Analyze data) Form a conclusion (Statistically interpret your data) Use conclusion to inform new hypotheses (and the cycle starts again!) Note that the conclusion of a scientific experiment is not that the hypothesis is correct or not. Chapter Goals Describe the differences and interconnectedness between the scientific method and the engineering method. The rest of this course is heavily focused on three different elements: experimental design.

so that there is an actual difference between “rejecting” and “failing to reject” the hypothesis. and the result is often a disjoint or incoherent experiment. but instead of seeking to learn about a scientific theory. clear and consistent communication is critical for interacting with customers or clients. In the majority of your time in the chemical engineering curriculum. communication is critical and should be required at every step of the way.Meanwhile. In engineering design. for clearly and concisely sharing information with co-workers. Evaluate the solution (test the prototype). For example. we are trying to address a given problem or need: Identify and define goals and constraints. let’s look at each step of the scientific method in more detail. What is the goal of this exploration? What are you trying to learn? This seems like a relatively simple step. from technical procedures to laboratory notebooks to formal reports. An “observation” type hypothesis usually seeks to classify a system (or compare multiple systems) when conditions cannot be changed. A “manipulation” type hypothesis is usually a statement about the way a system will change when something else happens. technicians. the engineering method is similarly cyclical. Model the solution (create a prototype). The hypothesis needs to be something that makes sense statistically. and others. With that in mind. you will spend considerable time on engineering design. not just opinion. but for the remainder of this course we will work on fostering an appreciation for the scientific method. a plant will grow faster if it is watered more often. it should be a single question (don’t try to ask multiple different things at once). but it can be easily overlooked. Further. In other words. the “generate ideas” step of the engineering method depends on scientific inquiry. There are several ways to write a valid hypothesis. there are more pine trees in Michigan than Maryland. Formulate a hypothesis (or hypotheses) based on that question. you should be able to defend your choice in question with a rational argument. This communication can take on many forms. The question helps you to focus your efforts. because you can less often disprove a negative) statement with a clear direction (indication of causality). it’s perfectly fine for the hypothesis to be wrong. The engineering and scientific methods are related largely by the way engineering methods rely on science to inform decisions. for having detailed records for patents. and a novel question (in the case of cutting-edge scientific research). clear and consistent communication is necessary for the reliable repetition of an experiment. Use solution to inform the goals and constraints of the problem (and the cycle starts again!) In both engineering and scientific methods. Refine the solution. management. This hypothesis must be testable – there must be some experiments you can conduct to draw a meaningful conclusion. but perhaps two that are especially applicable to our course: hypotheses that center around manipulation and those that focus on observation. Finally. In scientific experiments. This should be a precise and concise statement – much narrower than the question you posed. Select the best approach (sometimes informed by simulation). 167 . Formulate a question. Your hypothesis is usually a “positive” (as opposed to negative. For example. an important question (someone should care to know the answer). With that in mind. Generate ideas (through research and brainstorming).

Have a plan for proper treatment of outliers – if you can document what is clearly a mistake. Predict the result. How many different values of manipulated variables should you test? How many times should you repeat a trial? If you are investigating a “manipulation” type hypothesis. What data analysis is appropriate for this experiment? How will you communicate the data and results for this experiment? There are lots of options as far as plots go (scatter plot? With or without curve fitting? What kind of curve fitting? How do you display parameters? Bar chart or histogram? How do you express statistical error?). so you must decide which way to interpret it. why not? What went wrong? What other information would you need to be able to answer them? Can you use your findings to inform new hypotheses? 168 . and of the independent variables. be precise. It’s also possible that you need more sophisticated statistical tools at your disposal – we will cover a few more in the rest of this chapter. When considering potential experiments. (See Jeter and Donnell. what are the characteristic quantities?) This is where a lot of the statistical analyses from Chapters 3-0 come into play. Does the experiment as described provide all the relevant data that you need? Running through this “thought experiment” (and documenting it!) can be important in revising your experiment before it is actually run. Carefully collect your data and document all observations. How do you know when you are “done” with the experiment? Were there deviations from your plan? What? Why? Make sure you have notes regarding all actions and decisions. What do you expect to happen when you conduct this experiment? What might the data look like? In particular. it must be included in your data analysis. what would data that supports your hypothesis look like? Be specific. Conduct the experiment.) Be sure to collect enough data. The second most important aspect of that plan (or design) is also safety.14. you have a rationale for its exclusion in your report. If there are chemical. Compare prediction to experiment. How do you portray independent/manipulated variables versus dependent ones? What units make sense? (Does it make sense to do dimensionless quantities? If so. be sure to consider what data you will need to evaluate the hypothesis. If no mistake appears to be made for a data point. or perhaps a table is more appropriate. Form a conclusion. Chapter 2. or other hazards possible. basic lab safety is always in effect – appropriate eye protection and closed-toe shoes are worn and long hair is tied back. which ones can be manipulated in your efforts to explore their effects. do you have a control? How will you know your data is reliable? The most important aspect of any experimental plan (or engineering design) is safety.Develop an experimental plan. What can you say about your hypothesis? It is quite possible that there will be multiple ways that you can interpret your data. action must be taken to mitigate potential risks. There must be a rational basis for this choice. You should be able to identify which variables are dependent and independent. Your experimental plan should include careful consideration of equipment needed for the experiment and the methods required to conduct those experiments. temperature. if any? At a bare minimum. and be quantitative. How does your data relate to other references? What did you learn from this experiment and why is it important (why should we care?)? If you cannot answer these questions. outlier or not. Have you fully identified all hazards associated with your plan? Have you found Material Safety Data Sheets for all chemicals that will be used in the lab? What dangers do those chemicals pose.

computing this test statistic is more complicated than before. A one-factor experiment is an experiment where only one system variable is manipulated over a range of values. Enter Analysis of Variance (abbreviated ANOVA). In a completely randomized experiment. First we must compute the mean square between samples and the mean square within samples. we must be able to assume that each sample is from a normally distributed population. which we’ll discuss when we get into experimental design. we can conduct statistical analysis on these samples. we would consider each treatment as a representation of a population of results with that treatment. We can’t specify which means are different without turning to other statistical analysis. The test statistic for the ANOVA test is the ratio of two variances. and has the same variance as every other sample. but it’s just as likely that we want to compare more samples than that. In order to use ANOVA. the dependent variable.2 One-Factor Experiments Experiments are often conducted to investigate the effect that one or more quantities have on some outcome. If the null hypothesis is rejected. The quantities that are varied in an experiment (the manipulated variables) are called factors. the null and alternative hypotheses are H0: All population means are equal.3 Analysis of Variance (Multi-Sample Test for Means) We’ve discussed hypothesis testing for one and two samples. For an ANOVA test. The result. The question addressed by a one-factor experiment is whether varying the level of the factor results in a different mean response. while the mean square within is a measure of variance for an individual sample: 169 . and the observed responses as a random sample of that population. is independent from every other sample. a technique used to test claims involving three or more means.10. However. and the question that often arises concerns the differences in these samples: are the means for the levels actually different? If so. Ha: At least one population mean is different from the others. Therefore. so we will use the F-distribution again. all one-way ANOVA lets us conclude is that not all the means are the same. The experiment is often repeated several times (these are officially referred to as replicates) for specific values of that manipulated variable (these are officially called treatments or levels). which ones are different? 10. The mean square between is a measure of the variance due to differences among the different samples. of each trial of an experiment is the response variable or outcome variable.

which mean is different? There are two tests we’ll consider here (and you only have to conduct one of them). if one of the means is statistically significantly different than the others. Then we have to compute the test value. As mentioned. If there is little to no difference among the means. so F = 4. si is the standard deviation for sample i. However. 30. Example. where N is the sum of the sizes of all samples. Each researcher chooses to run the experiment individually.f.D = 18 − 4 = 14.9/3 = 183.where k is the number of samples (sets of trials) and N is the sum of the sizes of all samples (total number of all trials). You should find that MSW = 608/14 = 43. the hypotheses are H0: μA = μB = μC = μD Ha: At least two means are different. Their data is below.3. 38. since we’re using the F-distribution. 23. 30. There is enough evidence at the 95% confidence level to suggest that at least one mean is different than the others.f. and x-double-bar is the grand mean of this data – the mean of the sample means xi. By this line of thinking. we reject H0. xi is the mean of sample i.f. so F will be close to 1 and we fail to reject the null hypothesis (which.05 to determine whether the means are the same or not. and d. 41. recall. is that there is some difference among the means). it’s apparent that ANOVA tests are always right-tailed F-tests. 44 C: 40. 29 D: 21. We’ll follow the same general five steps as before. all ANOVA tells us is whether all population means are equal or not. 18. 37. The degrees of freedom for the numerator is equal to k − 1. Usually we want to know a little bit more than that – for instance. MSB will be large and we can reject the null hypothesis. The sum of samples between is simply the mean square between before dividing by k-1.05. you don’t really have a factor to test . The test statistic F is then the ratio of the mean square between to the mean square within: F=MSB/MSW.4 and MSB = 549. Therefore.instead we would just do a two-sample test on the mean from back in section 5.3. 24 Run an ANOVA test with α = 0. and we reject H0. 28. Four researchers are trying to measure the time it takes a fluid flow experiment to reach steady state. we have α = 0. The degrees of freedom for the denominator is N − k.1. In order to determine which mean is different.22. 36. They want to make sure their data at least has the same mean value. Solution. 170 . or we could implement a strategy given on the next page. ni is the sample size of sample i. where k is the number of samples. we can look up the critical value Fc = 3. but afterward they consider putting all their data together. then MSB will be about the same as MSW. Note that if there are only two samples. while the sum of samples within is the mean square within before dividing by N-k. we need values for d.D.N and d. Again. 30. For this test. if F is greater than a critical value Fc. A: 34.N = 4 − 1 = 3.f. we could resort to conducting six different two- sample tests for the mean. From here. 24 B: 47.34 and we’ll reject H0 if F > Fc. d. all we know is one mean is statistically different than the others. So. If we reject the null hypothesis.

The test statistics are. The critical value for the hypothesis test comes from the Studentized range distribution. Slightly less formally.f. we can except to reject the null hypothesis at confidence level α in the case that 171 . We reject the null hypothesis if q>qc. We reject the null hypothesis if |t|>|tc|. but requires that we introduce yet another probability distribution. for every combination of i and j.The Bonferroni method tests C different null hypotheses simultaneously: H0: μi=μj for every possible combination of levels i and j. The null hypotheses are still posed simultaneously: H0: μi=μj for every possible combination of levels i and j. we can except to reject the null hypothesis at confidence level α in the case that The Tukey-Kramer method is also popular. Slightly less formally. The critical value is from the q-distribution with d. The test statistics are. which requires two degrees of freedom values much like the F-distribution. The critical value is from the t-distribution with N-1 degrees of freedom but using α/(2C) instead of just α.f.D=N-k degrees of freedom and confidence level α.N=k and d. for every combination of i and j.

The F value is the ratio of MSB to MSW. Each column corresponds to a different material (factor). In this case. and the “error” are the “within” values. anova1(trials).975 Total 1767 19 The “columns” in the above table are the “between” values. both methods will arrive at the same conclusion for differences in sample means. 260 265 273 264. but MATLAB helps to suggest which might be the case with a box and whisker plot: 172 . SS stands for Sum of Squares and MS stands for Mean Square. and the rows represent repeated trials (replicates). trials=[250 263 257 253. which means at least one of the four samples has a different population mean than another one. 264 254 279 258.8 3.87 0. The results of these hypothesis tests allow us to state with statistical certainty that there is a difference between two sample means (and therefore.0294 Error 1023. 239 267 277 273].6 16 63. Example (from Navidi) The following MATLAB script runs a one-way ANOVA on an experiment where four different welding materials are tested for their hardness (using the Brinnell scale).In general. ANOVA will not tell us which samples are different. The results in MATLAB are below: Source SS df MS F Prob>F ----------------------------------------------- Columns 743. and the Prob value is the probability that we fail to reject the null hypothesis. Notice that MS is just the SS divided by the degrees of freedom. two different levels of the one-factor experiment).4 3 247. we can probably safely reject the null hypothesis. 256 267 269 262. since the probability is so small.

Their data is below. determine which treatment have different results (if you use MATLAB. it provides a way to do this graphically with little additional effort). and C below) and experimentalists have already run several trials on each of the three techniques. Percentage of light blocked by treated water samples Treatment A Treatment B Treatment C 8 4 6 6 7 5 7 8 6 8 6 6 8 3 7 9 9 6 11 7 5 Using 1-Factor Analysis of Variance. 10. determine the level of confidence with which we can say that any one treatment is statistically significantly better or worse than the others. If there is some difference among the treatments.1 Practice Problems 1) The Fictitious Chemical Company is testing a new procedure for extracting algae from a water bath and has chosen to measure its effectiveness by how much light can pass through various samples of treated water. 173 .3. 280 275 270 265 260 255 250 245 240 1 2 3 4 Next we would have to use the Bonferroni method to conclude that samples 1 and 3 differ. B. The procedure can be run in one of three ways (labeled A.

917.1 199. where all but one factor is held constant throughout both experiments). 675.7 178. Calibration constant.9 194. There are kr levels of the row factor and kc levels of the column factor.4 192. Assume the samples are all independent. 1179.2 0.0 191.0 182. 883. 638 Plant X: 857. 786. can we conclude that any one group is statistically different than the other? You may assume the density of the fluid is 1.1 0. s Group 2 time.4 Two-Factor Experiments and Two-Way Analysis of Variance As you might expect.003821 188.3 192.3 208. 695. 1153. A two-factor experiment requires collecting data for all combinations of the two factors (which we are stating here because it’s different than performing two separate one-factor experiments. Using one-way analysis of variance.2 205.003723 184. In a two-factor experiment. It greatly simplifies the math. mm2/s2 Group 1 time.003650 193. we then seek to determine the effects of the factors. a two-factor experiment is one in which two factors are considered simultaneously. Armed with a two-factor experiment and its results. s 0. it’s perhaps even more important that all sample sizes for each treatment combination are the same.0 3) The maximum hourly emissions (in μg/m3) of SO2 from four power plants are listed below. 891. 2) Three groups of scientists have been tasked with experimentally determining the absolute viscosity (dimensions mass per length-time) of a new synthetic fluid for use in heat exchangers.003579 206.8 187.0 182. experimental results are collected by row factor and column factor inside a table. There are therefore krkc different combinations of the two factors – and all of these combinations must be considered in order to have a complete design. 619.1 0. In order to compactly and clearly display the results of a two-factor experiment. The row effect for each row will indicate the degree to which that row’s level tends to produce 174 . With what probability can we conclude the emissions are not all the same among the plants? Plant W: 438.003689 191. and the time it takes to flow through the tube is recorded. 1014. s Group 3 time. Conducting a two-factor experiment may reveal interactions between the two independent variables in an experiment (where two one-factor experiments would not). 732.003880 179.4 187. 1053 Plant Y: 925. and we will only consider that case here.2 0.7 200.003559 201. 786 Plant Z: 893.000 g/cm3.4 0. 595 10. A sample of the fluid is heated to 40 degrees C and placed inside a tube called a viscometer.2 177.6 0.

and grand mean. For any level i of the row factor. The row effects. the combined effects of a row level and column level cannot be determined from their individual effects. we have three separate null hypothesis to test – instead of just concluding that the various means are equal. we can now write each treatment mean in terms of the grand mean. First. main effects. The interaction of the row and column levels must also be determined. Likewise. the average of all means μij in the jth column is μ. column means. Based on the definitions above. and interactions.j and as an equation. for a level j of the column factor. the average of all means μij in the ith row is denoted μi. it is said that the additive model applies. of course! In two-way analysis of variance. and interactions: When the additive model does not apply. it looks like this: The population grand mean is simply denoted μ and it is the mean of the means. In the case where all interactions are zero.. How are these values computed? With two-way analysis of variance. 175 . The row and column effects are sometimes called the main effects to distinguish them from the interactions. a bunch of computational definitions: The mean for a specific treatment combination (the ith row and the jth column factors) is denoted μij.outcomes that are larger or smaller than the grand mean. we more specifically seek to make claims regarding the row means. The interaction γij is a slightly more complicated combination of the specific treatment combination. The column effects are written as βj and are the differences between the column means and the grand mean. column mean. As an equation. are the differences between the row means and the grand mean. denoted αi. The column effect for each column does the same for column levels. its row mean. All three formulas are below.

5 77. the probability column is the probability that we fail to reject the null hypotheses.2 87. Example (from Navidi) In MATLAB.8 71. Notice that in MATLAB.7 79.8 72.9 87.5 66.0 76.36 0.0001 Rows 327.33 36 31.4).1 84.3 83. the middle four rows correspond to the same second value.4 66.5496 Error 1125.1 84.7 80. it does not make sense to consider the main effects. with no major contributions from specific combinations of rows and columns. because if the additive model is rejected. but with additional rows to describe the row factor and the interaction: Source SS df MS F Prob>F ---------------------------------------------------- Columns 877.8 89. Next we can look at the row effects and column effects.1 72. Therefore.1 86. each combination of the row and column factor was tested four times.2 83.56 3 292. which means there is a difference in 176 . the matrix of experimental values must be set up in a specific way.6 82.1 77. Therefore.5 83.164 0. trials=[86.8 71. which is the number of repeated values for each combination of the row and column factors. so the first four rows correspond to the same first value of the row factor.7 73.9 77.4 74.521 9. the mean values of the experiment can be deduced from knowing the row and column effects.1 81. This is the probability that we can fail to reject the null hypothesis for interaction.7 84.7 81.98 6 26.5 80.4 86. we fail to reject this null hypothesis and conclude that the additive model holds (is plausible) – that is.02 47 The first part of the table we should look at is the probability value for the interaction. and the final four rows correspond to the same final value.2 83.9 78.5 72.84 0. which is a rather large percentage.14 2 163. anova2(trials.Two-way analysis of variance addresses three main questions: Does the additive model hold? (Are interactions zero?) Is the mean outcome the same for all levels of the row factor? (Are the row effects zero?) Is the mean outcome the same for all levels of the column factor? (Are the column effects zero?) These questions should be addressed in order.9 65.23 0.259 Total 2487.6 77.7 89.6 94.1 78.0101 Interaction 156.9 76. we can reject the null hypothesis for both the row and the column effects. The result is a table similar to that of one- way ANOVA.9]. Each column still corresponds to a factor (now called the column factor).5 63.8 75. In the experiment below. which is rather small in both cases. but each X rows corresponds to the row factor. Again.4 70.57 5.4 72.2 93.7 90.7 85.7 77.9 82. the anova2 function requires a second input.

df_source. Do either the concentration or the duration of the application affect the amount absorbed? 10.df_error) You may consider “testing out” the fcdf function on the ANOVA tables elsewhere in this chapter to make sure you have it right (keeping in mind there will be rounding error). and the location you place the soda (refrigerator versus freezer). the time you have to cool it (30 versus 60 minutes). 10.157 2 ?? ?? ?? Interaction 0. Formal statistical tests to determine which means are statistically different are outside the scope of this course.5).population means based on certain values of the column factor. we quickly start to run into a problem of combinatorics: we’re still going to need replicates. That is. In order to compute the values for the probability column. but we have to show this statistically. use this fcdf function in MATLAB.1 Practice Problem The following is a partial Two-way ANOVA table for the results of an experiment in which a pesticide was applied to a sample at various concentrations and for different lengths of time and then measured to determine the amount absorbed by the sample. (b) Explain whether the additive model is plausible or not.5 Factorial Design Many experiments involve varying several factors. are referred to as a 2p factorial experiments. Such experiments. so how many trials of an experiment are we talking. and we only test three different values (levels) for those factors. Source SS Df MS F Prob>F Concentration 49. Say you have designed a 23 factorial experiment to vary three different factors – the container the soda is in (can versus bottle). generally we restrict ourselves to two levels (“low” and “high” or “-1” and “1”) because the number of experimental trials grows exponentially with the number of factors. 177 . It is hoped that all three factors are independent. not just one or two. as follows: >> prob=1-fcdf(F_value. there are more than two independent variables that might affect a single dependent variable. and there is a difference in population means based on certain values of the row factor.3. to determine the effects of more than two variables? If we have three factors (independent variables).4. but it might be instructional at this point to perform a multiple regression on the data in order to discern trend (see section 7. appropriately.991 2 ?? ?? ?? Duration 19.337 4 ?? ?? ?? Error 6. here. In this case. that is nine trials without even taking replicates into account! When we are varying p factors in an experiment.250 27 ?? Total ?? ?? (a) Complete the above table. Let’s consider an example of investigating the chilling of soda from room temperature. The dependent variable is the temperature of the soda after each experiment.

61. plus the results of three replicates for each combination. I will use “L” to represent “low” (30 minutes. This means it will perform hypothesis tests for individual factors. and cooling time. location = [location location location]. bottle) values of the three factors. The table below shows al the combinations. The MATLAB function for n-way ANOVA is called anovan. 29. 66 60 Fridge Can 60. does not test for the interactions between parameters. T=[64 60 41 27 64 60 43 28 65 61 42 29 65 61 43 29 66 62 43 31 66 62 46 30]. It works mostly like anova1 and anova2. 31 30 Fridge Bottle 64. and can) and “H” to represent “high” (60. 29.{time. 43. time = ['L' 'H' 'L' 'H' 'L' 'H' 'L' 'H'].container}. 62 30 Freezer Bottle 43. 65. container = [container container container]. let’s note that we will have to perform eight different trials (that’s not counting replicates) to account for all combinations of container. 66 60 Fridge Bottle 60. We will change the default settings to allow for this analysis. First. 46 60 Freezer Bottle 28. 61. time=[time time time]. and all multiples of factors. we have to be careful the same way that we were back when we were doing multiple linear regression – we can include the data in any order. freezer. The result is a table like the one below: 178 .'model'. 65. fridge. container = ['L' 'L' 'L' 'L' 'H' 'H' 'H' 'H']. cooling location. 62 30 Freezer Can 41. location = ['L' 'L' 'H' 'H' 'L' 'L' 'H' 'H']. so long as each column corresponds to the same experiment.location. but by default. we will turn to ANOVA to determine if there are statistically significant effects on our dependent variable. anovan(T.As in the past couple of sections. 42. 43 60 Freezer Can 27. Factor (Independent Variable) Response (Dependent Variable) Time (X1) Location (X2) Container (X3) Temperature 30 Fridge Can 64.'full') The anovan function needs to be told to run the “full model” to consider interaction effects. 30 To set this problem up in MATLAB.

f is some unknown function. Mean Sq. 65% confidence). there is interaction between the time and location values. Since we can reject the fourth null with a significance of virtually 0 (i. The next steps include conducting more experiments (to probe more combinations of time and location) and using theory to suggest the form of the function f.5 1 1.e. virtually 100% confidence).08 0 X2 4374 1 4374 2691.69 0 X3 1. the final column gives us the level of significance with which we can reject the null hypothesis. Sometimes there simply is no way to know which model is best. we must fail to reject the null. The conclusion is that the model that best matches the above data is likely of the form where t is time.e.35 (i. d. and right away. Let’s start with Occam’s Razor: 179 . and the statistics used to test the function can contradict one another – meaning if you run each of the accepted methods. Source Sum Sq.f.5 1 1.5 0. 10.351 Error 26 16 1..5 0. 2) There are several accepted methods for choosing a function.351 X2*X3 1. L is the contribution from the location (almost certainly the ambient temperature). what model or equation best describes the relationship between the outcome of an experiment and its independent factors? This is not an easy question. and the a-values are fitting parameters. 3) The proposed factors may not even be related to the outcome – ANOVA can give us some insights. The above results have two important implications: Since we can only reject the third null hypothesis with a significance of 0. So this section of the course packet is going to be a quick and dirty introduction.31 0 X1*X3 1.92 0.5 0..” There are literally entire textbooks devoted to model selection.351 X1*X2*X3 1. I want to point out four things: 1) When there is little or no known physical theory to support an experiment.625 Total 5042 23 As in the case for two-way ANOVA.92 0.5 1 1. the experiment should be repeated to test these insights.6 Model Selection After running ANOVA.5 0.92 0. several different functions will fit experimental data equally well. N-way ANOVA automatically assumes all functions f are the product of the variables. they may each suggest a different model is best. F Prob>F --------------------------------------------------------- X1 486 1 486 299.5 1 1.” but more “suggestions. a common follow-up question is.92 0. but even then.351 X1*X2 150 1 150 92. 4) Choosing a model is not governed by “rules. It’s plausible that soda container has no effect on final temperature.

ANOVA is usually sufficient for developing a model (keeping Occam’s Razor and the other above heuristics in mind as you pick an equation).. It’s hugely important that we rely on theory as much as possible to guide the form of our model. resulting in the “reduced” model To compute the test statics for this null hypothesis. If a product xixj is included in a model. unless there is some physical theory that suggests otherwise. If a power xn is included in a model. Aside from using ANOVA. x. Here are the big ones: A linear model should always contain both a slope and an intercept. same thing) for both models. there is one other hypothesis test I want to show you that can help determine whether a variable can be removed from a model... But as with all suggestions or heuristics. . you will need to compute the sum of squared errors (or SSR. when you do not have any known theory to apply. x2. then the individual variables xi and xj should also be included. Then the test statistic is The critical F-value is found using p-k degrees of freedom in the numerator and n-p-1 degrees of freedom in the denominator.The best scientific model is the simplest model that explains the observed facts. there are known exceptions. 180 . We want to test the null hypothesis If this null hypothesis is valid. plus an intercept) should also be included. then all powers less than that (xn-1. In this course. the model will remain correct if we drop the variables from xk+1 to xp. unless there is some physical theory that suggests there is no intercept. sum of squared residuals. Let’s refer to this as the “full” model. Say that we know the following model with p+1 parameters is known to describe an outcome: where ei is the error or residual for the data point. xn-2. Hopefully by reading those above bullets you noted some repetition. unless there is some physical theory that suggests otherwise. This leads us to the following suggestion for this course: The model equation should contain the smallest number of variables/parameters necessary to explain the data.

- Mathematics Introduction for MScUploaded by34plt34
- Matlab Matrix OperationsUploaded byHuy Phan
- 20090708_Commodities in the if Study UNDP_Cover and Table of ContentUploaded bycsendinf
- R Matrix TutorUploaded byFanny Sylvia C.
- Scilab TutorialUploaded byrak_mishra109
- 1234yuiokpUploaded byPoojitha Surisetti
- 21-29Uploaded byapi-239584927
- 9akk105151d0125 Prioritization ModuleUploaded byWitness Wii Mujoro
- mathematics sd-2016Uploaded byapi-262256068
- 304 MatrixUploaded bybuckk138
- process design dynamics_MatrixUploaded byAbhitej Kodali
- Turkey_A New Method for Noise Elimination From Measured Frequency Response FunctionsUploaded bysumatrablackcoffee453
- Jan 2009Uploaded byPrashant Fegade
- HWsUploaded byLinhHoàngTrương
- Greenbacks or GreenspaceUploaded byMgaster
- Pre - Lab 1Uploaded byM Faizan Farooq
- Chapter 3 Matrices.pdfUploaded byLi Andrew Marcelo
- Semi producto tensorial de matricesUploaded byAarón Castillo Jiménez
- pamelachrissis lesson10 28Uploaded byapi-292276730
- Appendix a-Signals and SystemsUploaded byNeelamAsif
- Basic Mathematics NotesUploaded bysasyeda
- Bai-tap-buoi-4Uploaded byDang Cong San
- 2nd cheapter.docxUploaded byAnuka
- Assign 1 SolUploaded byshu
- mathematics sd-2016Uploaded byapi-262256068
- Amt-142 (Matrices) Unit 1Uploaded byVishal Gupta
- MathematicsSD-2016Uploaded byLullaby summer
- Spru Ill on Finite Difference MethodUploaded byAzis
- AM27Uploaded byKandice Fyffe
- 4 Matrices 2009Uploaded byOmar Danni Ahmad

- PJN3-1000_assy8Uploaded byCharlie CB Portner
- BackRiver_BureauWaterWastewaterUploaded byCharlie CB Portner
- DiffEq.pdfUploaded byCharlie CB Portner
- Lecture_3_AirPollution_v2.pdfUploaded byCharlie CB Portner
- ENCH442_S18_Lecture3.pdfUploaded byCharlie CB Portner
- Environmental organic chemistryUploaded byCharlie CB Portner
- PolymersPlusUserGuideVolume1.pdfUploaded byCharlie CB Portner
- Lecture_2_AirPollution.pdfUploaded byCharlie CB Portner
- Lab Guide 2017Uploaded byCharlie CB Portner
- ENCH442_S18_Lecture2.pdfUploaded byCharlie CB Portner
- GPSS3Uploaded byCharlie CB Portner
- 219800136-Chemistry-and-Technology-of-Rubber.pdfUploaded byCharlie CB Portner
- DiffEqUploaded byCharlie CB Portner
- ENCH442_S18_Lecture1Uploaded byCharlie CB Portner
- Kinetics Solution ManualUploaded byCharlie CB Portner
- Lecture 3 AirPollution v2Uploaded byCharlie CB Portner
- lecture_4_2016.pdfUploaded byCharlie CB Portner
- Determination of Physical Properties of Organic LiquidsUploaded byCharlie CB Portner
- Chemical_Process_Safety_Fundamentals_with_Applications_by_Daniel_A._Crowl__and_Joseph_E_Louvar.pdfUploaded byCharlie CB Portner
- Final Lab Report Group 1 Flow Through Fluidized Beds.docUploaded byCharlie CB Portner
- Kinetic DataUploaded byCharlie CB Portner
- ENCH445-Lecture6.pdfUploaded byCharlie CB Portner
- lecture2_ench445Uploaded byCharlie CB Portner
- 02 Overview of Drinking Water TreatmentUploaded byCharlie CB Portner
- ENCH445-Lecture5-corrected.pdfUploaded byCharlie CB Portner
- Lecture 2 AirPollution Environmental EngineeringUploaded byCharlie CB Portner
- Lecture_2_AirPollution.pdfUploaded byCharlie CB Portner