MATLAB Answers

Cory Stack

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

Asked by Cory Stack
on 17 Apr 2013

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

  0 Comments

Tags

Products

No products are associated with this question.

1 Answer

Answer by per isakson
on 17 Apr 2013
 Accepted answer

Add a "*" to this line. It should probably read

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

  1 Comment

Cory Stack
on 18 Apr 2013

Wow I feel dumb lol but thanks for the help!


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply today