My programm is not running but giving 'Index in position 1 exceeds array bounds (must not exceed 1). Error in ruvgp (line 16) u=(u1(i,j)*cx(k))/(c0+sqrt(c0*c0+(c1.*ta(i,j))));' The function is as pasted in the body
1 回表示 (過去 30 日間)
古いコメントを表示
function[rho,u,v]=ruvgp(nx,ny,f,cx,cy,u,v,c0,c1,E,gbeta,rhog)%,beta,alpha,
rho=sum (f,3);
for j=1:ny
for i=1:nx
%t1=u(i,j)*u(i,j)+v(i,j)*v(i,j);
rho(i,ny)=f(i,ny,9)+f(i,ny,1)+f(i,ny,3)+2.*(f(i,ny,2)+f(i,ny,6)+f(i,ny,5));
end
end
for k=1:9
Fy=E*gbeta*rho(i,j)*rhog(i,j)*cy(k)./2;
u1 = ( sum(f(:,:,[1 5 8]),3) - sum(f(:,:,[3 6 7]),3))./rho(i,j);
v1 = ( sum(f(:,:,[2 5 6]),3) - sum(f(:,:,[4 7 8]),3))./rho(i,j)+Fy;
ta = u1(i,j)*u1(i,j)+v1(i,j)*v1(i,j);
% u=(u1(i,j)*cx(k))./(c0+sqrt(c0*c0+(c1*abs(u1))));
% v=(v1(i,j)*cy(k))./(c0+sqrt(c0*c0+(c1*abs(v1))));
u=(u1(i,j)*cx(k))/(c0+sqrt(c0*c0+(c1.*ta(i,j))));
v=(v1(i,j)*cy(k))/(c0+sqrt(c0*c0+(c1.*ta(i,j))));
end
end
1 件のコメント
KSSV
2020 年 4 月 10 日
Without provding inputs..how you expect us to run and check the code?
The error is clear, you are trying to access more number of elements than present in the array.
回答 (1 件)
Walter Roberson
2020 年 4 月 10 日
ta = u1(i,j)*u1(i,j)+v1(i,j)*v1(i,j);
i and j are scalars, so u1(i,j) and v1(i,j) are scalars, so ta is going to be a scalar.
u=(u1(i,j)*cx(k))/(c0+sqrt(c0*c0+(c1.*ta(i,j))));
but there you try to index ta(i,j) as if ta is a 2D array.
3 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!