Chapter Overview: 2: Modeling Basics
Chapter Overview: 2: Modeling Basics
Chapter Overview: 2: Modeling Basics
2: MODELING BASICS
2.1: Verbal Modeling- process description, control specifications, and connections
2.2: Degrees of Freedom- importance, calculation procedure, and examples
2.3: Incidence Graphs -Interpretations, Consistency, and Inconsistency
2.4: Excel Modeling - logical models, optimization with solver for nonlinear regression, sampling random numbers
2.5: Noise Modeling - White, Pink, and Brown Noise, Pops and Crackles
2.6: Numerical ODE solving in Excel- Euler’s method, Runge Kutta, Dead time in ODE solving
2.7: Solving ODEs with Mathematica- How to find numerical and analytical solutions to ODEs with Mathematica
2.8: Fitting ODE parameters to data using Excel- Using regression to fit complex models in Excel
2.9: Helpful Mathematica Syntax- Hints on how to use Mathematica to model chemical processes
This page titled 2: Modeling Basics is shared under a CC BY 3.0 license and was authored, remixed, and/or curated by Peter Woolf et al. via source content
that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.
1
2.1: VERBAL MODELING- PROCESS DESCRIPTION, CONTROL
SPECIFICATIONS, AND CONNECTIONS
Authors: (September 8, 2006) Brian McQuillan, Crystal Miranda, Brandon Quigley, and John Zhang
Stewards: (September 5, 2007) Kevin Luchi, Mike Nappo, Matt Neff, Lisa Schauman
2.1.1: INTRODUCTION
Every process requires a great deal of planning in order to successfully accomplish the goals laid out by its designers and operators. In order
to accomplish these goals, however, personnel that are not familiar with the design must fully understand the process and the functions of
the control systems. Control systems consist of equipment (measuring devices, valves, etc.) and human intervention (plant operators and
designers). Control systems are used to satisfy three basic needs of every process:
1. Reduce the influence of external disturbances
2. Promote the stability of the process
3. Enhance the performance of the process
Verbal modeling is used for creating and also understanding a process control system. Verbal modeling consists of first receiving and then
gathering information about the process. A step-by-step process is then used to describe the control systems used to satisfy constraints and
objectives that have been outlined. In the following sections you will read what requirements are generally outlined for process control and
the step-by-step method used to meet these requirements.
2.1.1 https://eng.libretexts.org/@go/page/22542
1.) Describe the Process
A brief description of the general process is needed while not dwelling on the details and calculations involved. The major steps of the
process, as well as inputs and outputs of the process, should be stated. A simple diagram should be provided detailing the chemical process
to help visualize the process.
2.) Identify Process Objectives and Constraints
The objectives and constraints of the process must be identified before process control actions can be performed.
The process objectives include the type, quantity, and quality of the product that is to be produced from the process. The economic
objectives, such as the desired levels of raw material usage, costs of energy, costs of reactants, and price of products, should also be
identified.
The process constraints include three different categories: operational, safety, and environmental limitations. Operational constraints refer
to the limits of the equipment used in the process. For instance, a liquid storage tank can only hold a certain volume. Safety constraints
describe the limits when the people or the equipment may be in danger. An example would be a pressure limitation on a reactor, which if
exceeded, could result in an explosion. Environmental constraints limit how the process can affect the immediate surroundings. For
example the amount of harmful chemicals that can be released before damage is done to nearby water supplies. All of these constraints
should be mentioned to build a robust control system.
Careful reading of the information provided to you by the customer, management, and government is required in order to properly identify
each constraint and objective. Often times, the process objectives will be very clearly laid out by the needs of the customer or management.
Operational constraints, or the limitations of the equipment being used, must be researched for each piece of equipment used in the process.
Generally, by satisfying the operational constraints a good portion of safety constraints are satisfied as well, but additional safety constraints
may exist and must be investigated by researching company policy and governmental regulations. Environmental regulations also have to
be researched through resources such as the EPA and Clean Air Act. Satisfying the economic aspect is largely determined by manipulating
additional variables after all other constraints and objectives have been met.
3.) Identify Significant Disturbances
Disturbances, in the sense of process description, are defined as inputs or external conditions from the surrounding environment that have
certain properties that cannot be controlled by the plant personnel. Examples of disturbances include ambient air temperature, feed
temperature, feed flow rate, feed composition, steam pressure changes, and cooling water temperature changes. Disturbances can drastically
affect the operation of a unit. A control system should be able to effectively handle all process disturbances. As such, all possible
disturbances must be identified and these disturbances need to be accounted for by the development of contingency plans within the
process.
4.) Determine Type and Location of Sensors
A proper design must ensure that adequate measurements of the system are obtained to monitor the process. To meet this goal, sensors must
be chosen to accurately, reliably, and promptly measure system parameters. Such parameters include temperature, flow rate, composition,
and pressure. Placement of sensors is important both in the usefulness of measurements as well as the cost of the system. Sensors should be
placed such that the measured quantities are appropriate in addressing control objectives.
5.) Determine the Location of Control Valves
Valves must be placed in a location to control variables that impact the control objectives. For example, control of the temperature of a
reactor could be obtained by placing a valve on either the stream of heating / cooling fluids or by placing a valve on the feed stream to the
reactor. One must determine which streams should be manipulated to meet process objectives.
6.) Perform a Degree of Freedom Analysis
2.1.2 https://eng.libretexts.org/@go/page/22542
The degrees of freedom in a system are equal to the number of manipulated streams (determined in step 5) minus the number of control
objectives and control restraints (determined in step 2). A degree of freedom analysis is used to determine if a system is being under- or
over-specified by the process objectives. The degrees of freedom come from the number of knowns and unknowns that are specified within
the system. If there are extra degrees of freedom present in a system, unused manipulated variables can be used to optimize the process. If
there are negative degrees of freedom, a system is over-specified because more objectives and restraints exist than manipulated streams. In
this case, all objectives cannot necessarily be met simultaneously and the least important objectives must be neglected. A system with zero
degrees of freedom is fully specified. All objectives can be met, but there is no room for optimization.
7.) Energy Management
In any system with exothermic or endothermic reactions, distillation columns, or heat exchangers, energy management becomes a factor that
must be accounted for. Heat must be removed from exothermic reactions in order to prevent reactor runaway, and heat must be supplied to
endothermic reactions to ensure desired production rates. Strategies such as pre-heating feed streams with the excess heat from a product
stream are helpful in maintaining efficient usage of energy, however, they also result in more complex processes that may require more
intricate control systems.
8.) Control Process Production Rate and Other Operating Parameters
The production rate can be controlled by a variety of manipulated variables. One manipulated variable may be the feed rate. The plant feed
rate can be changed and each subsequent unit can use its controls to accommodate this change, ultimately resulting in a change in the final
production rate. Other manipulated variables may also include reactor conditions, such as temperature and pressure. Temperature and
pressure affect reaction rates and can be used to alter the final production rate. It is important to choose the most suitable manipulated
variable to control production rate.
In addition to the production rate, other control objectives must be effectively managed by manipulated variables. For example, temperature
of an exothermic reactor may be controlled by the flow of a coolant stream passing over it in order to avoid dangerous high temperatures.
The pressure of a reactor may be controlled by the flow of feed gas in order to comply with the pressure limitations of the vessel.
9.) Handle Disturbances and Process Constraints
The effects of disturbances should be minimized as much as possible, in order to maintain the system at desired conditions and meet all
process objectives and constraints. Feedback or feedforward are specific control techniques and are common ways to overcome
disturbances. A feedback control works by studying the downstream data and then altering the upstream process. The actions executed are
reactive. Feedback can be viewed as an if-then statement: if a feed's temperature is detected to be lower than desired, then steam can be used
to preheat the feed. Feedforward is a more proactive approach in that it adjusts a manipulated variable before the disturbance is felt in the
process. Hence, if a sensor indicates low temperatures upstream of the feed, the feedforward control will counteract the effect of the cooler
upstream temperatures by preheating the feed before the feed temperature is effected. Note that a disturbance must be detectable and
measurable in order for the feedforward control to fix the anticipated disturbance before the system is effected.
Additionally, if constraints are reached during the process, controls should be implemented to avoid safety, operational, or environmental
hazards. This can also be done with feedback and feedforward controls on manipulated variables.
10.) Monitor Component Balances
Every component within a process, whether it is inert or not, should be accounted for at every step of the system in order to prevent
accumulation. This step is more crucial in processes that involve recycle streams. If such a stream is present, a purge stream is often
necessary to remove unwanted components. In addition, component balances are used to monitor yield and conversion or reveal locations in
the process where loss may be occurring. In order to monitor component balances, composition sensors are used.
11.) Control Individual Unit Operations
Most systems used today in industry employ the use of multiple unit operations. Each of these unit operations, however, needs to be fully
controllable in the sense that it has a control system that can adjust manipulated variables in order to maintain other parameters. For
instance, if an absorber is present, the system must be able to control the liquid solvent feed as some ratio to the gas feed. Another example
is a crystallizer. The refrigeration load of the crystallizer must be controllable in order to control the temperature.
12.) Optimize the Process
In most cases, there will be certain aspects of a process that will not be dictated to a designer and can be changed to make the overall
process more economical for the company. These are referred to as "unaccounted for" degrees of freedom and can be implemented as new
control valves or adjustable controller setpoints.
2.1.3 https://eng.libretexts.org/@go/page/22542
Some of the important questions to answer before delving deeper into a model are:
What are the components entering the system?
How do they enter? Separately? Combined stream? What physical states are they in?
What happens inside the unit process and what comes out at each exit point?
Remember to keep this part simple. There is no need to include chemical formulations or equations of any sort. Just lay out the basic flow of
material.
2. Define the primary goal of the process
The primary goal should be simple. Often, it is to maintain a specific measured variable above a minimum or below a maximum. In this
step, the only thing that needs to be determined is what the main goal is, and a few supporting details about why this is an important goal to
achieve.
For example, a primary goal could be to minimize the concentration of Compound Y in orange juice because studies show Compound Y
gives the juice a bad aftertaste.
3. Identify secondary processes that influence the primary goal
In a typical unit process, the primary goal will be directly influenced by one or two other aspects of the system. These can include
temperature, pressure, inlet conditions, and more and can occur at various points in the process.
The goal of this step is to determine which of these other process variables will be most likely to influence the primary goal and to step
down from there.
For example, the temperature of the orange juice mixer could have the greatest influence on production of Compound Y.
4. Identify safety and environmental risks
Next, you need to identify all of the points in the process that represent any type of risk. This will be important later in determining which
system variables need to be monitored.
Step through your process and identify any points that pose a significant risk of the hazards shown in the following figure.
Examples include: Boilers represent fire and explosion risks. Any stream with a dangerous chemical can represent corrosive, poison,
environmental, or all three risks.
5. Identify major costs associated with the process
How much something costs to produce is obviously a big deal in manufacturing. Identifying the largest sources of cost is critical in finding
ways to reduce cost overall. Typical places to start identifying costs are at inlet streams (what is the cost of raw materials) and at any portion
of the process where heat is added or removed.
It is important to include the high costs that can be associated with the risks identified in Step 4. Often the high cost of failure and risk
exposure will determine what other seemingly costly steps must be taken to ensure the safety of the process.
6. Identify variables you can directly manipulate
The basics of the process have been laid out, and now it's important to determine what variables you can actually control. Typically, you
only have direct control over the simplest of variables: switches and valves. Essentially, this just means that you cannot, in fact, choose a
temperature for your system and implement it. What you can do, is control a valve or switch that activates heating or cooling to control the
temperature.
During this step, you must decide where it is important to place these valves and/or switches. Use the information acquired previously about
the primary goal and secondary effects to determine what variables are worth controlling. Remember that you don't need to put valves
EVERYWHERE! Control valves are not costless and can also add unwanted complexity to your system. If you need to isolate equipment,
you can install manual valves. Keep the control valves to the needed level.
7. Identify sources of variation
2.1.4 https://eng.libretexts.org/@go/page/22542
In order to write a control scheme, you need to know what values in your system will change and why. Some common causes of variation
include:
Environment: ambient temperature
Other processes upstream or downstream: variable inlet conditions or outlet demand
Economic forces: product worth, material costs
Operators
Identifying what aspects of your process can be affected by these forces will allow you to assemble a more complete control scheme.
8. Describe your control system in words
Before you start trying to write everything out in computer code and mathematical equations, take the time to lay out your controls in
words. This is much like preparing an outline before writing a paper. It can save you from many headaches later on.
One example of generic, simple syntax for verbal modeling is: Maintain [system variable] at specified level by adjusting [variable I can
control].
2.1.5 https://eng.libretexts.org/@go/page/22542
10) Define control logic
As every process is different, a customized code for each process must be written to tell the system what to do. For example, when a level
control is a tank has reached a critically high point, the logic should spell out the necessary changes needed to bring the tank level back
down. For example, this could be partially closing a valve upstream of the tank or partially opening a valve downstream of the tank.
11) Create redundancy system
In the real world, you must balance cost and efficiency/safety. On one hand, you don't want an out-of-control system if one control fails. But
on the other hand, you can't afford to order two of everything. The critical point to keep in mind is to optimize the safety while minimizing
the cost.
12) Define "fail-safe"
A fail safe is a set up in the control logic to ensure that in the event of a failure of a control method, the system will automatically reach a
safe condition so that there is little to no harm done to other equipment or personnel.
13) Set lead/lag criteria
Valves and other equipment do not necessarily open/close or turn on/off at the exact instant a button is pressed or the control logic kicks in.
There is often lag time associated with each controller. You must determine how long this lag time is so that you can take it into account.
14) Investigate effects of change before/after
Be sure to investigate effects of changing each controller. For example, what are the effects of closing/opening this valve?
15) Integrate all systems
Ensure that all systems are working together and that there are no holes in the system. Make sure that information does not fall through any
cracks in the system.
[Note - we can use an example of the Barkel method - RZ]
== Solution ==
1.) Describe the Process
The purpose of the process is to heat an incoming stream of water from a temperature of 50ºF to a temperature of 80ºF. The main equipment
involved is a shell-and-tube heat exchanger.
2.) Identify Process Objectives and Constraints
2.1.6 https://eng.libretexts.org/@go/page/22542
The product specification of the process is water at a flow of 20 gallons per minute and a temperature of 80ºF.
Economically, the process costs $65 per hour to operate. There are no costs for the raw materials, as the only inputs to the system are water
and steam. The finished product produces a profit of $2 per gallon. The economic objective is to reduce process costs while producing
sufficient product.
The operational constraints and safety concerns are due to the pipes. The pipes can only sustain a temperature of 1000ºF. Safety is a concern
because attempting to heat the incoming water to a certain temperature may cause the heat exchanger to malfunction, leading to equipment
damage and possible burn injuries to nearby personnel. The system may only operate for 12 consecutive hours, after which the system will
need to be cooled down for 4 hours to avoid the aforementioned hazards. A simplified assumption is that there are no constraints on steam
because it is provided by the plant and causes no safety issues. The only environmental constraints involve the incoming water stream. The
incoming water is gathered from the nearby lake, and a stream of greater than 10000 gallons per hour would cause a disturbance in the
equilibrium of the lake.
3.) Identify Significant Disturbances
Significant disturbances can be found in the ambient air temperature, variable flow rates of the feed, and the temperature of the steam.
4.) Determine the Type and Location of Sensors
A flow sensor (FM) is placed at the incoming water stream. A temperature sensor (TS) is located on the product water stream. A flow
sensor is not needed for the steam stream for this problem because this value is not needed for control. A sensor could be placed here but the
information is not needed for this problem.
5.) Determine the Location of Control Valves
A flow valve is placed at the entrance of the incoming water stream. A flow valve is placed at the entrance of the steam.
6.) Perform a Degree-of-Freedom Analysis
There are two manipulated variables: the flow of the water feed stream and the flow of the incoming steam. There are two control
objectives: the flow of the feed stream, monitored by the flow sensor, and the temperature of the product, monitored by the temperature
sensor. Therefore the system has zero degrees of freedom.
7.) Energy Management
The incoming steam is used to transfer heat to the cool water feed. The temperature sensor on the product stream determines the applicable
setting on the steam flow valve.
8.) Control Process Production Rate and Other Operating Parameters
The process production rate is controlled by the flow valve on the entering water stream. The water temperature is controlled by the flow
valve on the incoming steam.
9.) Handle Disturbances and Process Constraints
Changes in the ambient air temperature can be detected by the temperature sensor, and can be corrected by the flow valve on the incoming
steam stream. Variable flow rates of the water feed stream can be detected by the flow sensor and compensated by adjustments on the flow
valve on the water feed stream. Changes in the temperature of the steam can be detected by the temperature sensor. The flow valve on the
steam stream can be adjusted to increase or decrease the flow of steam and subsequently the amount of heat exchanged.
10.) Monitor Component Balances
A vent is located on the heat exchanger to release excess steam from the system. Aside from that, any accumulation is unlikely and can be
neglected.
11.) Control Individual Unit Operations
The outlet temperature of the product stream is controlled by the flow valve on the steam feed stream. The flow of the incoming water
stream is controlled by the flow valve on the water feed stream.
12.) Optimize the Process
One might notice that the process is only using 1,200 gal/hr of water, well below the 10,000 gal/hr environmental constraint. If the profit of
the process is linear with the flow-rate of water, then increasing the flow-rate of water will increase the profits for the company. (With the
constraints specified, this is a Linear Programming optimization problem. The optimal setpoint falls on a boundary condition.) However, the
flow-rate of water entering the system is already specified, which results in zero degrees of freedom. (Zero degrees of freedom implies there
are no further control valves or setpoints.) Further investigation should be conducted to determine the reason for the flow-rate specification.
When considering increasing the flow-rate of water into the system, one should also check that the other constraints are not violated.
2.1.7 https://eng.libretexts.org/@go/page/22542
2.1.8: WORKED OUT EXAMPLE 2
A process converts phenol into salicylic acid through a series of two reactors. Phenol and NaOH are fed in the liquid phase into the
first reactor where it reacts with gaseous carbon dioxide that is pumped in. Assume constant fresh feed temperature and that the
feed flow rate is within operational constraints. Management has dictated that salicylic acid production must be 200 moles per hour.
Also, management would like the product stream to have a molar composition of 80% salicylic acid. Due to environmental
concerns, a maximum flow rate of 10000 gallons per hour of cold water can be used to cool the first reaction chamber. The valve
controlling the flow of cold water does not allow a flow rate in excess of 7500 gallons of water per hour. The salicylic acid product is
used in another process to produce aspirin, which has a market value of $10 per mole. The first reactor can be operated at pressures
up to 200 atm, while the second can be operated at pressures up to 10 atm. The first reaction is exothermic, while the second
reaction is assumed to generate negligible heat. A diagram of this process is shown below, as well as the reaction scheme. Verbally
model this system.
== Solution ==
1.) Describe the Process
The purpose of the process is to convert phenol into salicylic acid, the precursor for aspirin. First, the phenol is reacted with gaseous carbon
dioxide (CO2) and sodium hydroxide (NaOH) under high pressure and temperature in the first reactor. The product of this reaction is then
combined with sulfuric acid to form salicylic acid in the second reactor. The reaction scheme is shown above.
2.) Identify Process Objectives and Constraints
The process is expected to produce 200 moles per hour of salicylic acid. The product stream must contain at least 80% by moles of salicylic
acid. The equipment used in the process dictates the operational limitations. The first reactor vessel can be operated up to a pressure of 200
atm, while the second reactor vessel has a 10 atm upward pressure limit. As such, pressures in excess of these limits must be avoided. Since
the first reactor will generate a significant amount of heat, the heat must be removed to avoid damage to equipment and possible runaway
reactions. Therefore, a heat exchanger (in the form of a reactor jacket in this case) with cool water should be included to decrease the
temperature of the reactor. Economic concerns demand that phenol, sodium hydroxide, and sulfuric acid should not be used in extreme
excess. The costs of these materials and the energy costs required to process them affect the overall profitability, so these compounds should
not be wasted. Environmental regulations limit the use of water to cool the reactor at 10000 gallons per hour, however the valve constraints
limits the amount of water to only 7500 gallons per hour.
3.) Identify Significant Disturbances
The amount of cold water available to cool the reactor can be considered a disturbance because it comes from a reservoir outside of our
control. The ambient temperature is also a disturbance. If it drastically increases, the amount of cold water needed to cool the reactor would
need to increase as well. Composition of the feed streams will be assumed to be constant in this example. Therefore, they are not considered
disturbances.
4.) Determine the Type and Location of Sensors
A temperature sensor (TS) and pressure sensor (P) are located on the stream exiting the first reactor vessel. A flow meter (FM) is located on
the product stream leaving the second reactor. A composition sensor (CS) will also be located on the product stream leaving the second
reactor. The pressure drop can be controlled through the decompressor and thus is a control.
5.) Determine the Location of Control Valves
2.1.8 https://eng.libretexts.org/@go/page/22542
Control valves are located on the feed stream containing the phenol and sodium hydroxide, the incoming cold water to the first heat
exchanger, and the sulfuric acid feed stream. There is also a pump located on the carbon dioxide stream that enters the reactor.
6.) Perform a Degree of Freedom Analysis
There are 3 valves, 1 pump, and 1 decompressor but 5 objectives. This results in zero degrees of freedom. The valve located on the sulfuric
acid feed stream is meant to meet the composition constraint placed on the product stream leaving the second reactor. The valve located on
the feed stream carrying the reactants is set to satisfy production requirements. The valve on the cold water stream is used to maintain
reactor temperature, which satisfies an operational constraint. The pump is to ensure the correct pressure is achieved in the reactor, also
satisfying an operational constraint. The decompresser is to maintain a pressure of less than 10 atm in the second reactor, thus satisfying
another operational constraint.
7.) Energy Management
The heat from the exothermic reaction in the first reactor is transferred to the cold water stream. The hot water stream exiting the reactor
vessel jacket could be used to heat streams on other processes. The second reactor is assumed to generate negligible heat during the
reaction, thus any release of heat from the reactor will be considered safe to release into the environment surrounding the process.
8.) Control Process Production Rate and Other Operating Parameters
The production rate is measured by the flow sensor on the product stream and this signals the control valve on the feed stream through a
feedback mechanism to change the production rate as necessary.
9.) Handle Disturbances and Process Constraints
If the temperature sensor on the reactor exit stream exceeds a certain level due to a diminished cold water supply, the feed stream valve
would decrease the amount of reactants entering the reactor. The amount of feed would also be decreased if more than 7500 gallons per hour
of cooling water were needed, as this is an operational constraint. If the pressure gauge controlling the pump begins to read higher than
allowed pressures, the pump would decrease the flow of the carbon dioxide entering the reactor. Also, if the pressure gauge reads out a
pressure that will be too high for the second reactor, the decompresser will be allowed to disperse more pressure. If ambient air temperature
drastically increases, the temperature sensor would open the cold water valve allowing more cooling water to enter the reactor vessel jacket.
If the composition of the product stream falls below 80 mole percent of salicylic acid, then the valve controlling the sulfuric acid feed would
allow more sulfuric acid into the second reactor to increase the conversion of reactants.
10.) Monitor Component Balances
The composition sensor and flow meter on the product stream leaving the second reactor will account for every species to ensure that there
is no accumulation or loss within the system.
11.) Control Individual Unit Operations
The first reactor vessel's pressure is fully controlled by the pressure gauge and pump system and its temperature is fully controlled by the
temperature sensor which controls the reactant feed valve and the cool water valve. The second reactor's pressure is fully controlled by the
same pressure gauge and the decompresser system, and its temperature will be highly dependent on the amount of cooling water used to
cool the product exiting the first reactor.
12.) Optimize the Process
Since there are no unaccounted degrees of freedom, there are no valves to adjust in order to optimize the process. It should be noted,
however, that if there was no constraint on the composition of the product stream, the sulfuric acid feed valve would have become an
unaccounted for degree of freedom. If this had been the case, the valve could be adjusted to maximize the profit of the process. In order to
maximize the profit, the benefits of having higher conversion and more product would have to be weighed against the increase costs of
using more sulfuric acid feed.
2.1.10: REFERENCES
Luyben, William L., Tyreus, Bjorn D., and Luyben, Michael L. “Chapter 8: Eastman Process” in Plantwide Process Control, McGraw-Hill,
New York, pp. 251-272.
Luyben, Michael L., Tyreus, Bjorn D., and Luyben, William L., "Plantwide Control Design Procedure" in AIChE Journal Dec. 1997, Vol.
43, No. 12 pp. 3161-3174.
Riggs, James B. and Karim, M. Nazmul. “Chapter 17: Multiunit Controller Design” in Chemical and Bio-Process Control, Ferret
Publishing, pp. 491-504.
2.1.9 https://eng.libretexts.org/@go/page/22542
Stephanopoulos, George. Chemical Process Control: An Introduction to Theory and Practice, Prentice Hall, New Jersey, pp. 1-41.
This page titled 2.1: Verbal Modeling- process description, control specifications, and connections is shared under a CC BY 3.0 license and was authored,
remixed, and/or curated by Peter Woolf et al. via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history
is available upon request.
2.1.10 https://eng.libretexts.org/@go/page/22542
2.2: DEGREES OF FREEDOM- IMPORTANCE, CALCULATION PROCEDURE,
AND EXAMPLES
Authors: (13 December 2009) Jon Butler, Matthew J LaVelle
2.2.1: INTRODUCTION
In control engineering, a degree of freedom analysis is necessary to determine the regulatable variables within the chemical process. These
variables include descriptions of state such as pressure or temperature as well as compositions and flow rates of streams.
2.2.2: DEFINITION
The number of process variables over which the operator or designer may exert control. Specifically, control degrees of freedom include:
1. The number of process variables that may be manipulated once design specifications are set
2. The number of said manipulated variables used in control loops
3. The number of single-input, single-output control loops
4. The number of regulated variables contained in control loops
The following procedure identifies potential variables for manipulation.
2.2.4: APPLICATIONS
Single phase systems
All outlet streams have the same composition, and can be assumed to have the same temperature and pressure
Multiple phase systems
An additional (C-1) composition variable exists for each phase
Complete Process
When connecting units which share streams, one degree of freedom is lost from the total of the individual units
2.2.1 https://eng.libretexts.org/@go/page/22365
Figure 1: Blender Schematic
Here, there are 3 streams, each with C+2 unknowns for a total of 3C+6 Unknowns.
We have C mass balances and 1 energy balance for a total of 2C+1 equations. We also know composition, pressure, and temperature for the
incoming streams. This adds 2C+2 to the equation. Putting everything together gives:
Degrees of freedom = 3C+6 - (2C+1 + 2C+2)
Hence, the system has 3 degrees of freedom. Therefore, we can fix outlet composition, pressure, and flow rate. Figure 2 shows an example
control scheme:
2.2.6: REFERENCES
Ponton JW, 1994, Degrees of Freedom Analysis in Process Control, Chemical Engineering Science, Vol. 49, No. 13, pp 1089 - 1095.
eweb.chemeng.ed.ac.uk/courses/control/restricted/course/third/course/formal.html
This page titled 2.2: Degrees of Freedom- importance, calculation procedure, and examples is shared under a CC BY 3.0 license and was authored,
remixed, and/or curated by Peter Woolf et al. via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history
is available upon request.
2.2.2 https://eng.libretexts.org/@go/page/22365
2.3: INCIDENCE GRAPHS -INTERPRETATIONS, CONSISTENCY, AND
INCONSISTENCY
3.1 Introduction
Incidence graphs are useful tools for chemical engineers to model various relationships in a process. They are used to systematically map an
entire chain of processes and controllers to describe the effect, which each element has on the others. This helps to visualize the possible
process pathways or a chain of effects.
Below is an example of an incidence graph. The circles are nodes which represent a particular device or controller, e.g. a temperature
sensor. The arrows indicate the directional pathway of influence. For instance, a temperature sensor node would be connected to an adjacent
node (such as a heat exchanger). This heat exchanger node would in turn be connected to other nodes representing devices or controllers.
This type of diagram could be extremely useful in identifying the redundancies within a control system. A more elaborate application of
incidence graphs will be discussed in the Worked Out Examples section.
2.3.1: MONOTONICITY
Before proceeding to the next few sections, it is imperative to understand the basics of monotone systems. A monotonic function defines a
function that preserves a given order. Monotonic functions are classified as monotonic increasing or monotonic decreasing. Taking the
example of a function f(x), for a monotonic increasing function an increase in variable ‘x’ would result in an increase in f(x). On the other
hand, for a monotonic decreasing function an increase in variable ‘x’ would result in a decrease in f(x).
2.3.1 https://eng.libretexts.org/@go/page/22366
An example of a possible non-monotonic graph
2.3.2.1: TRAVERSING
Every incidence graph establishes a particular way to depict the direct effects of one device on its neighbors. Typically, a line will connect a
node to its neighbors--these lines are terminated by either a bar or an arrowhead.
An arrowhead at the end indicates that the initiator (from which the line is coming) is either increasing the value of the target (where the
arrow is pointing) or simply activating it (turning it on). The context of the connection will determine whether something is being increased
or turned on. For example, it would be illogical to assume that a drop in temperature would cause a temperature controller to deactivate a
pressure controller. Instead, it would be more prudent to assume that the temperature controller would adjust the pressure sensor.
arrowhead bar
A perpendicular bar indicates that the initiating device is either decreasing the value of the target device or inhibiting it (turn off). Note that
these indications are not necessarily strictly followed. Once again, context of the situation determines which interpretation should be used.
perpendicular bar
Graphs consisted of the arrowhead bar and the perpendicular bar allow you to see the result of an increase/decrease in one aspect of the
initial device on a designated device in the system. Everything done after the initial device comes as a result of changing the initial device.
In addition, these graphs provide the possibility of simplifying complicated relationships between devices into one conceptual unit. The
2.3.2 https://eng.libretexts.org/@go/page/22366
relationship between the initiating device and target nodes can be described by the following set --> {initiator,target1,target2,etc}. It is read
as "the increase or decrease in the initiating device affects the target nodes in the following manner... (+ for increase/activate and - for
decrease/inhibit). The initiator can be any device or variable in the system as long as the arrows support the designation. In other words, you
can show the effects of any device on any other device, as long as the pathway is supported by the diagram. There are often multiple routes
that a signal can travel.
2 helpful tips to keep in mind as you interpret an incidence graph:
1. Always travel from tail to head (or source to target) when traversing the graph from the initiating device to the designated device. Keep
in mind that it is possible to have arrowhead and/or perpendicular bars pointing in both directions in between two devices.
2. Arrowhead bars don’t always mean increase as perpendicular bars don’t always mean decrease. Arrowhead bars indicate that the effect of
performing an action to the device at the tail of the bar would yield the same effect to the device at the head of the bar. Penpendicular bars
indicate that the effect of performing an action to the device at the tail of the bar would yield the reverse effect to the device at the head of
the bar.
The following is a simple example of an incidence graph. We will refer to the circles below as “nodes” from this point onward. Nodes are
the selected devices or variables in a control system.
2.3.3 https://eng.libretexts.org/@go/page/22366
The incidence graph indicates:
1. For an order {1,2,3}: you observe {+,-,-}... remember not to count beginning node twice…
2. For an order {1,3}: you observe {+,+}
From the table and graph above, all pathways from node 1 to node 4 yield the same outcome. Node 4 is being decreased.
A consistent graph is made up of only consistent pathways for all possible pathways between any combination of two nodes. The graph
below is an example of a consistent graph.
2.3.4 https://eng.libretexts.org/@go/page/22366
Paths(s) Sign series
1,2,3 (+,+,-)
1,3 (+,-)
3,1,2 (+,-,-)
3,2 (+,-)
1,3,1 (+,-,+)
1,2,3,1 (+,+,-,+)
3,2,3 (+,-,+)
3,1,3 (+,-,+)
3,1,2,3 (+,-,-,+)
Another type of consistent graph is one in which the valves of the system are not dependent on one another for feedback. In other words,
there is no proportion of the output signal from a particular valve of a system is passed to the input of another valve. An example of this
2.3.5 https://eng.libretexts.org/@go/page/22366
would be to consider the following process diagram:
This process is of a distillation column in which the bottom columns collect high intensity liquids and the liquid is removed from a series of
evaporators. The evaporator is a single-effect evaporator equipped with a simple heat exchanger, a separation vessel and a steam jet ejector
to supply the vacuum. The product is then sent to an oven where it is dried and sent to the manufacturer. It is the chemical engineer’s task to
create a consistent incidence graph in which the valves in the diagram do not depend on each other’s feedback. An example of this is below:
Based on the table above, the incidence graph is consistent because the valves are not dependent on one another for feedback.
2.3.6 https://eng.libretexts.org/@go/page/22366
From the table and graph above, all pathways from node 1 to node 4 do not yield the same outcome. Node 4 is being decreased while
simultaneously being increased.
An inconsistent graph is made up of only inconsistent pathways for all possible pathways between any combinations of two nodes. The
graph below is an example of an inconsistent graph.
2.3.7 https://eng.libretexts.org/@go/page/22366
1,4 : (+,-)
Since the three pathways cause the same change to node 4, this sub-pathway is consistent.
All pathways leading from node 1 and to node 2 -
1,2 : (+,+)
1,4,2 : (+,-,-)
Since the two pathways cause different changes to node 2, this sub-pathway is inconsistent.
In this graph there are sub-pathways that are consistent and inconsistent, therefore the incidence graph is partially consistent.
2.3.3.4: SUMMARY
Just because a process is inconsistent does not mean that the desired results cannot be achieved. All it means is that you cannot consistently
achieve the desired results. Take the example of the flow of a final product. In a consistent process, no matter which path is taken, the flow
of the final product will always respond the same, whether desirable or not. In an inconsistent process, changing the path will not always
cause the flow of the final product to change the same way, but rather depends on the path taken.
In all, inconsistent processes are not bad. Often, processes will be very complex, containing many variables, and inconsistent processes will
be unavoidable. Care must just be taken with complex, inconsistent processes to achieve desirable results.
You are a process engineer and you have been assigned to devise a process control for a new reactor. The optimum operating condition for
the reaction inside the reactor is 220 oC ± 10oC. The reaction is exothermic and often goes way past the optimum temperature. It is
imperative that the reaction should not go above 250oC. The reactor has a built in heater (H1) to keep temperature at its optimum
temperature and a cooling water feed to cool the reactor in case temperature goes past 250oC. The reactor also has temperature sensor
installed to monitor the temperature. If temperature goes above 250oC, the desired mechanism is to increase the flow of water in the cooling
jacket surrounding the reactor and to turn off the heating element inside the reactor until it reaches its optimum temperature. As a control
redundancy mechanism, a pressure sensor is also installed inside the reactor. The pressure control will send signal to the cold water feed if
pressure reaches 1.2 atm which is the critical pressure. Draw a causation graph governing the situation when the temperature gets too hot
inside the reactor. Base your graph on the following variables:
Note: (There may be more than one correct solution to the assigned problem)
a. temperature
b. temperature sensor (T1)
c. cooling water feed (V3)
d. heating element (H1)
e. pressure
f. pressure sensor (P1)
2.3.8 https://eng.libretexts.org/@go/page/22366
High temperature will 'activate' the temperature sensor, telling it that the temperature has exceeded the optimal temperature and an action
need to be done to bring it back to the desired temperature. The temperature sensor would then open the valve for the cooling water feed
which would cause the water to flow through the jacket. This results in the temperature inside the reactor to decrease. The reverse happens
for the heating element. An activation of the temperature sensor would translate to an inhibition of the heating element in which the heating
element would stop increasing the temperature of the reactor. Temperature and pressure are directly related by ideal gas law and thus affects
each other in both ways. Thus, for the control redundancy mechanism, an increase in pressure would activate the pressure sensor which
would then activate the cooling water feed to cool the temperature for the reactor.
Logic control:
IF T1 =< 220 oC, THEN H1 is on, ELSE H1 is off
IF T1 >= 250 oC, THEN V2 and V3 is open, ELSE V2 and V3 is close
IF P1 >= 1.2 atm, THEN V2 and V3 is open, ELSE V2 and V3 is close
The level sensor monitors the fluid height inside the jacketed CSTR. Assuming the level inside the reactor is increasing steadily, the level
sensor will send a negative feedback signal to V1 to decrease the input flow.
Logic control:
IF L1 > 30 meters, THEN V1 is closed
IF L1 < 10 meters, THEN V4 is closed
2.3.9 https://eng.libretexts.org/@go/page/22366
Solution:
All relationships are consistent. Each variable 1,2,3,4 has a simple relationship which is monotonic among the other variables in the set.
Paths(s) Sign series
{1,2} (+,-)
{1,2,3} (+,-,-)
{1,3} (+,-)
{1,4,3} (+,+,-)
{1,4} (+,+)
{2,1} (+,-)
{2,3} (+,+)
{2,1,3} (+,-,+)
{2,1,4} (+,-,-)
{4,3} (+,-)
2.3.7: REFERENCES
Woolf, Peter (2006). A Mini-Guide to Consistent Graphs.
Woolf, Peter (2006). Terms Review.
Angeli, David & Sontag, Eduardo D. (2003). Monotone Control Systems.
This page titled 2.3: Incidence Graphs -Interpretations, Consistency, and Inconsistency is shared under a CC BY 3.0 license and was authored, remixed,
and/or curated by Peter Woolf et al. via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is
available upon request.
2.3.10 https://eng.libretexts.org/@go/page/22366
2.4: EXCEL MODELING - LOGICAL MODELS, OPTIMIZATION WITH SOLVER
FOR NONLINEAR REGRESSION, SAMPLING RANDOM NUMBERS
2.4.1: INTRODUCTION
Microsoft Excel program is one of the most popular and useful computer programs for a wide variety of numerical applications. Excel
features several different functions, interfaces and graphing tools which can be applied in many fields. The following functions might be
especially useful for logical programming in Excel:
Logical functions (ex: IF, OR and AND): These functions can be used in control analysis, particularly in safety regulation (for example,
if the temperature exceeds X degrees, shut down the reactor and send cooling water to the jacket)
Solver: This function can be used to maximize, minimize or try to obtain an input value in a cell by varying referenced cells.
Random Number Generator. This can be used as a tool for probability or randomly selecting data points for analysis from a large pool of
points.
While it might be less accurate than other modeling programs, the Excel model provides good estimates, and facilitates observation and
understanding of process behavior while requiring minimum computer knowledge. The following sections will provide you with a better
understanding of these common Excel functions, followed by examples in engineering applications.
2.4.1 https://eng.libretexts.org/@go/page/22367
Additional letter grades could be added by including more nested IF functions inside the existing function. One formula can include up to 7
nested IFs, which means you can return up to 8 different results.
2.4.1.1.2: EXCEL'S OR STATEMENT
The OR statement in Excel is similar to the IF statement. It returns TRUE if any argument or expression of values is TRUE, and it returns
FALSE if all arguments or expression of values are FALSE. The syntax for OR is:
OR(logical1,logical2,...)
logical1: there can be up to 30 arguments for the logical expression to test and return either TRUE or FALSE. If all of the arguments are
false, the statement returns FALSE for the entire expression.
Sample coding:
OR(1+1=2, 2+2=5)
In the logical1 part, 1+1 is equal to 2 and will return TRUE. In the logical2 part, 2+2 is not equal to 5 and will return FALSE. However,
since one of the test returns TRUE (logical1), the function returns TRUE even if logical2 is FALSE. TRUE will be output in the
corresponding function cell.
2.4.1.1.3: EXCEL'S AND STATEMENT
The AND statement returns TRUE if all its arguments or values are TRUE and returns FALSE if one or more argument or value is FALSE.
The AND statement syntax is:
AND(logical1,logical2,...)
logical1: similar to OR statement with up to 30 arguments to test that could return either TRUE or FALSE.
Sample coding:
AND(1+1=2, 2+2=5)
Logical1 will return TRUE for the correct calculation while logical2 will return FALSE for the incorrect calculation. However, since one of
the expressions is FALSE, the AND logical test will return FALSE even if one of the tests is true.
It is common and useful to understand how to implement different logical functions into each other. A good example would be:
IF(AND(2+2=4,3+3=5),"Right Calculation","Wrong Calculation")
During iteration, the AND statement should return FALSE since one of the expression/calculation is incorrect. The FALSE return will
output "Wrong Calculation" for the IF statement iteration.
2.4.1.1.4: OTHER USEFUL EXCEL FUNCTIONS
Excel has many useful functions that can help any engineer who is using Excel to model or control a system. An engineer may want to
know the average flow rate, number of times the liquid in a tank reaches a certain level, or maybe the number of time steps that a valve is
completely open or completely closed. All of these situations and many more can be addressed by many of the simple built-in functions of
Excel. Below are some of these functions and a brief definition of what they compute and how to use them. They are followed by an image
of a sample excel file with an example of each function in use. To see a list of all the built-in functions Excel has to offer, click shift-enter
on the cell.
AVERAGE(number1,number2,...) - Returns the average or arithmetic mean of the arguments. The arguments can be numbers, arrays, or
references that contain numbers.
CEILING(number1, significance) - Rounds a number up to the nearest integer or multiple of significance.
CHIDIST(x, degrees_freedom) - Returns the probability of the chi-squared distribution.
COUNT(value1,value2,...) - Counts the number of cells that contains numbers.
COUNTIF(range, criteria) - Counts the number of cells within the range that meet the given criteria.
COUNTIFS(criteria_range1,criteria1,criteria_range2,criteria2,...) - Counts the number of cells within multiple ranges that meet multiple
criteria.
FLOOR(number1,significance) - Rounds a number down toward zero, to the nearest multiple of significance.
FREQUENCY(data_array,bins_array) - Calculates how often a value occurs within a range of values (bins). The function will return a
vertical array of numbers having one more element than the bins_array. Once the formula is entered into the target cell, highlight the target
cell making a vertical array one cell larger than bins_array. Once selected press F2 to open the formula of the target cell and then press
CTRL+SHIFT+ENTER to execute your function.
LARGE(array,k) - Returns the k-th largest value in a data set. For example, the 2nd largest number.
MAX(number1,number2,...) - Returns the largest number in a set of values.
2.4.2 https://eng.libretexts.org/@go/page/22367
MEDIAN(number1,number2,...) - Returns the median of a set of values.
MIN(number1,number2,...) - Returns the minimum value in a set of values.
MODE(number1,number2,...) - Returns the most frequently occurring value in an array or range of values.
PERCENTILE(array,k) - Returns the k-th percentile of values in a range
ROUND(number1, num_digits) - Rounds a number to the specified number of digits.
SMALL(array,k) - Returns the k-th smallest value in a data set. For example, the 7th smallest number.
STDEV(number1,number2,...) - Returns the standard deviation of a given set of values ignoring text and logical values.
SUM(number1,number2,...) - Adds all of the values in a range of cells.
SUMIF(range,criteria,range,...) - Adds values of cells in a range meeting criteria.
VAR(number1,number2,...) - Estimates the variance of a given set of values.
2.4.1.1.5: NESTING
Though not complex or difficult, placing logical statements within one another can be a powerful practice. This is referred to as nesting.
An example demonstrating the use of a simple IF statement nested within another IF statement is shown below:
If one were to ask three individuals whether or not they agree that energy has a velocity, these individual will hypothetically respond in one
of three ways: "Yes","No", or (other). In this case, if the individual were to respond "Yes", then the questioner would respond "I agree!". If
the individual were to respond "No", the questioner would bitterly respond with a "Bah". And if the individual were to respond with a
nonsensical answer, then the questioner would respond "what .." in confusion.
The important point to get out of this example is that nested statements gives us the potential to process more information in one cell (or
line of programming code).
2.4.3 https://eng.libretexts.org/@go/page/22367
2.4.1.2: EXCEL'S DATA ANALYSIS TOOLS
Excel has several useful built in add-ins that can make data analysis much easier. Of these we will cover the solver tool, as well as the
ANOVA analysis.
2.4.1.2.1: SOLVER TOOL
The solver in Excel is a built-in tool with multiple capabilities. It could be used to optimize (find the maximum or the minimum value) a
specific cell (the target cell) by varying the values in other cells (the adjustable cells). It may also be used to solve a system of non-linear
equations. Solver formulas embedded in the spreadsheet tie the value in the target cell to the values in the adjustable cells. The user can also
specify numerical range constraints for the cells involved.
Optimization Model
In optimization, one seeks to maximize or minimize the value of a real function. Just as a student in a calculus class might use optimization
techniques to find a local maxima or minima of a complex function, a CEO might use similar techniques to find how much product their
company should manufacture to maximize profits. There are numerous optimization techniques, many specialized for specific types
problems. For the most part, MS Excel uses gradient-based techniques.
The solver tool is located in the Tools menu. If it does not appear there, it must be added in by selecting Add-ins and selecting the
appropriate check box.
The solver window contains the following fields:
Set Target Cell: This is the cell containing the value you want to optimize.
Equal To: Choose whether to maximize the value, minimize the value, or set it to a specific number.
By Changing Cells: Here you specify all the cells that can be varied when optimizing the target cell value.
Subject to the Constraints: Constraints are optional, but can be added by clicking Add and defining each constraint.
List of Available Constraints
<= (Less than or equal to) Stipulates that a selected cell must be less than or equal to a certain value.
= (Equal to) Stipulates that a selected cell must be equal to a certain value.
>= (Greater than or equal to) Stipulates that a selected cell must be greater than or equal to a certain value.
int (Integer) Stipulates that a selected cell must be an integer
bin (Binary) Stipulates that a selected cell must be equal to 1 or 0.
The window where these constraints can be entered is shown below.
It is important to make sure that constraints do not violate each other otherwise solver will not work without reporting an error. For
example, if a cell must be great than 2 and less than 1 Solver will not change anything.
Once all the fields in the Solver window are completed appropriately, click Solve. If solver can find a solution a window will pop up telling
you so, and the values will appear in the target and adjustable cells. If solver cannot find a solution it will still display the values it found but
will state that it could not find a feasible solution. Be aware that Excel solver is not a powerful enough tool to find a solution to nonlinear
equations, where programs such as Matlab might be a better choice.
* Guided Example: Suppose you have an Excel spreadsheet set up as shown below, with cell C6 depending on cell B6 according to the
quadratic relationship shown, and you want to minimize the value in C6 by varying the value in B6.
2.4.4 https://eng.libretexts.org/@go/page/22367
1) Open up the solver window.
2) Input C6 in the set target cell field, check the min button, and input B6 in the by changing cells field:
Max Time: This is the maximum amount of time excel will spend trying to find a converging value before giving up.
Iterations: This is the number of iterations excel will perform to converge to a value.
Precision: This is related to how close excel has to get before a value is "acceptable." In general, making this value several orders of
magnitude smaller will yield a more accurate result, but will take more time to do so, and may have a harder time converging.
Tolerance: This is also related to how accurate a solution is, this is related to the percent error. Making this smaller should also yield a
more accurate result, but with more difficulty finding a solution.
Convergence: Controls the amount of relative change that occurs during the last five iterations that Solver performs. The smaller the
number of the convergence the less change that will occur.
Box Options Click on the box to select the following options:
Assume Linear Model: This will speed up the time to find a solution because it will make Solver assume that the model is linear.
Assume Non-Negative: Solver will make the lower limit of adjust zero for all the cells that are programmed to be adjusted in the model
that are not limited by a chosen constraint.
Use Automatic Scaling: Used for large differences in magnitude to scale the inputs and outputs.
Show Iteration Results: Solver will pause between each iteration to show the results of that iteration in the model.
Estimates Specifies to Solver on how to use initial estimates for iterations
Tangent: Uses linear extrapolation by utilizing a tanget vector.
Quadratic: Uses quadratic extrapolation. Best to use for nonlinear models.
Derivatives Specifies what type of differencing is used for partial derivatives for both the objective and constraints.
Forward: Constrained values change slowly between iterations.
2.4.5 https://eng.libretexts.org/@go/page/22367
1. Raw data
2. A model equation to find predicted values
3. Initial guesses for varying values
Before using the solver function, the raw data should be organized into separate columns for the independent variable (first column) and
dependent variable (second column). A third column will show the predicted value that is obtained by using the model equation mentioned
earlier, and must reference various single cells that have initial values that Excel will use as a starting point for the regression. A fourth
column should be created with the square of the difference between the predicted value and the actual experimental value (raw data); this is
also known as the square of the residual. A cell at the bottom of this fourth column should include the sum of all the squared difference
values above it. Two more cells anywhere else in the worksheet should be designated as the initial guesses for the values to be varied to find
the solution.
It is important to choose a reasonable value for the initial guess. This will not increase the chance that Excel arrives at a global optimization
rather than a local optimization, but also reduces the time it takes for Excel to solve the system of non-linear equations.
Now, solver can be applied to the spreadsheet to optimize the regression. Refer to section 3.1 for how to access and use solver. The bottom
most cell of the fourth column that has the sum of the squares of the residuals will be the target cell. Since the residuals are essentially the
error, the sum of the residuals squared should be as small as possible, so the min circle should be selected. The initial guesses should be
entered into the "by changing cells". Constraints can be entered if the values of the cells are limited to a certain range. Solver will produce
the values of the varying parameters that yield the best fit to the nonlinear data.
Guided Example: A screen shot of a simple population problem is shown below. The yellow highlighted cells are the initial guesses for
the variables. In this case, the initial population (P0, cell E2) is entered as a constraint.
2.4.6 https://eng.libretexts.org/@go/page/22367
Carlo simulation uses a model that takes random input that follows an assumed distribution (in this case, 70% A and 30% B) and produces
output that models some phenomenon. The following is a simple example of such a simulation:
The Excel is equipped with a random number generator which can be called out using the RAND function. A random number between 0
and 1 can be generated in a cell by the following command:
In Microsoft Excel 2007 the RAND function returns a new random number every time the worksheet is calculated or when F9 is pressed. If
the same random number is needed to be referred to more than once in an Excel IF, AND, OR statement, one can create a column of random
numbers using =RAND(), and refer back to these cells in an adjacent column.
There are many ways to manipulate the random numbers that Excel produces. A random number can be generated within a different range
by multiplying the RAND function by a constant, i.e. multiply by 100 to change a decimal to percent. Another option to generate numbers
within a different range is the RANDBETWEEN function. RANDBETWEEN generates a random integer within a specified range. The
following command generates a random integer between -6 and 21:
It is also possible to modify your random numbers by nesting the RAND function within another function. For example, one can square the
results of one distribution to create a different distribution of numbers.
Another way to utilize the RAND function is to take a random sampling of a data set. If one has a spreadsheet with several hundred data
points, and would like to analyze only 100 random points, another column can be created titled "Random Number" or something similar. In
the first cell of this column, type the =RAND() function. Then drag this function all the way to the end of the data set. At this point, the user
can go to the DATA drag-down menu and select Sort... In this menu, select your random number column in the SORT BY drag down menu.
Either ascending or descending can be selected, as desired. Once the spreadsheet is sorted by the random numbered cells, the first 100 data
points can be used as a statistically random cross-section of the data.
The sort tool can be useful in cases when you are trying to find out the probability of having certain values above a certain threshold. For
example, if the 100 data points that you have represent the temperature variations occurring within a system, you can use sort tool to
determine how many temperature values exceed your threshold. From that, you can calculate approximately the probability of the system
temperature exceeding the threshold. Two screenshots of the sort process are shown below. Microsoft Excel 2007 uses a different menu,
allowing for one to choose between sorting from Largest to Smallest or vice versa. A screenshot below shows this new menu.
Sorting Setup:
2.4.7 https://eng.libretexts.org/@go/page/22367
Results to Randomization:
where T is the absolute temperature, A is the frequency factor, E is the activation energy, and R is the universal gas constant.
It is frequently desirable to be able to predict reaction rates at a given temperature, but first you need to know the values of A and E. One
way to obtain these values is to determine the reaction rate constant at a few temperatures and then perform a nonlinear regression to fit the
data to the Arrhenius equation. Given the following rate constant data for the decomposition of benzene diazonium chloride, determine the
frequency factor and activation energy for the reaction.
2.4.8 https://eng.libretexts.org/@go/page/22367
−1
(s ) (K)
0.00043 313.0
0.00103 319.0
0.00180 323.0
0.00355 328.0
0.00717 333.0
Solution: The following Excel file contains a solution to the problem that uses Excel's solver tool to perform the nonlinear regression and
determine the values of A and E:
Example 1
The spreadsheet is set up as described in the nonlinear regression section above.
1. Open solver (Tools / Solver)
2. Set the Sum of Residuals Squared value cell as the target cell
2.4.9 https://eng.libretexts.org/@go/page/22367
4. Set Pre-exponential Factor and Activation Energy as the adjustable cells. For this problem, keep A between 1E+13 and 1E+14 s^-1 and E
between 9.5E+4 and 1.05E+5 J
5. Sometimes, depending on what version of excel you are using, a message will come up like the one below. If this happens, click OK. The
graph will update with the new curves.
6. Click Solve and observe the values of A and E calculated by Solver and the changes to the plot showing the rate constant as a function of
temperature.
NOTE: If solver is not fitting the data well, click the options button in the solver window and make the precision value smaller by several
orders of magnitude.
2.4.10 https://eng.libretexts.org/@go/page/22367
greater than 0.4, the logic test will return TRUE and then output "Reacts" as the result. Assuming that the random number generator
produces an even distribution between 0 and 1, the random number will be greater than 0.4 sixty percent of the time. Coding of the IF-
statement is shown:
On the other hand, if the number generated is less than 0.4, the logic test returns FALSE and "Does not React" will be shown as the result.
Different numbers are generated each time the spreadsheet is updated, thus different result will return for the IF function. You can also
modify the numbers and return statement to better understand the operation of the functions.
The number of reactions is summed up and divided by the total number of trials to compare the predicted reaction probability with the value
given in the problem. It can be seen by comparing sheets one, two, and three that increasing the number of trials decreases the variation in
the predicted reaction probability.
2) On the left side panel you will see a section labeled "Add-ins". Select this.
3) Here you will see a list of "Inactive Applications" that are available for excel. Of these the ones we are interested in are the "Solver Add-
In" and the "Analysis ToolPak." Select one of these and click "Go" at the bottom of the window.
2.4.11 https://eng.libretexts.org/@go/page/22367
4) A new window will appear asking you which components of the package you would like to install. Select the needed tools (solver and
analysis toolpak). Click "Ok" and windows should install the corresponding tools into excel.
5) Once done, these tools will be found under the data section of Excel, on the far right of the window.
2.4.1.8: REFERENCES
1. =RAND()
=RANDBETWEEEN(-6,21)
Collision Example Excel File:
=IF(B6>=0.4,"Reacts","Does not React")
Bender, E.A. An Introduction to Mathematical Modeling, Mineola, NY: Dover Publications, Inc.
Fogler, H.S. (2006). Elements of Chemical Reaction Engineering, Upper Saddle River, NJ: Prentice Hall Professional Technical
Reference. ISBN 0-13-047394-4
2.4.12 https://eng.libretexts.org/@go/page/22367
Microsoft, Excel, Proprietary EULA, www.microsoft.com.
This page titled 2.4: Excel Modeling - logical models, optimization with solver for nonlinear regression, sampling random numbers is shared under a CC
BY 3.0 license and was authored, remixed, and/or curated by Peter Woolf et al. via source content that was edited to the style and standards of the
LibreTexts platform; a detailed edit history is available upon request.
2.4.13 https://eng.libretexts.org/@go/page/22367
2.5: NOISE MODELING - WHITE, PINK, AND BROWN NOISE, POPS AND
CRACKLES
2.5.1: INTRODUCTION
Noise is all around us in all sorts of forms. In the common use of the word, noise refers to sound. However, noise can more accurately be
thought of as random variations that are always present in one or more parts of any entity such as voltage, current, or even data. Rather than
thinking of noise only as an acoustic term, it should be thought of more as a random signal. Noise can be the inherent fluctuations in some
part in a system (ie. temperature at a given point) or it can be the unavoidable interference on a measurement from outside sources (ie.
vibrations from a nearby generator blur measurements from a pressure transducer). The static interference on your radio, the ‘snow’ on your
television, and the unresolved peaks on an infrared spectroscopy report are all examples of noise.
Chemical engineers can use statistical properties to characterize noise so they can understand a current process or develop an optimal
process. By characterizing the noise and determining its source, the engineer can devise methods to account for the noise, control a process,
or predict the path of a system. For example, when chemical engineers design plants, they use characterizations of noise to determine the
best control scheme for each process. Mathematical modeling can be used to characterize and predict the noise of a given system. In
modeling, to simplify the representation of general trends that reoccur, noise is classified in two major categories: frequency based and non-
frequency based. Frequency based noise consists of the colors of noise, and non-frequency based noise includes pops, snaps and crackle.
The purpose of the following sections is to give you a qualitative understanding of the sources of noise and how it can be characterized and
handled. Examples will be given to help you gain a quantitative understanding of how noise relates to controlling and modeling chemical
engineering processes.
2) Drift noise is correlated to time, and has random movement. Examples of drift noise can include fouling or catalyst decay, in which the
potency of the substance may decline over time as decaying occurs. Stock price fluctuations also model somewhat like drift noise.
2.5.1 https://eng.libretexts.org/@go/page/22368
3) Shot noise may be defined as sporadic and short bursts of noise, in which the amplitude is similar among the bursts of noise. Shot noise
can be correlated to pops (see #Pops below), in which at random times, the same shot noise is witnessed with the same amplitude. Examples
of shot noise include partial clogging or jamming in the process in which the same amplitude will be seen by the noise whenever the
clogging or jamming in the process occurs. Another example is customer demand of the product. If the control system (when trying to
optimize it) depends on the customer order, and customer demand is not consistent at all times (meaning downtimes for orders) but the order
amount is the same when orders are placed, then it will be effected by the shot noise described by the customer order (customer demand).
1
The more add/subtract cycles of RAND() you use, the closer approximation you'll get for a Gaussian distribution
of random errors.
As you would see these in an Excel file:
\ A B C D
1 Time Gaussian Noise Drift Noise Shot Noise
2 1 original value original value original value
3 2 = $B$2 + RAND() - RAND() + RAND() - RAND() = C2 + RAND() - RAND() + RAND() - RAND() = if(RAND()>0.9, $D$2+[single error value], $D$2)
4 3 = $B$2 + RAND() - RAND() + RAND() - RAND() = C3 + RAND() - RAND() + RAND() - RAND() = if(RAND()>0.9, $D$2+[single error value], $D$2)
Note: These formulas can be extended for any length of time. Longer periods of time are useful for visualizing drift noise.
2.5.2 https://eng.libretexts.org/@go/page/22368
2.5.2.1: COMBINED TYPES OF NOISE
Sensors, processes, demands, etc. often do not behave with simple noise models. However, most noise can be derived from the three general
types of noise. An example of a process with random and shot noise is shown in the thumbnail.
This is a graph of the total daily electricity usage for a plant during a normal operation period. As we can see, there are minor fluctuations
occurring every day, but some days there are large changes of electricity usage. These large changes can be seen as shot noise when the
consumption is viewed on this daily scale.
Possible reasons for the minor fluctuations could be due to electric heaters kicking on and off. Changes in the operation of smaller pumps
can cause these changes in electricity demand.
The large shots could be due to an energy-intensive part of the process that only operates when needed. The positive shots could be due to
this process kicking on and the negative shots could be due to a large process kicking off when not needed.
With this graph, we can say that there is shot noise present with the large changes in consumption, but there is also random noise present
with the minor daily fluctuations. We would not say there is drift noise present because the consumption remains around a constant mean
value and does not drift away from there.
However, the total consumption when viewed from a different scale may show other forms of noise. If we viewed the hourly usage of
electricity on one of the days with shot noise, it may resemble drift noise on the hourly scale.
where β ≥ 0.
Just like colors of light are discriminated by their frequencies, there are different colors of noise. Each beta value corresponds to a different
color of noise. For example, when beta equals zero, noise is described as white and when beta equals two, noise is described as brown.
2.5.3 https://eng.libretexts.org/@go/page/22368
is that it is independent of time. This factor also contributes to the idea that white noise cannot physically exist since it is impossible to have
noise be completely independent of time.
A sample power spectral density chart of white noise is shown below. As can be seen from the chart, the power over all displayed
frequencies is essentially the same, suggesting the PSD is equal to 1.
2.5.4 https://eng.libretexts.org/@go/page/22368
generated by integrating white noise. Interference from outside sources, such as vibrations from nearby machinery or background light, in
instrument readings usually have a brown noise pattern.
Below is a power spectral density chart for brown noise. From the charts of brown noise and pink noise, it can be observed that brown noise
loses power as frequency increases at a much faster rate than that of pink noise.
2.5.5 https://eng.libretexts.org/@go/page/22368
Noise Color Power Spectral Density Fourier Transform Curve Generate Data From Curve
The power of a noise signal is detected at a certain frequency. Then a plot of the log(power) vs. the log(frequency) can be constructed, and
the slope of the line gives the beta value. Following a backward thought process, one can produce a certain color of noise by creating
frequency components which have a value generated by a Gaussian distribution and then scaling by the appropriate beta power of
frequency.
A general method to characterize and model noise is explained below.
1. DATA
Data is what the signal transmits. The signal is dependent on what you are measuring or modeling. The data can be collected, for example, if
you're measuring temperature in a reactor, then your data is the temperature readings from a thermocouple at a certain position in the reactor
over a period of time.
2. CURVES
After you collect the data, you plot the data and find a best fit equation, , for that set of data. A math program can be used to find a best
fit equation. Microsoft Excel can be used for a simple model and programs such as Polymath or Mathematica can be used for more complex
models. A simple equation could be in the form of . The coefficients A and B can be varied to fit the data. Additional terms can
be added for more accurate modeling of complex data. The equation you find can then be used to predict and model future signal noise.
3. FOURIER TRANSFORMS
A Fourier transform is a tool used to convert your data to a function of . In this form, the noise can be more easily characterized. Apply a
Fourier transform to the curve, , you fit to your data to generate a relation for the power spectral density. The Fourier transform can be
performed by a computer depending on the complexity of (or see "Simplifying the Fourier Transform" below). The transform is the
integral shown below.
∞
−jwt
X(w) = ∫ x(t)e dt
−∞
where;
is the equation of the curve to fit the data.
is the exponential form of writing the relation . The j in the second term here indicates that that term is
imaginary.
is the frequency
4. POWER SPECTRAL DENSITY
This value is attained by simplifying and squaring the Fourier Transform. Since the series of simplifications needed are fairly complex, the
resulting power spectral density equation is displayed below.
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
2 2
At this point we attain a numerical value for the PSD at the particular frequency, . These numerical PSD values can be plotted versus
frequency to obtain the PSD chart.
5. CLASSIFICATION OF NOISE
The summation is repeated over and over for different frequencies, . A plot of the PSD vs. frequency, is made with these values. Once
this is done a best fit line is applied to the data points which will give you the characterization relation . Based on this we can
then classify the noise as a color of noise.
2.5.6 https://eng.libretexts.org/@go/page/22368
image from en.Wikipedia.org/wiki/Violet_noise#Violet_noise on 12/11/2008
THE REVERSE PROCESS
Knowing how to convert data to a color of noise is only half the problem. What if we know what type of noise is possible and we need data
from it for a given process? Knowing the noise color means that we know the power spectral density relation to the frequency. From here
onwards we follow the reverse route as that taken to get to the noise color by using the inverse Fourier transform instead.
Inverse Fourier Transform
∞
1
jwt
x(t) = ∫ X(w)e dt
2π −∞
where;
is the equation of the curve to produce future the data.
is the exponential form of writing the relation . The j in the second term here indicates that that term is
imaginary.
is the frequency
We can either use it to produce a curve or, by making a similar simplification as we did for the Fourier transform, to generate data directly.
This reverse process should be trivial to someone who worked through the forward process.
2.5.4.1: POPS
At one end of the extreme of non-frequency noise is what is defined as pops. Pops are infrequent random spikes in noise of approximately
the same amplitude. An example of this would be a loose wire that is usually completing the circuit. However, it randomly disconnects for a
split second and then recompletes the circuit for normal operation. Chemical engineering processes may inherently have pops that are
unpredictable. Safety features can be added to a process, such as pressure relief valves, to handle the pops when they do occur. The
following is an image of what pops might look like in a system:
2.5.7 https://eng.libretexts.org/@go/page/22368
2.5.4.2: SNAPS
On the other end of the non-frequency noise spectrum there are snaps. Snaps are single independent events that occur only once. When a
pencil is bent and it breaks under the force is an example of snapping. Another example would be the snapping of a piece of chalk or
exploding a bomb. The “popping” of one’s knuckles is really snapping since it is an independent event, unless you snap all your knuckles all
at once or one after the other really fast. Just like pops, snaps are unpredictable, and safety features should be added to the system to handle
the snaps. The following is an example of a snap:
2.5.4.3: CRACKLES
In between popping and snapping there is crackling. A very common example for crackling is the sound heard coming from a burning piece
of wood. Like popping, there is a non-frequency or irregularity in which the crackles occur. In addition, there is also an irregularity of the
amplitude of the crackle. In the case of the fire, not only can you not predict when the crackle sound would be heard, but you cannot predict
how loud it will be either. Furthermore, there is a universality condition associated with crackling. Regardless of the scale, the similar
randomness in repetition and amplitude should be observed.
In dealing with this universality condition the concept of a critical exponent arises. For example, if we are looking at the same crackling
effect, S , over a larger period of time the two would have to be equal after scaling the larger one.
T
⟨S ⟩small (T ) = A⟨S ⟩large ( )
B
(1−δ)
) then the rescaling of the size will also be small, say 1 + aδ .
Solving gives
a
⟨S ⟩(T ) = So T (2.5.1)
The exponent a is called the critical exponent and is a universal prediction of a given theory. There are other concepts which are used as a
check for universality for times when the critical exponent cannot be used but the most common one is the critical exponent. The following
is an example of what a crackle might look like in a system:
2.5.8 https://eng.libretexts.org/@go/page/22368
EXAMPLE 2.5.1: CRACKLE
A lead engineer monitoring the instantaneous flow rate of a coolant used to cool an exothermic reactor gathers data set ‘a’ over a 30hr
period. Later on that week he gathers data set ‘b’ for the same coolant flow rate. For both sets of data he determined that the way the
instantaneous coolant flow rate is reacting to the exothermic reactor is optimal to the reaction process. For his records he would like to
represent the noise in the data in a compact form. He wants you to first characterize the noise and then provide any other information,
which will generalize the trend in the data. Once you have completed these tasks, report back to him.
Solution
Each set of data is plotted, Flow Rate vs. Time. The two graphs show crackling trends.
2.5.9 https://eng.libretexts.org/@go/page/22368
Graph for data set 'a'
S0 = 2
this value can be the first value attained or an average of the first 2 or 3 values.
T = 30
Solving for the critical exponent using the relation given above we get;
a = −0.08
Once again we carry out the same calculation for data set 'b'.
< S >= 2.12
S0 = 3
this value can be the first value attained or an average of the first 2 or 3 values
T = 50
2.5.10 https://eng.libretexts.org/@go/page/22368
Solving for the critical exponent using the relation given above we get;
a = −0.08
The similarity of the two critical exponent gives further proof that the data the instantaneous flow rate of the coolant over a period of
time will show crackling.
A chemical engineer is reading flow rates from flow meter. Every 0.1 day for 8 days a reading was taken and the data is given here:
Colors of Noise Example. The data displays the fluctuations from the set flow rate of 3000 liters per hour at a wastewater treatment
plant. The specifications for the plant say that the max flow rate is 6000 liters per hour, or the pipes will burst. Also, the flow rate
cannot fall below 200 liters per hour, or the system will automatically shut down.
The chemical engineer notices that there were some readings close to these limits. It is the chemical engineer’s job to determine if the
readings are accurate flow rates or if there is an error with the flow meter. By characterizing the type of noise, the chemical engineer
can determine the source of the noise and so take appropriate preventative measures. What type of noise is present and what protective
measures should be taken?
Solution
1) Plot data. From the data presented, a flow rate vs. time chart was graphed to gauge degree of fluctuation in the flow rate.
2) Calculate the power spectral density data. Using the simplified integral derived to calculate the power spectral density, a table was
created with the resulting PSD values at varying frequencies. These frequencies were self defined and were chosen to encompass a
broad range. More detailed calculations can be found here: Colors of Noise Example under the worksheet titled “PSD CALC”.
3) Plot the power spectral density. The power spectral density for each frequency was then plotted against the frequency, creating the
power spectral density plot shown below.
4) Characterize the noise. To determine the β value for the data, a linear trend line was taken on the data. This trend line can be seen
in the power spectral density plot above. The slope of this trend line is the β value for the data. In this case, the β=0.023. Since this
2.5.11 https://eng.libretexts.org/@go/page/22368
value is not that of white noise (β=0) nor that of pink noise (β=1), we can say that this noise is somewhere between white and pink
noise.
5) Determine the source of noise.
There are two possible major sources of noise. They are the liquid motion in the pipe and noise in the flow meter caused by itself or
outside sources. Since it is found earlier that β=0.023, the source of noise is probably from the flow meter. It is not from the motion of
liquid in the pipe because liquid motion tends to produce brown noise (β=2).
6) Protective measures that can be taken. Knowing this, a correction can be made on the calculations to determine the actual flow
rate. A full step by step solution can also be found here: Colors of Noise Example under the worksheet titled “Solution”.
2.5.5: SUMMARY
Noise is all around us and is an unavoidable characteristic of monitoring signals. When noise is frequency based, like the colors of noise, it
can be characterized and modeled using mathematical tools. When noise is not frequency based, like pops, snaps, and crackles, it can be
recognized, but ways to model it are still being devised. Characterizing and modeling noise is important for chemical engineers to
accurately handle their data, control processes, and predict future trends.
2.5.6: REFERENCES
Kosko, Bart. “White Noise Ain’t So White”, Noise. ISBN 0670034959
Ziemer, Rodger E. Elements of Engineering Probability and Statistics, New Jersey: Prentice Hall. ISBN 0024316202
Papoulis, Athanasios. Probability, Random Variables, and Stochastic Processes, New York: McGraw – Hill Book Company. ISBN
0071199810
Peebles, Peyton Z. Jr. Probability, Random Variables, and Random Signal Principles, New York: McGraw – Hill, Inc. ISBN 0071181814
Sethna, James P. Crackling Noise, Nature 410, 242-250 (2001). Also available here.
en.Wikipedia.org
This page titled 2.5: Noise Modeling - White, Pink, and Brown Noise, Pops and Crackles is shared under a CC BY 3.0 license and was authored, remixed,
and/or curated by Peter Woolf et al. via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is
available upon request.
2.5.12 https://eng.libretexts.org/@go/page/22368
2.6: NUMERICAL ODE SOLVING IN EXCEL- EULER’S METHOD, RUNGE KUTTA,
DEAD TIME IN ODE SOLVING
Authors: (Presented: 9/8/06 /Date Revised: 9/19/06) Aaron Bennick, Bradley Anderson, Michael Salciccioli
Stewards: (9/5/07) Sean Gant, Jay Lee, Lance Dehne, Kelly Martin
2.6.1: INTRODUCTION
This article focuses on the modeling of ordinary differential equations (ODEs) of the form:
dy
= f(x, y)
dx
In creating a model, a new value y i+1is generated using the old or initial value yi, the slope estimate φ, and the step size h. This general
formula can be applied in a stepwise fashion to model the solution. All stepwise models will take the following general form:
yi+1 = yi + ϕh
The modeling methods discussed in this article are Euler’s method and the Runge-Kutta methods. The difference between the two methods
is the way in which the slope φ is estimated.
yi+1 = yi + f (xi , yi ) h
dy
For demonstration, we will use the basic differential equation dx
= 3x
2
+ 2x + 1 with the initial condition y(0) = 1. If a step size, h, is
taken to be 0.5 over the interval 0 to 2, the solutions can be calculated as follows:
x y_Euler y_Actual Error
y(0) 1 1 0
y(0.5) 1 + [3(0)^2 + 2(0) + 1](0.5) = 1.5 1.875 0.375
y(1) 1.5 + [3(0.5)^2 + 2(0.5) + 1](0.5) = 2.875 4 1.125
y(1.5) 2.875 + [3(1)^2 + 2(1) + 1](0.5) = 5.875 8.125 3.25
y(2.0) 5.875 + [3(1.5)^2 + 2(1.5) + 1](0.5) = 11.25 15 3.75
The y_actual values in this table were calculated by directly integrating the differential equation, giving the exact solution as:
2.6.1 https://eng.libretexts.org/@go/page/22369
quite inefficient because the region of stability is so small that the step size must be extremely small to get any accuracy. In a case like this,
an implicit method, such as the backwards Euler method, yields a more accurate solution. These implicit methods require more work per
step, but the stability region is larger. This allows for a larger step size, making the overall process more efficient than an explicit method. A
second drawback to using Euler's Method is that error is introduced into the solution. The error associated with the simple example above is
shown in the last column. This error can be seen visually in the graph below.
It can be seen that the two values are identical at the initial condition of y(0)=1, and then the error increases as the x value increases and the
error propagates through the solution to x = 2. The error can be decreased by choosing a smaller step size, which can be done quite easily in
Excel, or by opting to solve the ODE with the more accurate Runge-Kutta method.
yi+1 = yi + ϕ (xi , yi , h) h
Where φ(x i, yi , h) now represents a weighted average slope over the interval h .
ϕ (xi , yi , h) = a1 k1 + a2 k2 + … + an Kn
The constants a, p, and q are solved for with the use of Taylor series expansions once n is specified (see bottom of page for derivation). The
resulting set of equations have one or more degrees of freedom. This means that for every order of Runge-Kutta method, there is a family of
methods. Below are some of the more common Runge-Kutta choices.
2.6.2 https://eng.libretexts.org/@go/page/22369
and
p1 = q11 = 1.
Huen determined that defining a and a as 1/2 will take the average of the slopes of the tangent lines at either end of the desired interval,
1 2
accounting for the concavity of the function, creating a more accurate result. When substituted into the general form, we find
1 1
yi+1 = yi + ( k1 + k2 ) h
2 2
k2 = f (xi + h, yi + hk1 )
dy
For demonstration of this second-order Runge-Kutta method, we will use the same basic differential equation dx
2
= 3x + 2x + 1 with the
initial condition y(0) = 1. If a step size, h, is taken to be 0.5 over the interval 0 to 2, the solutions can be calculated as follows:
Figure 1: second-order Runge-Kutta
x k_1 k_2 y_Heun y_Actual Error
y(0) 3(0)^2 + 2(0) + 1 = 1 3(0.5)^2 + 2(0.5) + 1 = 2.75 1 1 0
y(0.5) 3(0.5)^2 + 2(0.5) + 1 = 2.75 3(1)^2 + 2(1) + 1 = 6 1 + [0.5(1) + 0.5(2.75)](0.5) = 1.9375 1.875 -0.0625
y(1) 3(1)^2 + 2(1) + 1 = 6 3(1.5)^2 + 2(1.5) + 1 = 10.75 2.375 + [0.5(2.75) + 0.5(6)](0.5) = 4.125 4 -0.125
y(1.5) 3(1.5)^2 + 2(1.5) + 1 = 10.75 3(2)^2 + 2(2) + 1 = 17 5.375 + [0.5(6) + 0.5(10.75)](0.5) = 8.3125 8.125 -0.1875
y(2.0) 3(2)^2 + 2(2) + 1 = 17 3(2.5)^2 + 2(2.5) + 1 = 24.75 10.75 + [0.5(10.75) + 0.5(17)](0.5) = 15.25 15 -0.25
When compared to the Euler method demonstration above, it can be seen that the second-order Runge-Kutta Heun's Technique requires a
significant increase in effort in order to produce values, but also produces a significant reduction in error. Following Runge-Kutta methods
can be worked through a similar manner, adding columns for additional k values. Below is a graphical description of how slope is estimated
using both Euler's method, and Heun's technique. Observe the increase in accuracy when an average slope across an interval of 0.5 is used
instead of just an initial estimate.
Using the improved polygon method, a2 is taken to be 1, a1 as 0, and therefore . The general form then becomes
Ralston's Method
2.6.3 https://eng.libretexts.org/@go/page/22369
The Ralston method takes a2 to be . Therefore and . It has been determined by Ralston (1962) and Ralston and
Rabinowitz (1978) that defining a2 as will minimize truncation error in second-order Runge-Kutta methods. The general form becomes
with
with
with
2.6.4 https://eng.libretexts.org/@go/page/22369
The integration of k's within other k values suggests the use of a spreadsheet. As with all Runge-Kutta methods, the calculation of values for
the fifth-order version would be greatly assisted through the use of Microsoft Excel.
2.6.6: ERROR
There are two types of error associated with solving ODEs using stepwise approximation methods in Excel. These errors are also present
using other methods or computer programs to solve ODEs. The first, discretization, is the result of the estimated y value that is inherent of
using a numerical method to approximate a solution. Discretization errors, also called truncation, occur proportionately over a single step
size. Truncation error will propagate over extended results because the approximation from previous steps is used to approximate the next.
In essence, a copy of a copy is being made. The accuracy of the next point is a direct result of the accuracy of the previous. Just as the
quality of a second copy is dependant on the quality of the first. This error can be reduced by reducing the step size.
Please see ODE model comparison interactive spreadsheet to better learn how step sizes can influence error.
The second types of errors are rounding errors. These errors are dependent on the computer’s capacity for retaining significant digits. The
more significant digits that a computer can hold, the smaller the rounding error will be.
2.6.6.0.1: ESTIMATING ERROR IN EULER'S METHOD
To mathematically represent the error associated with Euler's method, it is first helpful to make a comparison to an infinite Taylor series
expansion of the term yi + 1. The Taylor series expansion of this term is
2 3 n
′
h ′′
h n
h
yi+1 = yi + f (xi , yi ) ℏ + f (xi , yi ) +f (xi , yi ) +…+f (xi , yi )
2 3 !n
2.6.5 https://eng.libretexts.org/@go/page/22369
When this expansion is compared to the general form of Euler's method it can be seen that Euler's method lacks every term beyond
. These missing terms, the difference between the Euler approximation and an infinite Taylor series (taken to be the true
solution), is the error in the Euler approximation. Mathematically respresenting the error in higher order Runge-kutta methods is done in a
similar fashion.
2.6.6.0.1: ESTIMATING AND MINIMIZING ERROR IN RUNGE KUTTA METHOD
Uniform time steps are good for some cases but not always. Sometimes we deal with problems where varying time steps makes sense.
When should you change the step size? If we have an nth order scheme and and (n+1)th order scheme, we can take the difference between
these two to be the error in the scheme, and make the step size smaller if we prefer a smaller error, or larger if we can tolerate a larger error.
This is fairly simple with Runge Kutta, because we can take a fifth order method and a fourth order method using the same k's. Only a little
extra work at each step.
Another way of estimating error in the Runge-Kutta method is to reverse directions at each step of the advancing solution and recompute the
previous ordinate. By considering the difference between the newly computed previous ordinate and the originally computed value, you can
determine an estimate for the truncation error incurred in advancing the solution over that step. This is a bit more tedious, but does give a
good estimate of truncation error.
dy2
= 4y1 + x, y2 (0) = 2
dx
It should be observed that there is more error in the Euler approximation of the second ODE solution. This is because the equation also has
y1 in it. So there is the error introduced by using the Euler approximation to solve the 2nd ODE, as well as the error from the Euler
approximation used to find y1 in the 1st ODE in the same step!
Exact solutions were again obtained from directly integrating the ODEs: and
Lumping the given flow, concentration, and reaction constant together gives:
dV 1
= 1200
dX 1− X
Since no volume is required for a conversion of zero, the initial condition needed is V(0)=0.
2.6.6 https://eng.libretexts.org/@go/page/22369
Now the information simply has to be entered into Excel. A column for the conversion, X, going from 0 to 0.8 in 0.05 increments is used for
the step size, and the first value, V(0), is known to be zero. To get the volume, simply add the previous volume to the constants multiplied
by the step size and 1/(1-X), or:
1
Vi+1 = Vi + 1200 ∗ 0.05 ∗
1− X
Copying this formula down the column to the final conversion value of 0.8, gives the results shown in the table below:
X V
V(0) 0
V(0.05) 63
V(0.1) 130
V(0.15) 200
V(0.2) 275
V(0.25) 355
V(0.3) 441
V(0.35) 533
V(0.4) 633
V(0.45) 743
V(0.5) 863
V(0.55) 996
V(0.6) 1146
V(0.65) 1317
V(0.7) 1517
V(0.75) 1757
V(0.8) 2057
The final reactor volume obtained is approximately 2057 L. This compares reasonably well to the exact value of 1931 L. The Excel file
used to obtain this solution, along with the exact solution, can be downloaded below.
Example 1
The constants in the general form must be defined. To do this we will employ a second-order Taylor series expansion for yi + 1 in terms of yi
and . This Taylor series is
2
′
h
yi+1 = yi + f (xi , yi ) h + f (xi , yi )
2
Expanding with the chain rule, and substituting it back into the previous Taylor series expansion gives
2
∂f ∂f ∂y h
yi+1 = yi + f (xi , yi ) h + ( + )
∂x ∂y ∂x 2
The next step is to apply a Taylor series expansion to the k2 equation. The applied Taylor series expansion rule is
∂g ∂g
g(x + r, y + s) = g(x, y) + r +s +…
∂x ∂y
2.6.7 https://eng.libretexts.org/@go/page/22369
where O(h2) is a measure of the truncation error between model and true solution.
When this Taylor series expansion result of the k2 equation, along with the k1 equation, is substituted into the general, and a grouping of like
terms is performed, the following results:
∣ ∂f
∣a q ∂f
∣ 2 3
yi+1 = yi [a1 f (xi , yi ) |a2 f (xi , yi )] h [a3 p ∣ s 11 f (xi , yi ) ∂ y ∣ h |O ( h )
∣ 1
Setting this result equal to the substituted general form will allow us to determine that, for these two equations to be equivalent, the
following relationships between constants must be true.
It should be noticed that these three equations, relating necessary constants, have four unknowns. This means that to solve for three
constants, one must first be chosen. This results in a family of possible second-order Runge-Kutta methods.
2.6.10: REFERENCES
"Delay Differential Equation", Wolfram MathWorld, Online: September 8, 2006. Available
http://mathworld.wolfram.com/DelayDifferentialEquation.html
Chapra, Steven C. and Canale, Raymond P. "Numerical Methods for Engineers", New York: McGraw-Hill.
Franklin, Gene F. et al. "Feedback Control of Dynamic Systems", Addison-Wesley Publishing Company.
R. England. "Error Estimates for Runge-Kutta Type Solutions to Systems of Ordinary Differential Equations", Research and
Development Department, Pressed Steel Fisher Ltd., Cowley, Oxford, UK. October 1968.
Call, Dickson H. and Reeves, Roy F. "Error Estimation in Runge Kutta Procedures", ACM, New York, NY, USA. September 1958.
This page titled 2.6: Numerical ODE solving in Excel- Euler’s method, Runge Kutta, Dead time in ODE solving is shared under a CC BY 3.0 license and
was authored, remixed, and/or curated by Peter Woolf et al. via source content that was edited to the style and standards of the LibreTexts platform; a
detailed edit history is available upon request.
2.6.8 https://eng.libretexts.org/@go/page/22369
2.7: SOLVING ODES WITH MATHEMATICA- HOW TO FIND NUMERICAL AND
ANALYTICAL SOLUTIONS TO ODES WITH MATHEMATICA
Authors: Matthew Baumgartner, Olyvia Dean, Viral Patel, Joel Schweitzer, and Eric Van Beek
Stewards: Brian Hickner, Lennard Gan, Addison Heather, Monique Hutcherson
Date Released: September 6, 2006 /Date Revised: September 8, 2007
2.7.1: INTRODUCTION
Mathematica is an advanced mathematics solution program created by Wolfram Research, Inc. One of the most powerful software packages
of its kind, Mathematica is able to easily and conveniently solve complicated mathematical formulae, including differential equations. This
article focuses on the modeling of first and higher order Ordinary Differential Equations (ODE) in the following forms:
dy
= f(x, y) (Basic ODE)
dx
z
dy
= f(x, y) (Higher Order ODE)
dz x
Like all software, Mathematica uses a specific language in order to perform calculations. The names of all functions must be capitalized-
this applies to both mathematical functions (such as Sin and Cos) and built-in functions (such as Plot and DSolve). For this reason it is
common for users to write their own functions in minimized letters. This decreases the chance of overriding or redefining a Mathematica
function. Square brackets always follow function calls, and the function's parameters are always enclosed in curved brackets. For example,
if a user wished to plot sin(x) from x = 0 to x = 1, they would type: Plot[Sin[x],{x,0,1}]. The user must type "Shift"+"Enter" to input the
function. Typing only "Enter" will add a line to the formula. . For full PC keyboards, the “Enter” key on the far right is the equivalent of
“Shift”+”Enter”. If the user does not want to see the output line, it can be suppressed by typing a semi-colon at the end of the expression.
Mathematica also recognizes common mathematical constants such as pi (Pi), Euler's constant (E), and imaginary numbers (I). Note that
these constants must also be capitalized when entered.
Mathematica features two functions for solving ODEs: DSolve and NDSolve. DSolve is used when the user wishes to find the general
function or functions which solve the differential equation, and NDSolve is used when the user has an initial condition. The prompts for the
functions are quite similar. Note: Two equal signs must be used to denote equality in an equation. Using one equal sign assigns a value to a
variable.
Example:
f(x) = 5x2 + 7 This input creates a variable named f(x) that has a value of 5x2 + 7.
f(x) = = 5x2 + 7 This input creates a function f(x) which is defined by 5x2 + 7.
Mathematica will sometimes store user created functions or variables into its cache. This causes some (potentially) correct commands to
output errors. It is recommended to quit the local kernel and reinitialize the commands after any changes to your code.
2.7.1 https://eng.libretexts.org/@go/page/22370
Also, check that every command in the code is being executed. Clearing all the outputs in the cell may be helpful to figure out which
commands had not been executed. This can be done by going to the “Cell” option found on the top and choosing the “Delete All Output”
Example:
OUTPUT IS NOT CLEARED
2.7.2 https://eng.libretexts.org/@go/page/22370
CODE WITH CLEARED OUTPUTS
As seen in the examples, it is easier to troubleshoot and debug your program when it looks less confusing. Clearing the extra outputs helps
you focus on just the code that you have written.
2.7.3 https://eng.libretexts.org/@go/page/22370
Depending on the needs of the user, the functions “ParametricPlot” or “Plot3D” may also be useful. The notation for these functions is the
same as “Plot”.
Here is a simple example of what you would type into Mathematica:
Solution = NDSolve[{y'[x]==y[x]*Cos[x+y[x]],y[0]==1},y,{x,0,30}]
Mathematica will output:
Output[1]= {{y->InterpolatingFunction[ { { 0.,30.} },<>] } }
To plot this function you would type:
Plot[Evaluate[y[x]/.Solution],{x,0,30}]
Note: Remember to type "Shift"+"Enter" to input the function
In the example above, h denotes the step size and the coefficients are determined by the method used. Multistep methods are
expansions of more familiar single-step methods used to solve differentials (i.e. Euler, Runge-Kutta, Taylor). Each of these methods
requires an initial point in order to calculate the following point. Similarily, multistep methods also require initial points in order to solve the
ODE. The number of initial points required depends on which method is used to solve the ODE. Multistep methods typically produce less
error than the single-step methods because of multiple initial points.
In order to determine what method to use one must first find the stiffness of the function.
2.7.4 https://eng.libretexts.org/@go/page/22370
the new solution [4]. In order to solve an ODE using this method, f(t,y) must be continuous and satisfy Lipschitz condition for the y-variable
which states [5]:
for all | h | < ε where B and β are independent of h, β > 0 and α is an upper bound for all β for which a finite B exists
This is a basic form of the Adams-Bashforth method. Note that two initial points are required for this method.
There is another Adams method that requires three initial points. The method is solved the same way, however the equation varies a little bit
and is referred to as the Adams-Moulton Method.
The coefficients/constraints, β can be solved for using knowledge of ODE's and other math tools. It was stated earlier that .
We can let f(t,y) = λy, therefore . We can also let if there is a constant step size and σ represents a polynomial.
Through substitution we find [6]:
We can expand the quadratic using another math identity and ultimately solve for constraints β1 and β2. Another method for solving for
coefficients β1,β2 is mentioned below:
In order to find the coefficient βj one must first use polynomial interpolation to find the polynomial p of degree s − 1 such that:
for
From this the Lagrange formula for polynomial interpolation yields
Now the polynomial p is a locally good approximation of the right-hand side of the differential equation y' = f(t,y) that is to be solved. Now
we must consider the equation y' = p(t) instead. This equation can be solved exactly by simply taking the integral of p.
The Adams–Bashforth method arises when the formula for p is substituted. The coefficients bj turn out to be
s−j 1 s
(−1)
bet aj = ∫ ∏(u + i) du.
(j − 1)!(s − j)! 0 i=1
i≠j
The Adams-Bashforth method is typically used for Linear and Non-liner ODE's with dense systems.
for i ≥ 1
The Gear method, also known as the backward differentiation formulae (BDF, a.k.a. Gear’s formulae) is another multi-step method but is
generally used for multiple equations. In order to use the gear method your function must have a stiffness greater than 500, meaning that the
function is stiff.
As a particular cases, taking for i ≥ 2 and optimizing the remaining coefficients to maximize the accuracy of the resulting scheme
recovers the Implicit Euler method. Taking for i ≥ 3 gives
We now focus on this case in particular. Applying this method to the scalar model problem and assuming constant h and a solution of the
form , we find the following quadratic equation for
2.7.5 https://eng.libretexts.org/@go/page/22370
the two roots of which are given by
− −−−−−− − −−−−−−
− α1 + √ γ(1 + ϵ) − α1 − √ γ(1 + ϵ)
sigma = or
2(1 − Σ) 2(1 − Σ)
2
gamma = α1 − 4α2
Applying the identities, we may expand both roots in terms of powers of h. By our assumed form of the solution, it follows that
.The leading-order term in the expansion in h of (a “spurious root”) is proportional to h. For small h, quickly
decays to zero, and thusmay be neglected. The leading-order terms in the expansion in h of (the “physical root”) resemble the Taylor-
series expansion of the exact solution over a single timestep.
Matching coefficients with the expansion of the exact solution as indicated by underbraces in the above
expression, and applying the definition , we arrive at three equations for to achieve the highest order of
accuracy possible with this form. It is easily verified that satisfy these three equations. The leading-
order error term of this method is proportional to . Thus, over a single timestep, the scheme is “locally third-order accurate”; more
significantly, over a fixed time interval [0,T], the scheme is globally second-order accurate. The resulting method,
is thus referred to as BDF2, and may be viewed as a implicit alternative to AM3 that, for the same number of steps into the past, p =
max(m,n), has reduced order of accuracy but greatly improved domain of stability. Higher-order BDFs may be derived in an analogous
fashion; BDF3, BDF4, BDF5, and BDF6 in particular are found to have excellent stability properties as compared with their AM
counterparts with the same number of steps.
Enthalpy balance
When is the concentration of species a and species b equal? The initial conditions for the reactor are as follows:
T0 = 1
ca0 = 2.0
cb0 = 1.8
tf = 0.2
s = NDSolve[{x'[t] == x[t]^2 - y[t] - z[t]^2, y'[t] == y[t]^3 - x[t] - z[t]^2, z'[t] == x[t] - y[t] - z[t]^2, x[0] == 2, y[0] == 1.8, z[0] == 1},
{x, y, z}, {t, 0.2}]
Plot[Evaluate[{x[t],y[t]} /. s], {t, 0, 0.2}]
2.7.6 https://eng.libretexts.org/@go/page/22370
2.7.6: WORKED OUT EXAMPLE 2
You have been asked to study a semi-batch reactor for the reaction . The rate law is , where k = 2.7. Other
parameters are: initial volume = 5, volumetric flow rate = 0.05, initial concentration of A = 2500. Use Mathematica to create a Conversion
versus Time plot for 100 time units.
1. Mole Balance:
ra V
fracdXdt = −
NA0
2. Rate Law:
3. Stoichiometry:
4. Combine:
If the semi-batch reactor runs for 100 time units, the conversion is about 0.8. This can be seen in the plot below or by running the two
commands that follow into Mathematica.
s = NDSolve[{y'[t] == 2.7 (1 - y[t]) (5 + .05 t)/(2500 y[t]), y[0] == 0.0001}, y, {t, 0, 100}];
Plot[Evaluate[y[t] /. s], {t, 0, 100}, PlotRange -> All]
2.7.7 https://eng.libretexts.org/@go/page/22370
Color Plot: e.g. Plot[Sin[x], {x,0,2Pi}, PlotStyle->Red]. You can also make the plot thick, dashed, etc. e.g. Plot[Sin[x], {x,0,2Pi},
PlotStyle->{Red,Thick,Dashed}]
Insert Legend: e.g. Needs["PlotLegends`"] <--MUST insert this BEFORE your plot command. Plot[{Sin[x],Cos[x]}, {x,0,2Pi},
PlotLegend->{"sine", "cosine"}]
equations governing the situation are: and , where F1 = 2, F2 = 12, V1(0) = 0, V2(0) = 0.
If you write the ODEs in Mathematica by directly substituting in F1 = 2 and F2 = 12, you will have to change the ODEs each time you
change the values of F1 and F2. Below is an example of what the Mathematica equations would look like.
s = NDSolve[{V1’[t] == 8 – V1[t], V2’[t] == 12 – (1/3)*V2[t], V1[0] == 0, V2[0] == 0},{V1,V2},{t,0,10}]
Another option is to define F1 and F2 before your equations, and then call them when solving for your ODEs. This allows you to easily
substitute in new values for your variables without changing the differential equations, and reduces the odds of making simple
computational errors in your ODE in the process. The Mathematica code would look as shown below.
variables = {F1 -> 2, F2 -> 12};
s = NDSolve[{V1’[t] == 4*F1 – V1[t] , V2’[t] == F2 – (1/3)*V2[t], V1[0] == 0, V2[0] == 0} /. variables,{V1,V2},{t,0,10}]
3. Be Aware of the Kernel
The Mathematica Kernel stores all of the information about variable definitions. When you define a variable , the definition is stored there.
The kernel is automatically started when a new Mathematica session is started. You may also start it manually. To start the kernel manually
go to Evaluation -> Start Kernal -> Local. Once the kernel is started and you wish to go back and change a variable definition you must
"Quit the Kernal" before you see the change occur. In order to "Quit the Kernal" you must go to Evaluation -> Quit Kernal -> Local.
Terminating the Mathematica Kernal, erases all of the definitions previously entered. For this reason, after you "Quit the Kernal" and enter
in new definitions for your variables you must re-enter all of your code. The images below show how to "Start Kernal" and how to "Quit the
Kernel."
2.7.8 https://eng.libretexts.org/@go/page/22370
Example:
An example of when you would want to "Quit the Kernal" when using Mathematica for Controls is when you are finding a steady state
point using a PID controller. We start by defining the variables for vset, taui, taud, and Kc. Mathematica solves this equation using the
defined variables and shows that (x->3.9, V->10) is the steady state point. This is shown in the figure 1 below.
2.7.9 https://eng.libretexts.org/@go/page/22370
Figure 1 when you defined Kc even though you have not defined it here.
Figure 3 shows the output once you have "Quit the Kernel" and re-entered the Mathematica code.
Now you see that the definition for Kc has been deleted because the steady state points are in terms of Kc. To find the impact of Kc you can
use this solution.
4. Define functions or formulas that are used often
If you will use a function often and it is not already defined in Mathematica by default, define your own. This can be especially helpful if
you intend repeat the same function multiple times while only changing variables. A scenario where defining your own function could save
you time and error is when comparing P-Fisher's values while keeping the margins constant. Only the variables will change but the function
will remain the same. The new function will only last as long as each session in Mathematica.
To define a function, begin by naming the function followed by an open bracket. List all the variables with an underscore after each name
and separate each variable with a comma. Close the bracket when all the variables have been listed. To let Mathematica know that this is a
newly defined function, after closing the bracket place a semi-colon and equal sign. Now define what the formula is using the variable
names. When you have finished, click shift-enter simultaneously. To test the new formula, start with naming the function and open bracket,
then list all the variables numerical values separated by comma's in the same order that was listed when defining the function. Close the
bracket after all the variables have been listed and click shift-enter simultaneously. The output will be the next line in Mathematica with the
answer.
Example:
It is also possible to use this tool to put equations in terms of unknown variables. To do this begin by defining the function the same way as
before. When plugging in the numerical values of the variables, leave the unknown variables as their variable name. The Mathematica
2.7.10 https://eng.libretexts.org/@go/page/22370
output will provide the answer in terms of the unknown variables.
Example:
5. "Make it pretty"
Oftentimes when people program in any language, they tend to crowd lines, almost as if they were trying to save paper. Well, since this does
not apply when you are typing on a screen, don't worry about it.
Ex) You could write:
vars = {V -> 1000, Cao -> 0.2, UA -> 20000, F -> 2000, DE1 -> 30000, k1 -> 1.0 10^13, DH1 -> 50000, rcp -> 60, R -> 1.987, To -> 500,
Tf -> 500, Tjin -> 500, Fj -> 1000, Vj -> 100, Caf -> 0.2, DH2 -> -192000, DE2 -> 30000, k2 -> 1.0 10^13};
eqns = {Ca'[t] == (Caf - Ca[t]))/V - Ca[t]*k1*Exp[-DE1/(R*T[t])], Cb'[t] == (0 - Cb[t])/V +k1*Ca[t]*Exp[-DE1/(R*T[t])] -
k2*Cb[t]*Exp[-DE2/(R*T[t])], T'[t] == (Tf - T[t])/V + (-DH1/(rcp))*k1*Ca[t]*Exp[-DE1/(R*T[t])] + (-DH2/rcp )*k2*Cb[t]*Exp[-
DE2/(R*T[t])] - (UA (T[t] - Tj[t]))/(V *rcp), Tj[t] == (Fj (Tjin - Tj[t]))/Vj + (UA (T[t] - Tj[t]))/(Vj *rcp), Ca[0] == 0.2, Cb[0] == 0, T[0] ==
500, Tj[0] == 500};
sol = NDSolve[eqns /.vars, {Ca, Cb, T, Tj}, {t, 0, 50}]; Plot[{Ca[t]} /. sol, {t, 0, 50}, AxesLabel -> {t, Ca}, PlotRange -> Full];Plot[{Cb[t]}
/. sol, {t, 0, 50}, AxesLabel -> {t, Cb},PlotRange -> Full];Plot[{T[t]} /. sol, {t, 0, 50}, AxesLabel -> {t, T}, PlotRange -> Full];Plot[{Tj[t]}
/. sol, {t, 0, 50}, AxesLabel -> {t, Tj}, PlotRange -> Full]
but it looks much better if you do this:
These thoughts will hopefully help you later on and make it easier to read your code.
6.) "Check the colors!"
Here is a list of font color that Mathmatica will output for a specific reason.
Local Variables in a certain Font Color
Local variables of Module and With in Green
1. Example:
Function arguments and pattern names in Green (Italics)
1. Example:
Variables made special by use in arguments in Turquoise
Example:
Errors and Warnings in a certain Font Color
Syntax Errors in Purple
Example:
Emphasized Syntax Errors in Dark Red with Yellow Background
2.7.11 https://eng.libretexts.org/@go/page/22370
Example:
Missing arguments in Bright Red
1. Example:
Excess arguments in Bright Red
1. Example:
Possible unwanted assignments in Bright Red
Example:
Unrecognized option names in Bright Red
Example:
Local Scope conflicts in Dark Red with Yellow Background
Example:
Variables that will go out of scope before being used in Bright Red
Example:
Shadowing in multiple contexts in Bright Red
Example:
Other in a certain Font Color
Comments in Light Grey
Example:
Strings in Dark Grey
Example:
Global symbols that have no value assigned in Bright Blue
Example:
2.7.11: REFERENCES
"Adams Method", Wolfram MathWorld, Online: August 5, 2007. Available http://mathworld.wolfram.com/AdamsMethod.html [1]
"Gear Predictor-Corrector Method", Davidson University, Online August 5, 2007. Available
webphysics.davidson.edu/Projects/SuFischer/node47.html [2]
Fogler, H. Scott (2006), Elements of Chemical Reaction Engineering, New Jersey: Pretince Hall PTR. ISBN 0-13-047394-4 [3]
2.7.12 https://eng.libretexts.org/@go/page/22370
"Adams-Bashforth", Pitt Math, Online: September 8, 2007. Available:
www.math.pitt.edu/~sussmanm/2071Spring07/lab02/index.html#AdamsBashforthMethods [4]
"Lipschitz Condition", Wolfram MathWorld, Online: September 7, 2007. Available
http://mathworld.wolfram.com/LipschitzCondition.html [5]
"Adams-Bashforth (AB) Methods", University of California-San Diego, Online: September 7, 2007. Available:
renaissance.ucsd.edu/chapters/chap11.pdf [6]
"Gears Method", University of California-San Diego, Online: September 7, 2007. Available: renaissance.ucsd.edu/chapters/chap11.pdf
[7]
Use the Harvard Referencing style for references in the document.
For more information on when to reference see the following Wikipedia entry.
This page titled 2.7: Solving ODEs with Mathematica- How to find numerical and analytical solutions to ODEs with Mathematica is shared under a CC BY
3.0 license and was authored, remixed, and/or curated by Peter Woolf et al. via source content that was edited to the style and standards of the LibreTexts
platform; a detailed edit history is available upon request.
2.7.13 https://eng.libretexts.org/@go/page/22370
2.8: FITTING ODE PARAMETERS TO DATA USING EXCEL- USING
REGRESSION TO FIT COMPLEX MODELS IN EXCEL
2.8.1: SECTION 8. FITTING ODE PARAMETERS TO DATA USING EXCEL: USING REGRESSION TO FIT
COMPLEX MODELS IN EXCEL
Note: Video lecture available for this section!
Authors: Anthony Campbell, Victoria Cardine, David Hines, Stephen Kerns /Date Revised: 14th September 2007
Stewards: Jeff Byrd, Khek Ping Chia, John Cruz, Natalie Duchene, Samantha Lyu
2.8.1.1: INTRODUCTION
One of the most important abilities of an engineer is to model measured values of a system. Modeling of a system aids in optimizing
objectives, as well as predicting future operations. This can be especially helpful when changes cannot be immediately implemented. In
general modeling terms, a set of data can always fit a set of variables. However, an excessive number of degrees of freedom usually exist,
creating multiple solutions. Therefore, the physical significance of the variables is an important consideration.
As time proceeds, various values may need to be changed to accommodate variations within the system. The following sections will discuss
the use of Microsoft Excel© as a tool to adjust the values of variables given a set of experimental data. The models presented below take
into account the design equations of the system being modeled, and the rate laws, where applicable.
2.8.1 https://eng.libretexts.org/@go/page/22371
In order to use the Solver function, click on Data and then the Solver button in the Analysis box.
NOTE: If using Microsoft Office 2003, the Solver Application can be added by clicking on the "Tools" tab at the top of the screen. The
same directions can be followed after this step.
NOTE: If you receive an error message while trying to access Solver, it may already be added in Excel. Uninstall Solver (by following the
same steps, but unchecking "Solver Add-in") then reinstall it.
2.8.2 https://eng.libretexts.org/@go/page/22371
Define the model that you want to fit to the data
Define the sum of least squares in one of the spreadsheet blocks
In Solver, have Excel minimize the sum of least squares by varying the parameters in the model
Accurate modeling is dependent on two factors; initial values and verifying results.
Initial values: As stated in the introduction, many data fitting problems can have multiple “solutions”. In numerical methods, given a set of
initial parameters the data will converge to a solution. Different initial values can result in differing solutions. Therefore, if the initial values
are not set by the problem statement, multiple initial guesses should be entered to determine the “best” value for each variable.
Verification of curve fit: When fitting a curve to given data points, it is important to verify that the curve is appropriate. The best way to do
this is to view the data graphically. It is fairly simple to use the Chart tool to graph the data points. Adding a trend line will show the
mathematical relationship between the data points. Excel will generate a function for the trend line and both the function and the R-squared
value can be shown on the plot. This can be done by clicking “Options” next to “Type” of trend and checking the empty boxes that are
labeled “Display equation on chart” and “Display R-squared value on chart”.
There are various types of trendlines that can be chosen for your given data points. Depending on the trend that you may see, you might
want to try a few of the options to obtain the best fit. Sometimes the squared residual value will be better for a certain type of trend, but the
trend is not necessarily “correct”. When you have obtained sample data, be aware of the trend you should be seeing before fitting a certain
trend type to the data points (if this is possible). The polynomial trend type gives you the option to change the order of the equation.
Typically, you will not acquire a squared residual value of zero. This value is a simple analysis of the error between the trend line, and the
actual data. Once the function and squared residual values are generated, you can begin to evaluate the generated solution.
During your solution analysis, it is important to check for variables or parameters that may be unnecessarily influencing the data. Excel can
generate a "best" solution, which is not correct due to background calculations or Excel's misinterpretation of the modeled system. To assess
this possibility, you can graph data generated by using the solved for variables against the given data.
Additional information about the Excel Solver Tool can be found in Excel Modeling.
Problem statement:
Suppose water is being pumped into a 10-ft diameter tank at the rate of 10 ft3/min. If the tank were initially empty, and water were to leave
the tank at a rate dependent on the liquid level according to the relationship Qout = 2h (where the units of the constant 2 are [ft2/min], of Q
are [ft3/min], and of h are [ft]), find the height of liquid in the tank as a function of time. Note that the problem may be, in a way, over
specified. The key is to determine the parameters that are important to fit to the experimental surge tank model.
Solution:
The solution with fitted parameters can be found here: Surge tank solution This Excel file contains this scenario, where given the actual data
(the height of the liquid at different times), the goal is to model the height of the liquid using an ODE. The equations used to model h(t) are
shown and captioned. In order to parameterize the model correctly, Solver was used to minimize the sum of the least square differences at
each time step between the actual and model-predicted heights by changing the parameters' values. The model predicts the actual height
extremely well, with a sum of the least squared differences on the order of 10^-5. A graph showing the modeled and actual height of the
tank as a function of time is included as well.
2.8.1.6: WORKED OUT EXAMPLE 2: FITTING A HEATED SURGE TANK MODEL(A HEATED CSTR) PARAMETERS TO
DATA IN EXCEL
Problem Introduction: In this example we will analyze how we can fit parameters used for modeling a heated CSTR to data stored in
Excel. The purpose of this problem is to learn how to vary ODE parameters in Excel in order to achieve a square difference between the
2.8.3 https://eng.libretexts.org/@go/page/22371
calculated and experimental data of zero. Some questions to consider are, “How do I model this? Is this a first order ODE? Are there any
coupled ODE's? How many variables need to be considered?" This example will use an Excel file to help you in this process.
Problem Statement: Download the heated CSTR problem file.CSTR Problem Take the experimental data produced from the heated CSTR
model in the Excel spreadsheet*. You are modeling a heated CSTR. It would be wise and is highly recommended to review both the heated
CSTR problem and a wiki on using Excel's solver.
You know this is a heated CSTR...
2. Numerically solve the ODEs through modifying the given wrong set of parameters.
3. While changing the parameters, use Excel to calculate the error between the calculated model and the experimental data.
4. Use the Excel solver function to solve for some of the parameters to minimize error to less than 5%
5. How would your approach be different if our heat transfer area needed to be as small as possible due to capital constraints? Explain.
6. How would your approach be different if our mass feed rate has to be in the range of 3-3.5 kg/s? Explain.
Problem Solution: The solution with fitted parameters can be found here.CSTR Solution
With the model and data given in the example the error must first be defined. Here there error is the squared residual or [(model observation
at time i)-(data observation at time i)]^2 over (all i).
Chemical engineering intuition must be used to reasonably approximate some variables. In real life we would double check that "parameters
normally known, but erroneous" are correct. (Due to problem constraints, we will assume these are accurate, but a true chemical engineer
would check regardless). We must now modify "parameters often needing fitting". For part 3, we can modify the parameters as shown in the
solution.
2.8.4 https://eng.libretexts.org/@go/page/22371
If we have restrictions on heat exchange area then we should try to fit the "heat transfer coefficient and area" as low as possible. Likewise, if
we have restrictions on feed rate, we must keep this above 4 while fitting other parameters as best as possible to achieve a small error. These
have certain industrial applications as costing of heat exchangers and limitations on mass flow rates need to be modeled before a reactor
design is implemented.
Side Note: The example above assumes a first order rate law. This is not always the case. To change the equations to fit a new rate law, one
must derive a new dCa/dt equation and dT/dt using their knowledge of reactor engineering. Once the new equations are derived write the
formula in an excel format in our dCa/dt and dT/dt column and then drag it to the end of the column. All other columns should stay the
same.
An example of modelling a reaction rate ODE with rate constant and rate order variable parameters:
video.google.com/googleplayer.swf?docId=-4220475052291185071
A copy of the slides can be found here: Unnarrated Slides
A copy of the excel file can be found here: Excel File
2.8.1.8: REFERENCES
Holbert, K.E. "Radioactive Decay", 2006, ASU Department of Electrical Engineering, Online: October 1, 2007. Available
www.eas.asu.edu/~holbert/eee460/RadioactiveDecay.pdf
This page titled 2.8: Fitting ODE parameters to data using Excel- Using regression to fit complex models in Excel is shared under a CC BY 3.0 license and
was authored, remixed, and/or curated by Peter Woolf et al. via source content that was edited to the style and standards of the LibreTexts platform; a
detailed edit history is available upon request.
2.8.5 https://eng.libretexts.org/@go/page/22371
2.9: HELPFUL MATHEMATICA SYNTAX- HINTS ON HOW TO USE
MATHEMATICA TO MODEL CHEMICAL PROCESSES
2.9.1: SECTION 9. HELPFUL MATHEMATICA SYNTAX: HINTS ON HOW TO USE MATHEMATICA TO
MODEL CHEMICAL PROCESSES
Title: Useful functions in Mathematica as pertaining to Process controls
2.9.1.1: INTRODUCTION
Mathematica has many different functions that are very useful for controlling chemical engineering processes. The Mathematica syntax of
these functions is often very complicated and confusing. One important resource is the Mathematica Documentation center, which is
accessed through the program help menu. The Documentation Center provides an extensive guide of every function in the program
including syntax and sample code. A "First Five Minutes with Mathematica" tutorial is also present in the menu, which provides a quick
guide to get started with Mathematica. This article will briefly outline several useful Mathematica functions and their syntax.
In order to have Mathematica calculate your inputs, you must evaluate the cells. Do this by pressing Shift+Enter. This will only evaluate
the current cell that your cursor is located. To evaluate all the cells of a notebook press Ctrl+A, to select all, and then press Shift+Enter.
Parentheses vs. Brackets
Brackets, [], are used for all functions in Mathematica. The only thing parentheses, (), are used for is to indicate the order of operations.
Equality, = vs. ==
The single equal sign (=), is used to assign a value or a function to a variable. The double equal sign (==) is used to set two values equal to
each other, such as solving for a value, or to test equalities. When testing equalities, Mathematica will output 'True' or 'False.'
If you recieve 'True' or 'False' as an output when you are expecting it, you likely used a == somewhere that you should have used a =.
Semicolon Use
Placing a semicolon after a line of code will evaluate the expression; however, there will be no output shown.
Mathematica Functions
All Mathematica functions start with a capital letter, eg. Sin[x], Exp[x], Pi or Infinity.
Assigning and Inserting Variables or Parameters
To assign values to variables, use -> rather than an equals sign. For example,
To insert a set of parameters to a function use /. This symbol applies a rule or list of rules in an attempt to transform each subpart of an
expression.
For example, if you want to enter the above parameters into the expression y = Kc * x + Ca0, enter the following in Mathematica:
Variables are case sensitive. For example, X is different than x. Also, if you define a variable, it will remain defined until you redefine it as
something else or clear it. You can clear a variable, for example, x, by using the Clear[x] command. You can also quit the Kernel, which will
clear all variables.
2.9.1 https://eng.libretexts.org/@go/page/22372
Forcing a Numerical Expression
To force Mathematica into giving a numerical solution, use the function N[expression]. For example,
Another method to do this is to place a decimal place in any of your numbers (i.e. "5." instead of just "5")
2.9.1.3: INTEGRATION
Mathematica can do some very complex integrations with fairly little coding. Integration can be very helpful for many engineering
applications, but when the functions become very complex they become increasingly difficult to integrate. Mathematica will integrate any
function that is possible to integrate.
To integrate a function f(x) the Mathematica, the command is Integrate[].
For an indefinite integral the correct coding is Integrate[f(x),x] where x is the independent variable.
For a definite integral with limits of y and z the correct coding is Integrate[f(x),{x,y,z}]
For example:
We can integrate a function like the one below:
f(x) = Sin(5 * x / 8) * x
We can find the indefinite integral as seen here:
2.9.1.4: SOLVER
Mathematica's Solve function attempts to solve an equation or set of equations for the specified variables. The general syntax is Solve[eqns,
vars]
Equations are given in the form of left hand side == right hand side.
A single variable or a list of variables can be also be specified. When there are several variables, the solution is given in terms of a list of
rules. For example,
When there are several solutions, Solve gives a list of them. For example,
Solve will not always be able to get explicit solutions to equations. It will give the explicit solution if it can, then give a symbolic
representation of the remaining solutions in terms of root objects. If there are few symbolic parameters, you can the use NSolve to get
numerical approximations to the solutions.
2.9.1.5: PLOTTING
Mathematica contains a very powerful plotting interface and this overview will go over the basics of plotting. Using Mathematica's Plot[ ]
function there is a basic syntax to be used:
Plot[function, {variable, variable_min, variable_max}]
2.9.2 https://eng.libretexts.org/@go/page/22372
For example, the command "Plot[y=x, {x,0,10}]" will output a graph of the function y=x for a range of x from 0 to 10.
The function could also be previously defined and then referenced in the Plot [ ] command, this functionality provides a lot of simplicity
when referencing multiple functions and helps prevent a typo from affecting your Plots.
y[x]==x
Plot[y[x],{x,0,10}]
To plot multiple functions on the same plot, use an array of functions using curly brackets { }, in place of the single one:
Plot[{y=x,y=2*x}, {x,0,10}]
Another useful plotting option in Mathematica is the ListPlot function. To use this function, the following formatting should be used:
ListPlot[Table[f(x),{x,min,max}]
This is obviously only the basics, Mathematica provides many more options including colors, legends, line styles, etc. All of these extra
features are well documented at Wolfram's Reference Site.
An additional piece of information: Type the following command on the line after the Plot command to determine the max value plotted. It
will display the number associated with the absolute max of the function within the plotting range.
Max[Last/@Level[Cases[%,_Line,Infinity],{-2}]]
The syntax for solving a list of differential equations is DSolve[{eqn1,eqn2,...},{y1,y2,...},x], while the syntax for solving a partial
differential equation is DSolve[{eqn, y, {x1,x2,...}]. For example,
2.9.3 https://eng.libretexts.org/@go/page/22372
Note that differential equations must be stated in terms of derivatives, such as y'[x]. Boundary conditions can also be specified by giving
them as equations, such as y'[0]==b.
Plotted Solution:
Solutions given by DSolve sometimes include integrals that cannot be carried out explicitly, thus NDSolve should be used. NDSolve finds a
numerical solution to an ordinary differential equation within a specified range of the independent variable. The result will be given in terms
of InterpolatingFunction objects, and thus the solution should be plotted. For example,
Note that a place holder was defined to store the NDSolve solution in order for the solution to be plotted. The general syntax for plotting is
Plot[Evaluate[y[x] /. s], {x, xmin, xmax}], where s is said placeholder. The plot below shows the solution to this example.
There is a PID controller on the valve but is not important in explaining the Mathematica syntax. Consider it just a different way to define
Fin.
Parameters are assumed to be Vset = 10, Kc = 10, tauI = 0.1, and tauD = 1
For this problem the differential equation needs to be modeled with the given parameters in Mathematica. The problem asks what the steady
state of the system is. This is solved for by substituting in a PID expression for Fin (not important in this context), setting the derivatives
equal to zero, and solving for V and Xi(a made up variable for the PID controller). The following Mathematica code does all said things.
2.9.4 https://eng.libretexts.org/@go/page/22372
The final line shows that the steady state values for the problem are V = Vset or 10 units of volume, and Xi (the made up variable for the
PID controller) has a steady state value of 3.9
In this example there is syntax for defining parameters, applying those parameters to equations, setting up equations, and solving equations
for steady state values. There is also syntax for plotting multiple equations on the same graph and how to evaluate multiple functions over
time periods. Overall very useful for solving Controls Engineering problems in Mathematica.
2.9.1.8: MATRIX
It is very simple to create a matrix in Mathematica. Simply pick a name for the matrix (for this example we will use a) then simply enter
each row inside of curly brackets {} with the individual values separated by commas, and the the row separated by a comma. The function
MatrixForm[] will display a matrix in its matrix form rather than as a list of numbers.
EX: a =
MatrixForm[a] displays:
523
7 9 11
8 13 9
You can refer to any specific position in the matrix by using the system:
matrix[[row],[column]]
EX: For the matrix above a[[1],[2]] a value of 2 would be returned.
entered as
2.9.5 https://eng.libretexts.org/@go/page/22372
eq1 = 3*x^2+2y
eq2 = x^2-3*y^2
2. Compute the Jacobian with Mathematica's Derivate function
computed by
Jac =
Jac =
Then call the Eigenvalue function.
Eigenvalues[Jac]
Result: λ={-1.82, 0.85}
The Jacobian can be computed as long as the matrix is square. Many other function types are acceptable when entering eq1 and eq2,
including trigonometric and exponential functions.
2.9.6 https://eng.libretexts.org/@go/page/22372
2.9.1.12: PROBABILITY DENSITY FUNCTION
Often in controls, it is necessary to calculate the probability that a certain event will occur, given a particular known distribution. In these
scenarios, it is helpful to know how to use the built-in probability density function in Mathematica. The syntax for using the probability
density function to calculate the probability of observing a value x for a generic distribution dist is shown below.
PDF[dist,x]
A variety of distributions can be used in conjunction with the probability density function. These distributions include the normal
distribution and the binomial distribution.
Normal Distribution
For a normal distribution with a mean μ and a standard deviation σ, use the following syntax to specify the distribution.
NormalDistribution[μ,σ]
To calculate the probability of observing a value x given this distribution, use the probability density function as described previously.
PDF[NormalDistribution[μ,σ],x]
To calculate the probability of observing a range of values from x1 to x2 given this distribution, use the following syntax.
NIntegrate[PDF[NormalDistribution[μ,σ],x],{x,x1,x2]
For the theory behind the probability density function for a normal distribution, click here.
Binomial Distribution
For a binomial distribution with a number of trials n and a success probability p, use the following syntax to specify the distribution.
BinomialDistribution[n,p]
To calculate the probability of observing a successful trial exactly k times given this distribution, use the probability density function as
described previously.
PDF[BinomialDistribution[n,p],k]
To calculate the probability of observing between a range of k1 number of successes and k2 number of successes given this distribution, use
the following syntax.
NIntegrate[PDF[BinomialDistribution[n,p],k],{k,k1,k2]
Alternatively, binomial distribution can be found using a user defined function. Define the equations as follow: binom[nn_,kk_,pp_]:=
nn!/(kk! (nn-kk)!) pp^kk (1-p)^(nn-kk)
where:
number of independent samples = nn
number of events = kk
probability of the event = pp
To find the odds of getting 5 heads out of 10 coin tosses,assuming the probability of head = 0.5, substitute the values for nn,kk and pp as
following: binom[10,5,0.5]
2.9.7 https://eng.libretexts.org/@go/page/22372
Using the same scenario, but instead for the odds of getting 5 or more heads in the 10 tosses, the function can be used as:
Sum[binom[10,i,0.5],{i,5,10}]
For the theory behind the probability density function for a binomial distribution, click here.
Manipulate a plot:
You can also manipulate a plot. The slider bar lets change the variable n and the plot changes accordingly.
The Mathematica file used to create this example, can be downloaded below.
Manipulate Command Example
For more information regarding manipulate, please see the Wolfram's Reference Site.
[Note - need to add manipulate for the Bode plots - R.Z.]
2.9.8 https://eng.libretexts.org/@go/page/22372
2.9.1.15: PLOTTING LOG-LOG GRAPHS
2.9.9 https://eng.libretexts.org/@go/page/22372
[It would be good to replace this images with actual text - R.Z.]
This page titled 2.9: Helpful Mathematica Syntax- Hints on how to use Mathematica to model chemical processes is shared under a CC BY 3.0 license and
was authored, remixed, and/or curated by Peter Woolf et al. via source content that was edited to the style and standards of the LibreTexts platform; a
detailed edit history is available upon request.
2.9.10 https://eng.libretexts.org/@go/page/22372