Azzera filtri
Azzera filtri

Please I need help to fix this gauss seidel code, I feel like its not well-written because 1- if I increase the number of nodes, it gives the output as "NaN" 2-it doesn't converge..

2 visualizzazioni (ultimi 30 giorni)
I'm trying to solve the energy balance equation of some component of a flat plate solar collector( glass cover, air gap, absorber and HTF) using gauss seidel. I have written the below code but something is wrong with it because 1- if I increase the number of nodes, it gives output the as "NaN" unless I reduce the time step 2-it doesn't converge.
function [T_siedal,x,iter,error] = Gauss_S(Nx,Ny,aE,aW,aN,aS,aNN,aSS,b,aP,delx,T_am)
%N_x no of nodes in the x-direction
%N_y no of nodes in the y-direction
% x - x-position (m)
% y - y-position (m)
%Setup grid
for i=1:Nx
x(i,1)=(i-1)*delx;
end
maxiter=10000;
T_guess=zeros(Nx,Ny);
T=T_guess;
tol=0.00000001;
error=1;
iter = 0;
%%boundary condition at inlet of HTF
for i=1:Nx
for j=1:Ny
if i==1 && j==1
T(i,j)=T_am;
end
end
end
while (error>tol && iter<maxiter)
T_old=T;
for i=1:Nx
if i==1
%%HTF equation
%%Absorber Equation
j=2;
T(i,j)=((aE(i+1,j)*T(i+1,j))+(aN(i,j+1)*T(i,j+1))+(aS(i,j-1)*T(i,j-1))+(aNN(i,j+2)*T(i,j+2))+(b(i,j)))/aP(i,j);
%%Air Gap Equation
j=3;
T(i,j)=((aE(i+1,j)*T(i+1,j))+(aN(i,j+1)*T(i,j+1))+(aS(i,j-1)*T(i,j-1))+(b(i,j)))/aP(i,j);
%%Glass Cover Equation
j=4;
T(i,j)=((aE(i+1,j)*T(i+1,j))+(aS(i,j-1)*T(i,j-1))+(aSS(i,j-2)*T(i,j-2))+(b(i,j)))/aP(i,j);
elseif i>1 && i<Nx
%%HTF equation
j=1;
T(i,j)=((aE(i+1,j)*T(i+1,j))+(aW(i-1,j)*T(i-1,j))+(aN(i,j+1)*T(i,j+1))+(b(i,j)))/aP(i,j);
%%Absorber Equation
j=2;
T(i,j)=((aE(i+1,j)*T(i+1,j))+(aW(i-1,j)*T(i-1,j))+(aN(i,j+1)*T(i,j+1))+(aS(i,j-1)*T(i,j-1))+(aNN(i,j+2)*T(i,j+2))+(b(i,j)))/aP(i,j);
%%Air Gap Equation
j=3;
T(i,j)=((aE(i+1,j)*T(i+1,j))+(aW(i-1,j)*T(i-1,j))+(aN(i,j+1)*T(i,j+1))+(aS(i,j-1)*T(i,j-1))+(b(i,j)))/aP(i,j);
%%Glass Cover Equation
j=4;
T(i,j)=((aE(i+1,j)*T(i+1,j))+(aW(i-1,j)*T(i-1,j))+(aS(i,j-1)*T(i,j-1))+(aSS(i,j-2)*T(i,j-2))+(b(i,j)))/aP(i,j);
else
%%HTF equation
j=1;
T(i,j)=((aW(i-1,j)*T(i-1,j))+(aN(i,j+1)*T(i,j+1))+(b(i,j)))/aP(i,j);
%%Absorber Equation
j=2;
T(i,j)=((aW(i-1,j)*T(i-1,j))+(aN(i,j+1)*T(i,j+1))+(aS(i,j-1)*T(i,j-1))+(aNN(i,j+2)*T(i,j+2))+(b(i,j)))/aP(i,j);
%%Air Gap Equation
j=3;
T(i,j)=((aW(i-1,j)*T(i-1,j))+(aN(i,j+1)*T(i,j+1))+(aS(i,j-1)*T(i,j-1))+(b(i,j)))/aP(i,j);
%%Glass Cover Equation
j=4;
T(i,j)=((aW(i-1,j)*T(i-1,j))+(aS(i,j-1)*T(i,j-1))+(aSS(i,j-2)*T(i,j-2))+(b(i,j)))/aP(i,j);
end
end
error = norm(T-T_old)/norm(T);
iter = iter+1;
end
T_siedal=T
end
if true
% code
end
  3 Commenti
Gadosky571
Gadosky571 il 7 Apr 2018
thanks for the suggestion John. I'm new to Matlab that's why but I will see if I can solve it using backslash. its part of my project not a homework. Thanks once again.
Rohit Bhise
Rohit Bhise il 7 Ago 2020
Hey I'm also having the same problem. I'm trying to solve cavity problem with symmetric coupled Gauss sidel method and I'm getting NAN values. Did you find solution to your problem?

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Numerical Integration and Differential Equations in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by