This Matlab program uses the error function to calculate the concentration on both sides of a material interface, across which the phenomenon of diffusion is taking place.
The program solves Problem 5.12 in the 6th. or 7th. edition of the textbook "Materials Science for Engineers", Shackelford, J F. The original problem is:
___________________________________________________________________
A diffusion couple is formed when two different materials are allowed ot interdiffuse at an elevated temperature. For a block of pure metal A adjacent to a block of pure metal B, the concentration profile of A (in at%) after interdiffusion is given by
cx = 50 * (1 - erf(x / (2 * sqrt(D * t)))
where x is measured from the original interface. For a diffusion couple with D = 1E-14 m^2/s, plot the concentration profile of metal A over a range of 20E-6 m, on either side of the original interface (x=0), after a time of 1 hour. [Note that erf(-z) = -erf(z)].
___________________________________________________________________
The concentration profile of material A (%) is calculated and plotted, for a block of pure metal A adjacent to a block of pure metal B, at time t. The independent variable x is measured from the original interface, between A and B. The constant of diffusion is D = 10E-14 m^2/s, and the concentration is plotted over a range of 20 micrometers on either side of the original interface.
The error function is the integral of the normal probability distribution; thus it is the cummulative probability distribution, and it depends on the parameters of the problem. Usually a parameter z is defined as the argument of the error function. The error function is available in Matlab as erf.
_________________________________________________________________________________
% error01.m
% Ricardo Ernesto Avila Montoya Feb. 5, 2007% Materials Science for Design. ricardoavila.org
% Universidad Autonoma de Ciudad Juarez, Mexico
% A Matlab program to calculate and plot the error function:
% a solution of the diffusion problem.
% The plot displays the concentration of solutes at time
% t = 1800 s, on both sides of a material interface.
clc; % clear command window
clf; % clear figureclear; % clear memory
x = linspace(-20e-6, 20e-6, 40)'; % generate x-axis values
D = 1e-14; % m^2/s, coefficient of diffusiont = 1800; % seconds, time
c=50 * (1 - erf(x/(2*sqrt(D*t)))); % calculate concentration
% Plot the result in figure 1
figure(1) plot(x,c, 'r')
axis([x(1) x(size(x,1)) 0 100]); % axis limits
grid
xlabel('distance from interface: x, m')
ylabel('% concentration')
title('Plot of error function, concentration at time 1800 s')
hold on
% Display the variables (data in memory at end of run)
whosdisp(' ***** Succesful execution of program ***** ');
disp(' ****************************************** ');
No comments:
Post a Comment