Sei sulla pagina 1di 9

Problem 1: Solve the ODE below for concentration ( c ) as a function of reactor volume (VR ).

Develop a MATLAB m-file. Plot concentration versus volume label the axes and provide a
graph title. Discuss the solution.


= 0 < VR 2000
(+)

c(0) = 2;

Data : Q = 50; k = 0.198; v = 3.8


Matlab Program 1:
function [VR,c]=ODEproblem1(N)
Vrspan=[0 N];%define the volume interval on which to solve the problem
c0=2; %define the initial condition
% Call on ode45 to solve the problem, RHS is a function that defines the
% right hand side of the ODE, The @ symbol tells me that the RHS is a
% function and not a variable
[VR,c]=ode45(@RHS,Vrspan,c0);

figure
plot (VR,c,'m'); grid on %plot concentration c versus Volume VR
xlabel ('VR');%This is the x-axis
ylabel ('c');%This is the y-axis
title ('This is plot of Concentration, c versus Volume, VR');
end

function [myRHS]=RHS(VR,c) %VR is an independent variable, c is a dependent


variable
k=0.198; Q=50; v=3.8;
myRHS=-k*c/(Q*(c+v));
end
This is plot of Concentration, c versus Volume, VR
2

1.8

1.6

1.4

1.2
c

0.8

0.6

0.4

0.2
0 200 400 600 800 1000 1200 1400 1600 1800 2000
VR

Discussion 1: An ODE function, Ode45 was called upon to solve the first ODE

Problem 2: Solve the following two-point BVP using Matlab. Provide the Matlab file as well as
a discussion of the solution.

2 2
2+
=
1+Kc
0 < r <1


|r=0= 0 c(1) =1 = 5 K = 2

Solution 2:

Reducing the second order equation to first order;

2 2
+ = 1
2 1+Kc

Let; c = c(1)2

= cl = c(2) First ODE equation

2
= cll = cl(2)3
2

Substituting back into equation 1


2
cll + cl =
1+Kc

2
cl(2) + c(2) =
1+Kc

2
cl(2) = - c(2).Second ODE equation
1+Kc

Solving for the boundary conditions;

cl(0) = 0 From First ODE equation c(2) = 0First BC

c(1) = 1 c(1) - 1 = 0Second BC


Matlab Program 2:
function [r,c]=BVPproblem2(N)

solinit=bvpinit(linspace(0.01,1,10),[1 0]); % bvpinit forms the initial guess


for bvp4c
sol = bvp4c(@Odefun,@BCfun,solinit); % Calling on bvp4c to solve boundary
value problems for ordinary differential equations having the
function'Odefun',boundary conditions 'BCfun' and 'solinit' solution with the
mesh count and initial guess.
r = linspace(0.01,1); %values interval of r
c = deval(sol,r); %Evaluate the numerical solution of c using the output of
bvp4c 'sol' and 'r'
plot(r,c(1,:)); grid on %Plot c versus r
xlabel('r'); % x-axis caption
ylabel('c'); % y-axis caption
title ('This is plot of "c" versus "r"');
end

function dbdr=Odefun(r,b)%odefun is a function handle that evaluates the


differential equations
dbdr=[b(2) (5*b(1))/(1+2*b(1))-((2/r)*b(2))];
end

function theBC=BCfun(ya,yb)%Handle to a function that evaluates the residual


in the boundary conditions
theBC=[ya(2) yb(1)-1];
end
This is plot of "c" versus "r"
1

0.95

0.9

0.85
c

0.8

0.75

0.7
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
r

Discussion: The ODE function in second order was converted to first order ODE so as to enable
us use bvp4c of matlab to solve the solution, this resulted to two first order ODE equations. With
our boundary conditions and initial condition, we developed our matlab program and plotted our
graph of c versus r. The graph (curve) indicated that c increases as r increases.

Problem 4: Solve the following PDE using the MATLAB function pdepe. Provide the Matlab
file as well as a discussion of the solution.
2
1
+ =
2
- Da ( ) 0 < x <1; 0<t<tf
+
1
- | (0,t) - [1-c|(0,t)] = 0 |(1,t) = 0

c|( x,0)= 0 c|(0,0)=1

Data: Da 2; Pe 100; v 2; tf 2.5 . You may experiment with different values of t f

Rearranging the equation;


2
1
=
2
- Da ( ) - ..1
+

1
= - Da ( ) - 2
+
Comparing 2 to the general equation;


C = x-m (mf ) + s

1
C = 1; m = 0; f = ; s = - Da ( ) -
+

For the Boundary conditions, BC

BC No1: Left (l)

Having the general equation as

p + qf = 0
1
p+q =0

and the first BC we compare the coefficients of p and q


1
- | (0,t) - [1-c|(0,t)] = 0 ..BC 1

pl = - [1-c|(0,t)] and ql = -1

pl = -[1-c] and ql = -1

BC No2: Right (r)

Comparing the second BC with the general equation as above;

|(1,t) = 0.BC 2

pr = 0 and qr = Pe

pr = 0 and qr = 100

Initial Condition (IC);

c0= 0 .. IC

Matlab Program 4:
% this is an m-file to solve problem 4
function [x,t,sol] = PDEproblem4(tf)
m = 0;% the problem has a rectangular coordinate
x = 0:0.05:1;
t = 0:0.1:tf;
% calling on pdepe to solve the problem, the solution is contained in sol
sol = pdepe(m,@pdeFunc,@pdeIC,@pdeBC,x,t);
c = sol;

% Now plot the solutions on 3D


surf(x,t,c)
title('PDE plot solution @ tf=2.5')
xlabel('Distance x')
ylabel('Time t')
zlabel('c')

%Now plot the solution on 2D


figure
plot(x,c(end,:)); grid on %at t=2.5 as c=f(x)
title('Plot of solution @ tf=2.5') %tf will be varied for 1,2 and 4
xlabel('Distance x')
ylabel('c(x,tf)')

figure
plot(x,c(1,:)); grid on
title('Plot of solution @ tf=2.5') %tf will be varied for 1,2 and 4
xlabel('Distance x')
ylabel('c(x,tf)')

figure
plot(t,c(:,end)); grid on
title('Plot of solution @ x=1')
xlabel('Time t')
ylabel('c(1,tf)')

end

function [C,f,s]=pdeFunc(x,t,c,dcdx)
%This defines c(x,t,u,dudx), s(x,t,u,dudx), f(x,t,u,dudx)
C = 1;
f = (1/100)*dcdx;
s = -(2*c/(c+2))-(dcdx);
end

function [c0] = pdeIC(x)


% This defines the initial conditions
if (x>0)
c0 = 0;
else
c0 = 1;
end;
end

function [pl,ql,pr,qr]=pdeBC(xl,cl,xr,cr,t)
%This defines the boundary conditions:i.e. left BC & right BC
%[pl,ql,pr,pl]==[pLeft,qRight,pRight,pLeft]
%[xl,xr]=[0,1]
%[xl,cl,xr,t]==[xleft,cleft,xright,time]
pl = -(1-cl);
pr = 0;
ql = -1;
qr = 100;
end

Figure4:
PDE plot solution @ tf=2.5

Plot of solution @ tf=2.5


1

1.5
0.9

1
0.8 c
c(x,tf)

0.7 0.5

0.6
0
3
1
0.5 2
0.8
0.6
1 0.4
0.4 0.2
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Time t 0 0
Distance x
Distance x

Plot of solution @ tf=1


1
Plot of solution @ tf=2
1
0.9

0.9
0.8

0.7 0.8
c(x,tf)

0.6
c(x,tf)

0.7

0.5
0.6
0.4

0.5
0.3

0.2 0.4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Distance x Distance x
Plot of solution @ tf=4 Plot of solution @ tf=0.5
1 1

0.9
0.9
0.8

0.7
0.8
0.6
c(x,tf)

c(x,tf)
0.7 0.5

0.4
0.6
0.3

0.2
0.5
0.1

0.4 0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Distance x Distance x

Plot of solution @ x=1


0.5

0.45

0.4

0.35

0.3
c(1,tf)

0.25

0.2

0.15

0.1

0.05

0
0 0.5 1 1.5 2 2.5
Time t

Discussion:

The plot of the solution c versus x, distance is first obtained at final time, tf=2.5 and further
varied at times 0.5, 1, 2 and 4. The initial plot at tf= 2.5 gave a negative slope that indicates that
the solution c decreases as the distance, x increases. Subsequent plots such as @ tf=0.5,
altered the regularity of the previous plot, at the maximum limit of x solution of c remained
constant with a value of zero until x started decreasing and at point 0.8 of the x-axis, c
gradually started to increase in a curve like manner until at some point between 0.8 and 0.9 of c
the slope disrupts a little and then continues. Plots of tf= 4 and tf=2 had no significant change
compared with the initial plot of tf=2.5 and then plot of tf=1 had at the maximum limit of x, c
solution close to value 0.3 and then continued to increase almost uniformly with decreasing
values of x. It can now be deduced that at varying tf greater than 2 the plots remained the same
but at tf less than 2 the plots varied at different values of tf. Assuming the solution of c is
concentration of molecules in space and x is the distance the concentration moves, it now means
that at a lesser time such as 0.5, the concentration does not cover much distance but at a greater
time interval the concentration travels covering a greater distance.
In the last plot of c solution versus time, t which is a positive indicates that the latter remained
at zero until time of almost 0.5 where it increased continuously with time but at some point of
time 1.25, the solution of c remained constant with increasing time.

The plot of c solution versus time, t implied that concentration increased with time and got to a
point the concentration remained constant even with increase in time.

Potrebbero piacerti anche