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

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 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