Here's a start, but what is N and x? And you didn't call plot(), so what, in this alphabet soup of a program, is being plotted along the x and y axes?
N = 100;
U = zeros(N*2+2);
A = zeros(N*2+2);
B = zeros(N*2+2);
C = zeros(N*2+2);
D = zeros(N*2+2);
Y = zeros(N*2+2);
onesN=1.0/N;
Re=5000;
EE=1.0;
t=0;
dt=EE*Re*N^2;
AA = -0.5 * EE;
BB = 1.0 + EE;
KKEND=12;
KKMOD=1;
Y(1)=0;
U(1)=0.0;
U(x)=1.0;
N=20
for j=2:N
U(j)=0.0;
A(1) = 1.0;
B(1) = 1.0;
C(1) = 1.0;
D(1) = 1.0;
end
for j=2:N
Y(j)=Y(j-1)+N;
A(j)=AA;
if j==N
A(j)=0.0;
D(j)=BB;
B(j)=AA;
end
if j==2
B(j)=0.0;
C(j)=1.0-EE*U(j)+0.5*EE*U(j+1)+U(j-1);
end
if j==N
C(j)=C(j)-AA*U(x);
end
end
for j=3:N
D(j)=D(j)-B(j)*A(j-1)/D(j-1);
C(j)=C(j)-C(j-1)*B(j)/D(j-1);
for k=2:N
M=N-(k-2);
U(M)=(C(M)-A(M)*U(M+1))/D(M);
Y(1)=0.0;
Y(x)=Y(N)+N;
t=t+dt;
end
end
Best Answer