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 visualización (últimos 30 días)
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 comentario
KSSV
KSSV el 10 de Abr. de 2020
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.

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 10 de Abr. de 2020
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 comentarios
Oluwaseyi Aliu
Oluwaseyi Aliu el 10 de Abr. de 2020
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

Iniciar sesión para comentar.

Categorías

Más información sobre Just for fun en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by