Not Sure How I'm Getting "Subscript indices must either be real positive integers or logicals"

on 17 Apr 2013

per isakson (view profile)

Here is my code, it is an iterative solution to an equation, and I keep getting the error which occurs in the denom(i) line: Subscript indices must either be real positive integers or logicals

g1=1.4;

g4=1.4;

T1=300;

T4=300;

p4p1=5;

R=287;

a1=sqrt(g1*R*T1);

a4=sqrt(g4*R*T4);

ratio= [1.01:.0001:10];

exponent=-2*g4/(g4-1);

numer=ratio;

denom=numer;

temp=denom;

for i=1:length(ratio)

```   numer(i)=(g4-1)*(a1/a4)*(ratio(i)-1);
denom(i)=sqrt(2*g1((2*g1)+(g1+1)*((ratio(i)-1))));
temp(i)=ratio(i)*((1-(numer(i)/denom(i)))^(exponent));
if abs(temp(i)-p4p1)<.01
p2p1=ratio(i);
break;
end
end```

Products

No products are associated with this question.

per isakson (view profile)

on 17 Apr 2013

`    denom(i)=sqrt(2*g1*((2*g1)+(g1+1)*((ratio(i)-1))));`

Cory Stack

Cory Stack (view profile)

on 18 Apr 2013

Wow I feel dumb lol but thanks for the help!

Join the 15-year community celebration.

Play games and win prizes!

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi