Computational Methods in The Introductory Courses To Chemical Engineering (KETA01) and Biotechnology (KKKA05)
Computational Methods in The Introductory Courses To Chemical Engineering (KETA01) and Biotechnology (KKKA05)
Introductory Courses to
Chemical Engineering (KETA01) and
Biotechnology (KKKA05)
Carmen Arévalo
Lund University
carmen@maths.lth.se
Lecture 7
Open Rubric
Integration
Z b
• Area: f (x)dx
a
Z b
1
• Average value of a function: f (ξ) = f (x)dx
b−a a
Z b
• Distance: d = v(t)dt (v is velocity)
a
Z Z Z
• Mass: M = c(x, y, z) dx dy dz (c is concentration)
Z Z
• Heat transfer: f (x, y)dx dy (f is flux in cal/(cm2s))
I(f ) may be interpreted as the area between the curve y = f (x) and the
x-axis.
Areas above the x-axis are positive; those below the x-axis are negative.
I = (b − a) × average height
The trapezoidal rule approximates the integral below the curve as the area
of the trapezoid
f(x)
f(a)
f(b)
x
a h b
b
b−a
Z
f (x) dx ≈ [f (a) + f (b)]
a 2
Z = trapz(X,Y)
2.5
1.5
0.5
0
0 0.5 1 1.5 2
Stepsize: h = (b − a)/2,
Nodes: a, (a + b)/2, b
Z b
h a+b
f (x)dx ≈ Q(f ) = f (a) + 4f ( ) + f (b)
a 3 2
If the spacing is uniform and we call its length h, the error of approximating
the integral of f in the interval [a, b] by the trapezoidal rule is
1
ET (f ; h) = − (b − a)h2f 00(c), c ∈ [a, b]
12
Taking a spacing half as large will reduce the error by one fourth (roughly).
1
ES (f ; h) = − (b − a)h4f (4)(ξ), ξ ∈ [a, b]
180
Taking a spacing half as large will reduce the error by 1/16-th (roughly).
1 2 f (4)(ξ2)
ES (f ) = h ET (f )
15 f 00(ξ1)
• For same h, Simpson’s rule is more accurate than the Trapezoidal rule
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0 0.06250.1250.1875 0.25 0.375 0.5 0.75 1
q = quad(fun,a,b)
q = quad(fun,a,b,tol)
uses an absolute error tolerance tol instead of the default which is 10−6.
[q,fnce] = quad(fun,a,b,tol)
We will compute the heat required to raise 1000 g of this material from
-100 to 200 degrees (C) using the equation
Z T2
∆H = m c(T ) dT
T1
= 42732 cal
>> c=@(t)1000*(0.132+1.56e-4*t+2.64e-7*t.^2)
>> qs=quad(c,-100,200,1e-6)
qs =
42732
Z b
(sin(t) + 2 cos(t)) dt ≈ quad(@mf,a,b)
a
After creating the structure, one can use the ppval built-in function together
with quad:
x = [0.97 1.12 2.92 3.00 3.33 3.97 6.10 8.39 8.56 9.44];
y = [2.58 0.43 0.06 5.74 7.44 8.07 6.38 2.51 1.44 6.52];
s = spline(x,y);
f = @(x)ppval(s,x);
int = quad(f,x(1),x(end))
t 0 10 20 30 35 40 45 50
Q 4 4.8 5.2 5 4.6 4.3 4.3 5
c 10 35 55 52 40 37 32 34
>> t=[ 0 10 20 30 35 40 45 50];
>> Q = [ 4 4.8 5.2 5 4.6 4.3 4.3 5];
>> c = [ 10 35 55 52 40 37 32 34];
>> M=cumtrapz(t,Q.*c)
M =
0 1040 3310 6040 7150 8007.8 8749.5 9518.5
Arévalo KETA01 & KKKA05 23