MATLAB projects for Computer Science/Engineering using these numerical method techniques?
古いコメントを表示
i am reciving one error and could not solve it, could you please check it. many thanks
the error is
Index exceeds array bounds.
Error in probblem51 (line 53)
Sv(j)=-1*(phiold(j,i+1)+phi(j,i-1));
code :
%A two dimensional inviscid, incompressible fluid is flowing steadily
%through a chamber between inlet and the outlet. Obtain the solution
% using
%both PSOR and the ADI methods.%
close all, clc
%Defining the constants
L=6; % length
H=4; % Height
JN=21; % Maximum number of grid points along y
IM=31; % Maximum number of grid points along x
phi=zeros(JN,IM);
deltax=0.2;
deltay=0.2;
B=deltax/deltay;
%Initial Guess
for i=1:IM
for j=1:JN
phi(j,i)=50;
end
end
Errormax=0.01;
er=1;
count=0;
while er
phiold(j,i)=phi(j,i);
count=count+1;
Beta=B^2;
alpha=-2*(1+Beta);
e=ones(IM,1);
f=ones(JN,1);
for i=2:IM-2
for j=2:JN-1
Su(i)=-Beta*(phiold(j+1,i)+phi(j-1,i));
if i==IM-1
Su(i)=-Beta*(phiold(j+1,i)+phi(j-1,i))-phiold(j,IM);
end
if i==2
Su(i)=-Beta*(phiold(j+1,i)+phi(j-1,i))-phiold(j,1);
end
end
A=spdiags([e alpha*e e], -1:1,IM-2,IM-2);
phiold=Su(i)*inv(A);
end
for j=2:JN-2
for i=2:IM-1
Sv(j)=-1*(phiold(j,i+1)+phi(j,i-1));
if j==JN-1
Sv(j)=-1*(phiold(j,i+1)-phi(j,i-1))-phiold(JN,i);
end
if j==2
Sv(j)=-1*(phiold(j,i+1)-phi(j,i-1))-phiold(1,i);
end
end
B=spdiags([f*Beta alpha*f Beta*f], -1:1, JN-2,JN-2);
phi=Sv(j)*inv(B);
end
end
4 件のコメント
Walter Roberson
2021 年 5 月 30 日
for i=2:IM-2
for j=2:JN-1
Su(i)=-Beta*(phiold(j+1,i)+phi(j-1,i));
if i==IM-1
Su(i)=-Beta*(phiold(j+1,i)+phi(j-1,i))-phiold(j,IM);
end
if i==2
Su(i)=-Beta*(phiold(j+1,i)+phi(j-1,i))-phiold(j,1);
end
end
A=spdiags([e alpha*e e], -1:1,IM-2,IM-2);
phiold=Su(i)*inv(A);
end
You are overwriting all of phiold for each i iteration. Are you sure that is appropriate?
You are overwriting Su(i) for each different j iteration. Are you sure that is appropriate?
mehmet salihi
2021 年 5 月 31 日
Walter Roberson
2021 年 5 月 31 日
The error message is on a line that indexes into phiold and phi. The first double loop repeatedly overwrites all of phiold, so it is appropriate to first prove that the way it is overwritten is correct, that the size of phiold is kept consistent. Only then is it appropriate to study the structure of the second double loop, which overwrites all of phi, to see whether the size of phi is being kept consistent.
Hint: NO, the size of phiold is not being kept consistent.
mehmet salihi
2021 年 5 月 31 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!