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

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

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

*No products are associated with this question.*

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))));

## 0 Comments