0% found this document useful (0 votes)
16 views

% Calculate The Entries of (A) and (B) For The Equation of The First Cell

This document contains Matlab code that sets up matrices and vectors to solve a finite volume method (FVM) equation representing diffusion. It initializes matrices A and b with boundary values, loops to fill in interior values, solves the system of equations, and compares the FVM solution to an exact solution to calculate error.

Uploaded by

nuri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

% Calculate The Entries of (A) and (B) For The Equation of The First Cell

This document contains Matlab code that sets up matrices and vectors to solve a finite volume method (FVM) equation representing diffusion. It initializes matrices A and b with boundary values, loops to fill in interior values, solves the system of equations, and compares the FVM solution to an exact solution to calculate error.

Uploaded by

nuri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

A = zeros(N,N);

b = zeros(N,1);
Phi = zeros(N,1);

% Calculate the entries of [A] and {b} for the equation of


the first cell
A(1,1) = -3*gamma*Area/dx-h*pi*D*dx;
A(1,2) = gamma*Area/dx;
b(1,1) = -h*pi*D*dx*Phi_infinite - 2*gamma*Area/dx*PhiA;

% Calculate the entries of [A] and {b} for the equation of


the inner cells
for i = 2: N-1
A(i,i-1) = gamma*Area/dx;
A(i,i) = -2*gamma*Area/dx-h*pi*D*dx;
A(i,i+1) = gamma*Area/dx;
b(i,1) = -h*pi*D*dx*Phi_infinite;
end

% Calculate the entries of [A] and {b} for the equation of


the last cell
A(N,N-1) = gamma*Area/dx;
A(N,N) = -gamma*Area/dx-2*gamma*h*Area/(h*dx+2*gamma)-
h*pi*D*dx;
b(N,1) = -h*pi*D*dx*Phi_infinite-
2*gamma*h*Area/(h*dx+2*gamma)*Phi_infinite;

Phi = A \ b;

q_base=2*gamma*Area/dx*(Phi(1,1)-PhiA)

x = [0:L/32000:L];
m = sqrt(h*P/gamma/Area);
exact = cosh(m*(L-x))/cosh(m*L)*(PhiA-
Phi_infinite)+Phi_infinite;

plot(x, exact, 'LineWidth', 2)

M = sqrt(h*P*gamma*Area*PhiA)

error = zeros(N,1);

for a=1:N
error(a) = abs((Phi(a)-exact(32000/N*a)) /
exact(32000/N*a)*100);

end
maximum = zeros(N,1);
max(error)
legend('FVM', 'Exact')

You might also like