% DIFF1.M 1-Dimensional Diffusion Solution
%
% Tom Huber, March 1997
%
ncells = 25; % Number of Cells in the Array
NTimes = 20; % Number of Time steps to perform
FracLeft = 1/3; % Fraction diffusing to the left
FracSame = 1/3; % Fraction which remains in same cell
FracRight = 1/3; % Fraction diffusing to the right
Values = zeros(ncells,1); % Initialize the Array to have zero concentration
VMax = 100; % Maximum Concentration
Values(ncells/2) = VMax; % Initially set the concentration at the midpoint
for i=1:NTimes % Perform a total of NTimes time steps
NewValues = Values*FracSame; % New values initially a fraction of original
for j=2:ncells-1 % For each cell except leftmost or rightmost
NewValues(j-1) = NewValues(j-1)+Values(j)*FracLeft; % Diffuse Left
NewValues(j+1) = NewValues(j+1)+Values(j)*FracRight; % Diffuse Right
end % for j=1...
Values = NewValues; % The updated values become the current values
plot(Values) % Plot the values
axis([1 ncells 0 VMax]) % Set the minima and maxima on axes
xlabel('Position') % Label the axes and the title
ylabel('Value')
title(['After Time Step: ' num2str(i)])
drawnow % Make Matlab display the graph
% (Normally it only displays at the end of a program)
end % for i=1...
% DIFF1.M 1-Dimensional Diffusion Solution
%
% Tom Huber, March 1997
%
ncells = 25; % Number of Cells in the Array
NTimes = 20; % Number of Time steps to perform
FracLeft = 1/10; % Fraction diffusing to the left
FracSame = 3/10; % Fraction which remains in same cell
FracRight = 6/10; % Fraction diffusing to the right
Values = zeros(ncells,1); % Initialize the Array to have zero concentration
VMax = 100; % Maximum Concentration
Values(ncells/2) = VMax; % Initially set the concentration at the midpoint
for i=1:NTimes % Perform a total of NTimes time steps
NewValues = Values*FracSame; % New values initially a fraction of original
for j=2:ncells-1 % For each cell except leftmost or rightmost
NewValues(j-1) = NewValues(j-1)+Values(j)*FracLeft; % Diffuse Left
NewValues(j+1) = NewValues(j+1)+Values(j)*FracRight; % Diffuse Right
end % for j=1...
Values = NewValues; % The updated values become the current values
plot(Values) % Plot the values
axis([1 ncells 0 VMax]) % Set the minima and maxima on axes
xlabel('Position') % Label the axes and the title
ylabel('Value')
title(['After Time Step: ' num2str(i)])
drawnow % Make Matlab display the graph
% (Normally it only displays at the end of a program)
end % for i=1...
% DIFF1.M 1-Dimensional Diffusion Solution
%
% Tom Huber, March 1997
%
ncells = 25; % Number of Cells in the Array
NTimes = 20; % Number of Time steps to perform
FracLeft = 1/10; % Fraction diffusing to the left
FracSame = 3/10; % Fraction which remains in same cell
FracRight = 6/10; % Fraction diffusing to the right
Values = zeros(ncells,1); % Initialize the Array to have zero concentration
VMax = 100; % Maximum Concentration
Values(ncells/4) = VMax; % Initially set the concentration at the midpoint
for i=1:NTimes % Perform a total of NTimes time steps
NewValues = Values*FracSame; % New values initially a fraction of original
for j=1:ncells % For each cell except leftmost or rightmost
if j>1
NewValues(j-1) = NewValues(j-1)+Values(j)*FracLeft; % Diffuse Left
end
if j