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!