Che374assign5 Sol
Che374assign5 Sol
Che374assign5 Sol
Problem 1
The equation of motion of a simple pendulum, subject to damping and external torque, is given by:
d 2θ dθ
ml 2 2
+c + mgl sin θ = M (t )
dt dt
Where m = mass of the bob, l = length, c = damping factor, g = gravitational acceleration, M(t) =
external torque, θ = angular deflection and t = time.
Express this equation as a system of linear first order equations
Solution
Let
θ1 = θ
θ2 = θ ′
Therefore
⎡ θ1′ = θ 2 ⎤
⎡θ ⎤ ⎢ ⎥
θ = ⎢ 1⎥ θ′ =
⎣θ 2 ⎦ ⎢θ 2′ = θ ′′ = M (t ) − cθ 2 − 2mgl sin(θ1 ) ⎥
⎣ ml ⎦
Problem 2
{THIS WAS SUPPOSED TO BE DONE BY HAND - see page zzz}
Find the solution of the equation
y ′ = 2 − 3 x + 4 y; y (0) = 1
In the interval 0 ≤ x ≤ 1
(a) Using Euler’s method with a step size of 0.5
(b) Using Heun’s method with a step size of 0.5
(c) Using 4th Order Runge Kutta Method with a step size of 0.5.
%%%%%%
{MATLAB VERSION}
%% function to be solved
function F = p3fun(x,y)
F = 2 - 3*x + 4*y;
end
%HEUN
for i= 1: n
K1 = feval(f, x(i), y(i));
K2 = feval(f, x(i)+0.75*h, y(i)+0.75*h*K1);
y(i+1) = y(i) + h * 1/3 * (K1 + 2*K2);
end
%EULER
for i= 1: n
y(i+1) = y(i) + h * feval(f, x(i), y(i));
end
%RK4
while x < xStop
i = i + 1;
h = min(h,xStop - x);
K1 = h*feval(dEqs,x,y); % h*slope at the start point
K2 = h*feval(dEqs,x + h/2,y + K1/2); % h*slope at the midpoint
K3 = h*feval(dEqs,x + h/2,y + K2/2); % h*slope at the midpoint
K4 = h*feval(dEqs,x+h,y + K3); % h*slope at the endpoint
% advance the solution
y = y + (K1 + 2*K2 + 2*K3 + K4)/6;
% increment the step
x = x + h;
% Store current soln.
xSol(i) = x;
ySol(i,:) = y;
end
end
2
CH E 374 – Assignment # 5 Fall 2007
Part B: { this part may be done in groups}
MATLAB
80
70
Euler0.1
60 Euler0.05
Euler0.01
50 RK4
40
y
30
20
10
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
x
Thus a better solution is obtained by using higher order method or using much smaller steps in a lower
order method (Euler).
3
CH E 374 – Assignment # 5 Fall 2007
Problem 4: Non-Isothermal Plug flow Reactor
A Plug flow reactor is used to oxidize SO2 to SO3. The following reactor equations have been
developed (With radial and axial dispersion neglected, Young & Finlayson, 1973):
dX
= −50ℜ
dz
(1)
dT
= −4.1(T − Tsurr ) + 1.02 × 104 ℜ
dz
Where the reaction rate is:
X [1 − 0.167(1 − X ) ] − 2.2(1 − X ) / K eq
1/ 2
ℜ= (2)
[ k1 + k2 (1 − X )]
2
and
ln k1 = −14.96 + 11070 / T
ln k2 = −1.331 + 2331/ T (3)
ln K eq = −11.02 + 11570 / T
With parameters: Tsurr = 673.2, T (0) = 673.2, X (0) = 1 . Where X is the concentration of SO2 divided by
the inlet concentration, 1-X is the fractional conversion, and T is the temperature in K.
(a) write a function (an m-file) to evaluate the right hand side of the above differential equations
(b) Test the m-file with y(1) = 0.2 and y(2) = 573.2
(c) Write a driver program to solve the function in (a). The driver code should set the initial values
and the total interval of integration [0 1].The driver should also make plots, one for the
fractional conversion as a function of dimensionless axial distance and another for the
temperature variation along the axial distance.
% rate constants
k1=exp(-14.96+(11070/T));
k2=exp(-1.331+(2331/T));
% equilibrium constant
Keq=exp(-11.02+(11570/T));
% reaction rate
R=((X*(1-0.167*(1-X))^(0.5))-(2.2*(1-X)/Keq))/((k1+k2*(1-X))^(2));
F(1)=-50*R;
F(2)=-4.1*(T-Tsurr)+(1.02*10^4)*R;
End
test
>> y0 = [1 573.2];
>> myode1(0.2,y0)
ans =
-0.0083
411.6903
5
CH E 374 – Assignment # 5 Fall 2007
750
740
730
Temperature Variation
720
710
700
690
680
670
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Length
0.8
0.7
0.6
Fractional Conversion
0.5
0.4
0.3
0.2
0.1
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Length
6
CH E 374 – Assignment # 5 Fall 2007
Problem # 5
The velocity distribution of a fluid in a straight uniform pipe is given by the Poisson equation:
∂ 2U ∂ 2U
+ = −4
∂x 2 ∂y 2
Where U is the axial dimensionless velocity. The following boundary conditions apply:
U ( x, y = 0) = 0
U ( x, y = H ) = 0
U ( x = 0, y ) = 1.5 y ( H − y)
Find the velocity distribution for a channel with L=10 and H=1 using centered finite difference
approximation. Use Δx = Δy = 1/10 . Produce a plot of y as a function of U for x = 5 and a surface plot
of the velocity distribution in the channel.
%%%%%%%%%%%%%%%%%%%%%
Number of nodal points in the x-direction, nx
dx =dy=0.1
nx= 10/0.1 +1 = 101
Number of nodal points in the x-direction, ny
ny = 1/0.1 + 1 = 11
Boundary conditions:
U (i, j = 0) = 0
U (i, j = ny ) = 0
U (i = 0, j ) = 1.5( j * dy )( H − ( j * dy ))
U (i = nx, j ) = U (i = nx − 1, j )
7
CH E 374 – Assignment # 5 Fall 2007
% ************************************************
% PROBLEM 5
% Centered in space
%d2U_dx2=(U_(i+1,j )-2 U_(i,j) +U_(i-1,j ))/ dx^2
%d2U_dy2=(U_( i ,j+1) -2 U_(i,j) +U_(i ,j-1))/dy^2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
L = 10;
H = 1;
dx = 1/10; dx2 = dx^2;
dy = 1/10; dy2 = dy^2;
ys = [0:dy:H];
nx = L/dx+1;
ny = H/dy+1;
vecD = -2.0 / dx2 -2.0 / dy2;
vecLx = 1.0 / dx2;
vecLy = 1.0 / dy2;
n = nx*ny;
A = eye( n );
b = -4*ones( n,1 );
% BCs
U_yH = 0;
U_y0 = 0;
U_x0 = 1.5;
for i = 1:nx:n
UU = [ UU; U(i:i+nx-1)' ];
end
figure;
surf( UU )
view( -10, 30)
title( 'Velocity distribution' )
xlabel('x')
ylabel('y')
zlabel('U')
figure;
plot( UU( :,5/dx), ys, 'o-b' )
title('Velocity profile at x=5')
xlabel(' U '); ylabel(' y'); grid on
figure;
plot( UU, ys, 'o-b' )
9
CH E 374 – Assignment # 5 Fall 2007
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
-0.1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
0.9
0.8
0.7
0.6
0.5
y
0.4
0.3
0.2
0.1
0
-0.05 0 0.05 0.1 0.15 0.2 0.25 0.3
U
10
CH E 374 – Assignment # 5 Fall 2007
Velocity distribution
1
0.8
0.6
0.4
U
0.2
-0.2
15
10
100 120
y 0 60 80
20 40
0
x
11