Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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;
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
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:
2 2
+ = 1
2 1+Kc
Let; c = c(1)2
2
= cll = cl(2)3
2
2
cl(2) + c(2) =
1+Kc
2
cl(2) = - c(2).Second ODE equation
1+Kc
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
1
= - Da ( ) - 2
+
Comparing 2 to the general equation;
C = x-m (mf ) + s
1
C = 1; m = 0; f = ; s = - Da ( ) -
+
p + qf = 0
1
p+q =0
pl = - [1-c|(0,t)] and ql = -1
pl = -[1-c] and ql = -1
|(1,t) = 0.BC 2
pr = 0 and qr = Pe
pr = 0 and qr = 100
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;
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 [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
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
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
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.