Attempted to access A(0); index must be a positive integer or logical.

  • Follow


I am trying to run this:

N=[26, 40.4, 49.6, 56.4, 62.1, 67.4, 72.4, 77.3, 82.2, 87.2, 92.5, 98.1, 104, 110.8, 118.5, 125.5, 138.5, 153, 178.8, 210.6];

M=0.000001*N 

A=[3596.212, 270.068; 7907.681, -12159.460; 13585.443, -4913.489; 15361.970, -21745.037]

X=(M.*(6.023e+23))./((M.*(6.023e+23))+(7.122*(1.0e+19)))

for j=0:7
    S=S+(A(j).*((2.*X-1).^j))
    break
end

s=sum(S)

DGex=(X.*(1-X)).*s

TE=8.314.*304.15.*((X.*log(X))+((1-X).*log(1-X)))

DGM=DGex+TE

But the output is:

??? Attempted to access A(0); index must be a positive integer or logical.

Error in ==> essai2 at 14
    S=S+(A(j).*((2.*X-1).^j))
0
Reply nouha 11/22/2010 1:38:04 PM

nouha wrote:
> I am trying to run this:
....
> A=[3596.212, 270.068; 7907.681, -12159.460; 13585.443, -4913.489; 
> 15361.970, -21745.037]
....
> for j=0:7
>    S=S+(A(j).*((2.*X-1).^j))
....

> But the output is:
> 
> ??? Attempted to access A(0); index must be a positive integer or logical.
....

So, don't do that...Matlab array indices are from x(1) thru x(end). 
Matlab is _NOT_ C...

--
0
Reply dpb 11/22/2010 2:12:08 PM


note:
DGex=X×(1-X)×∑_(j=0)^(j=7)▒〖A_j×(2X-1)^j 〗
0
Reply nouha 11/22/2010 2:14:04 PM

"nouha " <nouha@voila.fr> wrote in message <icdrns$cmm$1@fred.mathworks.com>...
>
> But the output is:
> 
> ??? Attempted to access A(0); index must be a positive integer or logical.
> 
> Error in ==> essai2 at 14
>     S=S+(A(j).*((2.*X-1).^j))

That's correct. Your loop runs from j=0 to j=7. When j=0, the expression you're looping over tries to evaluate A(0) .  The index j=0 is not positive.
0
Reply Matt 11/22/2010 2:15:06 PM

3 Replies
1427 Views

(page loaded in 0.021 seconds)

Similiar Articles:













7/23/2012 5:36:37 PM


Reply: