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))/(c​0+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
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
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
Oluwaseyi Aliu
Oluwaseyi Aliu 2020년 4월 10일
Thank you sir, I have tried this and it seems to work here but when I called u and v in the function given below to calculate another variable it gives: 'Index in position 1 exceeds array bounds (must not exceed 1). Error in gcolgp (line 29) t1=u(i,j)*u(i,j)+v(i,j)*v(i,j)'
function [g,e]=gcolgp(nx,ny,u,v,cx,cy,omegag,g,rho,w,e)
for j=1:ny
for i=1:nx
t1=u(i,j)*u(i,j)+v(i,j)*v(i,j);
for k=1:9
t2=u(i,j)*cx(k)+v(i,j)*cy(k);
geq=w(k)*rho(i,j)*e(i,j).*(1.0+3.0.*t2+4.5.*t2.*t2-1.5.*t1);
g(i,j,k)=(1.-omegag)*g(i,j,k)+omegag*geq;
e(i,j) =g(i,j,1);
end
end
end
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Just for fun에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by