Info

This question is closed. Reopen it to edit or answer.

i am working in fluid dynamics problem. when i run the program , i got the following error. please explain Attempted to access n(-0.2); index must be a positive integer or logical

1 view (last 30 days)
a=0.2;b=1.2;d=2;N=5;s=2;M=2;pe=0.7;w=.1;t=1;x=1;re=0.2;sc=.1;k=.1;Gc=5; Gr=5;pai=0;y=-1:0.01:1;alpha=2;h1=1+a*cos(2*pi*x);h2=-d-b*cos(2*pi*x+pai); a0=(N^2)+i*w*pe; m=sqrt(a0); a4=(s^2)+(M^2)+i*w*re; n=sqrt(a4); a1=h1-h2; a2=sinh(n*a1); f=sc*(k+i*w); %w=omega a5=1/a2; a3=(f^2)-(n^2); a6=Gc/a3; a7=a6*(sinh(n*(y-h2))); a8=(m^2)+(n^2); b1=alpha/(m^2); b2=-(i*w*t); X=b1*exp(b2); a9=(Gr*X)/a8; a10=round(a9*sinh(n(y-h1))); a11=Gr*(1+X)/a8; a12=a11*sinh(n(y-h2)); T1=a5*(a7+a10-a12); a13=(lamda-Gr*X)/(n^2); T2=a5*a13(sinh(n(h2-y))+sinh(n(y-h1))); T3=a13; a14=Gr/a8; a16=sin(m(h1-h2)); a15=(1+X)*cos(m*h2)*sin(m*y)-(1+X)*sin(m*h2)*cos(m*y)+x*sin(m*h1)*cos(m*y)-X*cos(m*h1)*sin(m*y); a17=a15/a16; T4=a14*a17; a18=Gc/a3; a19=sinh(f(y-h2)); a20=sinh(f(h1-h2)); a21=a19/a20; T5=a18*a21; W0=T1+T2+T3+T4-T5; W=W0*exp(i*w*t); plot(y,W)

Answers (1)

Geoff Hayes
Geoff Hayes on 18 Oct 2014
Siva - n is defined as
n=sqrt(a4);
where a4 is a 1x1 complex number. So n is a 1x1 complex number as well. The error message Attempted to access n(-0.2); index must be a positive integer or logical is telling you that the code is treating n as a vector and that you are trying to access an element using the index -0.2, which is negative and not an integer.
As n is not an array then accessing it in this manner does not make sense. So you have probably missed a multiplication sign. And so instead of
sinh(n(y-h1))
it should be
sinh(n*(y-h1))
This occurs in a number of places, so make sure that you do all the necessary replacements.

Community Treasure Hunt

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

Start Hunting!