The equation above describes how a steady-state mass chemical acts in a one-dimensional canal, which can occur when building a canal for irrigation. This equation is based on its 𝑐 = concentration, 𝑡 = time, 𝑥 = distance, 𝐷 = diffusion coefficient, 𝑈 = fluid velocity, and 𝑘 = a first-order decay rate. This 2nd-order homogeneous differential equation also has parameters set at 𝑐(0) = 80, and 𝑐(10) = 20.
Centered finite difference method is used to approximate for the equations derivatives. Since the equation has a double derivative two different approximations are used. When plugged into the function the equation can be reformatted into adding c(i-1) , c(i) and c(i+1). These coefficients can be further simplified to (.75)*c(i-1) + (-1.2)*c(i) + (.25)*c(i+1) , this equation is then used for the initial conditions of C(0) = 80 and C(10) = 20. Given the parameters a 4x5 matrix can be derived. This matrix is then used to derive the change in concentration regarding distance using the Gauss Jordan method.
The Alternative approach defines the function as a homogeneous differential equation. First, the quadratic formula is used to find the positive and negative rates. To find the coefficients, the initial parameters are plugged into the equation to create a system of equations. The coefficients are then added to the exponential equation representing the concentration over time.
Define parameters (set matrix a and b as augmented matrix)
Initialize vectors x and l. (to use for columns and rows in the matrix)
For loop (for determining which columns to use)
For loop (for determining which rows to use)
If statement ( to find the highest row value and move to the top of the matrix)
For loop for the first iteration (tell which column to use)
For loop initializing the first iteration (for row reduction using a factor)
For loop (for backward substitution)
b matrix is divided by a matrix to represent coefficients
Initialize x for plot and c(x) for plot
plot values along with analytical equation
Matlab
A = [-1.2 0.25 0 0; 0.75 -1.2 0.25 0; 0 0.75 -1.2 0.25; 0 0 0.75 -1.2];
b = [-60 0 0 -5]';
Aaug = [A b]
[m,n] = size(A); % checking the size of matrix
% Initialization
x = zeros(m,1);
l = zeros(m,m-1);
% Main Program
% Reducing Matrix A to upper triangular form
for k = 1:m-1
for p = k+1:m
if (abs(A(k,k)) < abs(A(p,k)))
A([k p],:) = A([p k],:);
b([k p]) = b([p k]);
end
end
for i = k+1:m
l(i,k) = A(i,k)/A(k,k);
for j = k+1:n
A(i,j) = A(i,j)-l(i,k)*A(k,j);
end
b(i) = b(i)-l(i,k)*b(k);
end
end
for k = 1:m-1
for i = k+1:m
A(i,k) = 0;
end
end
%c=A
% Backward substitution of Matrix A
x(m) = b(m)/A(m,m);
for i = m-1:-1:1
sum = 0;
for j = i+1:m
sum = sum + A(i,j)*x(j);
end
x(i) = (b(i)- sum)/A(i,i);
end
c = A\b;
%% Plot
xplot = 0:2:10;
cplot = [80;c;20];
xc = 80 * exp(-.15* xplot)
figure(2);
plot(xplot,cplot,'--','LineWidth',3);
hold on
plot(xplot,xc, 'LineWidth',2)
xlabel('Distance (x) ');
ylabel('Concentration C(x)');
title('Concentration vs. Distance');
hold off
The dotted blue line represents the numerical method; whereas, the red line represents the analytical solution of 80e^(-.15). I chose to get rid of the first coefficient of the analytical solution since the value would begin to increase as it reached x = 20. This way the function decreases instead of slightly increasing when x increases.
The numerical method in this problem had no difference from the backslash command. Since the Gauss-Jordan method provided the same values I calculated the error from my alternative approach. The alternative approach provided a function whose first coefficient eventually reached infinity, but the concentration should increase as time increases. I decided to zero out this part of the equation as it would only add inaccuracy especially as time increased.
The analytical solution, when plotted for a larger parameter, would begin to produce incorrect results as time increased. This meant that the first exponential would eventually reach infinity, even if the coefficient is almost 0. Using Matlab'1s built-in cond command the condition number of matrix A was found to be 1.53. This means that the coefficient values will drastically change if the matrix B values change. The solutions themselves are relatively close to the Alternative solution meaning that the numerical method has validity.