Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
CHE 2162 Introduction to Computer Modeling
and Simulation of
Chemical Engineering Systems
Lecture 20
November 11, 2014
Review: 2nd order ODE Example
2nd order ODE requires
two boundary conditions
Note that the second derivative can be written as,
Insertin
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
CHE 2162 Introduction to Computer Modeling
and Simulation of
Chemical Engineering Systems
Lecture 19
November 6, 2014
Eulers Method
Use the tangent line (slope at xn)
to calculate the solution at xn+1
Cant project the solution to far
along the tangent l
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
CHE 2162 Introduction to Computer
Modeling and Simulation of
Chemical Engineering Systems
Lecture 2 August 28, 2014
Evolution of computers
Abacus representing the number is 1,532,786
Evolution of computers
Slide Rule
Evolution of computers
EDVAC(Electroni
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
CHE 2162 Introduction to Computer
Modeling and Simulation of
Chemical Engineering Systems
Lecture 3 September 2, 2014
Bits & Bytes
Start with integers: Any integer (1, 2, 3, 4, 10, etc.) can be represented as
where di represents the integers up to B1 and
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
CHE 2162 Introduction to Computer Modeling
and Simulation of
Chemical Engineering Systems
Lecture 22
November 18, 2014
Symbolic Math
Symbolic mathematics tools allow you to analytically
perform differentiation, integration, simplification,
transforms, an
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
CHE 2162 Introduction to Computer Modeling
and Simulation of
Chemical Engineering Systems
Lecture 24
December 2, 2014
Final Exam: Matrix Arithmetic operators:
+ Plus.
X + Y adds matrices X and Y. X
and Y must have the same
dimensions unless one is a scala
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
CHE 2162 Introduction to Computer Modeling
and Simulation of
Chemical Engineering Systems
Lecture 21
November 13, 2014
Statistics
Whenever analyzing data, you have to compute statistics
> scores = 100*rand(1,100);
Builtin functions
mean, median and mo
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
CHE 2162 Introduction to Computer Modeling
and Simulation of
Chemical Engineering Systems
Lecture 15
October 21, 2014
Numerical differentiation and integration
Matlab has a few functions that can be used in obtaining finite
approximations for differentia
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
CHE 2162 Introduction to Computer Modeling
and Simulation of
Chemical Engineering Systems
Lecture 16
October 23, 2014
Numerical Integration
Lets numerically solve the following double integral
2
ysin(x) xcos(y)
dxdy
0
Now similar to the 1d integrals
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
CHE 2162 Introduction to Computer
Modeling and Simulation of
Chemical Engineering Systems
Lecture 6 September 11, 2014
Matlab vectors and matrices
An ordered collection of numbers separated by commas or spaces
can be defined in MATLAB as an array or vect
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
CHE 2162 Introduction to Computer Modeling
and Simulation of
Chemical Engineering Systems
Lecture 10 September 25, 2014
Midterm Review
Write a simple Matlab Script
A script is
a collection of commands executed in sequence
written in the MATLAB editor
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
CHE 2162 Introduction to Computer
Modeling and Simulation of
Chemical Engineering Systems
Lecture 7 September 16, 2014
Matrix math review
The transpose operators turns a column vector into a row vector and
vice versa>
> a = [1 2 3 4+i]
> transpose(a)
> a'
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
CHE 2162 Introduction to Computer Modeling
and Simulation of
Chemical Engineering Systems
Lecture 14
October 16, 2014
Curve fitting using polynomials
Experimental data is often accompanied by noise
Athough all control parameters (independent variables)
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
CHE 2162 Introduction to Computer Modeling
and Simulation of
Chemical Engineering Systems
Lecture 13
October 14, 2014
Polynomials
Many functions can be well described by a highorder polynomial
MATLAB represents a polynomials by a vector of coefficients
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
CHE 2162 Introduction to Computer Modeling
and Simulation of
Chemical Engineering Systems
Lecture 12
October 9, 2014
Plot options
Can change the line color, marker style, and
line style by adding a string argument
> plot(x,y,k.);
color
marker line style
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
CHE 2162 Introduction to Computer
Modeling and Simulation of
Chemical Engineering Systems
Lecture 5 September 9, 2014
Matlab vectors and matrices
An ordered collection of numbers separated by commas or spaces
can be defined in MATLAB as an array or vecto
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
CHE 2162 Introduction to Computer Modeling
and Simulation of
Chemical Engineering Systems
Lecture 11
October 7, 2014
Variable Scope in Matlab
he scope of a variable is generally defined as the range of
nctions that have access to the variable to set or mo
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
CHE 2162 Introduction to Computer
Modeling and Simulation of
Chemical Engineering Systems
Lecture 8 September 18, 2014
Basic Plotting
Example:
> x=linspace(0,4*pi,10);
> y=sin(x);
Plot values against their index
> plot(y);
Usually we want to plot y ver
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
CHE 2162 Introduction to Computer Modeling
and Simulation of
Chemical Engineering Systems
Lecture 9 September 23, 2014
Nested functions
A nested function is a function that is completely contained
within a parent function (the actual program resides in t
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
CHE 2162 Introduction to Computer
Modeling and Simulation of
Chemical Engineering Systems
Lecture 4 September 4, 2014
IEEE 754 Standard
Single precision (32 bits total):  about 7 digits accuracy
(222 produces 7 digits)
IEEE Single precision Real exponen
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
1. Class A had 30 students who received an average test score of 78, with
standard deviation of 10. Class B had 25 students an average test score of
85, with a standard deviation of 15. We want to know if the difference in
these averages is statistically
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
1.
A large tank initially holds 400 gallons of water into which 1600 pounds of a certain
salt has been dissolved. An inflow pipe brings in water containing 2 pounds of the
same salt per gallon at a rate of 5 gallons per minute. An outflow pipe allows the
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
1. Show all work
a. Convert the octal number 8631 to decimal.
8x83+6x82+3x81+1x80= 4096+384+24+1=4505
b. Convert the decimal number 751 to binary.
The binary representation follows the same procedure as above. This
highest power of 2 is
ln(751)ln(2)=9.55.
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
1. Determine the positive roots of the following equations using Matlab:
a. x 38 x 2+17 x + x=10
> fun1='x.^38*x.^2+17*x+x.^0.510'
> fplot(fun1,[1 10])
f(x) crosses zero near 0.7 and 2.3.
> fzero(fun1,0.7)
ans =
0.8173
Trial> fzero(fun1,2.3)
ans =
2.42
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
1. Define the following:
a. cumsum(X,DIM)
For vectors, cumsum(X) is a vector containing the cumulative sum of the
elements of X. For matrices, cumsum(X) is a matrix the same size as X
containing the cumulative sums over each column. For ND arrays,
cumsum
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
1. In many of your Chemical Engineering classes, you will be using heat capacity
to solve problems, namely: Mass and Energy Balances, Kinetics, Heat Transfer
and Thermodynamics. For many gases, heat capacity (Cp) can be described in
terms of a cubic equat
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
1. Given A = 10 5 9 3
1 5 6 2
15 18 7 10
22 16 11 8
What does A(:,[4 1 2 3]) produce ?
Answer: 3 10
2 1
10 15
8 22
5 9
5 6
18 7
16 11
The command works by first changing i=1,j=1 with i=1,j=4, next i=1,j=2 with
i=1,j=1, next i=1, j=3 with i=1,j=2
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
1) Get and save the current date and time
Create a variable start using the function clock
a. What is the size of start? Is it a row or column?
b. What does start contain? See help clock
c. Convert the vector start to a string.
d. Use the function datestr
Introduction to Computer Modeling and Simulation of Chemical Engineering Systems
CHEMICAL E ChE2162

Fall 2014
Homework:
1) How many significant digits are in the following decimalbase numbers ?
a) 15,001
5significant digits
b) 740,001
6significant digits
c) 0.0054
2significant digits
d) 23,405
5significant digits
e) 80,0000.970
9significant digits
f) 1.235