필터 지우기
필터 지우기

My Matlab code for 1D convection Diffusion problem is taking too much time to execute

조회 수: 3 (최근 30일)
clc;
clear all;
phia=1; %Boundary Conditions
phib=0; %Boundary Conditions
gamma=0.1;
L=1; %Length of a bar
nx=5; %No. of subdomains
dx=L/nx; %finite volume length
phi=zeros(nx+2,1);
u=0.1;
rho=1;
D=gamma/dx;
F=rho*u;
tolearnce=1e-7;
error=1;
phi(1,1)=phia;
phi(7,1)=phib;
iter=0;
x=0:dx:L;
% p= rho*u*L/gamma;
phi_exact = phia + (phib-phia).*((exp(rho*u*x/gamma)-1)./ (exp(rho*u*L/gamma)-1));
figure (1);
plot(x,phi_exact,'ro')
while error>tolearnce
phi_old=phi;
for i=2
a_E1=D-F/2;
a_W1=0;
Spa=-(2*D+F);
Sua=(2*D+F)*phia;
a_P1=a_E1+a_W1-Spa;
phi(i,1)=(a_E1*phi(i+1) + a_W1*phi(i-1)+ Sua)/a_P1;
end
for i=3:nx
a_W2=D+F/2;
a_E2=D-F/2;
a_P2=2*D;
phi(i,1)=(a_E2*phi(i+1) + a_W2*phi(i-1))/a_P2;
end
for i=6
a_W3=D+F/2;
a_E3=0;
Spb=-(2*D-F);
Sub=(2*D-F)*phib;
a_P3=a_E3+a_W3-Spb;
phi(i,1)=(a_E3*phi(i+1) + a_W3*phi(i-1)+ Sub)/a_P3;
end
iter=iter+1;
end
figure(1)
hold on
plot(x,phi,'b','Linewidth',1);
legend('Exact solution','Difference_Scheme');

답변 (1개)

the cyclist
the cyclist 2021년 9월 1일
You set the values
tolearnce=1e-7;
error=1;
before you enter the while loop, and you never change them. Therefore, the loop will never be exited.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by