Info

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

Help i get the error Subscript indices must either be real positive integers or logicals.

1 view (last 30 days)
here is my code,
%Matlab HW 6
%Created February 19, 2017 by Ashley Nelson
%
%Input Variables:
%Pdesrd= the desired operating point pressure
%Qdesrd=desired operating flow rate R
%Nnormal= normal operating speed of the fan/pump
%a,b,c= equation coefficients
%n=number of preformance curve data points entered by user
%
%Output Variables:
%P=Pressure outlet of the fan/pump
%a=the first coefficient
%b=the second coefficient
%c=the third coefficient
%I will use the letters d-k to represent various sums of the vectors as
%seen below in the calculations section. This is to make the equations a bit
%easier to write.
%t=a numerator
%B=a denomonator
%SSE1 will be denoted as S and SSE2 will be denoted as T
%
%input section:
Pdesrd = input('Enter the pressure for the desired operating point:')
Qdesrd=input('Enter the flow rate for the desired operating point:')
disp('The fan/pump curve is P=a+bQ+cQ^2 with Q being the desired operating point, and P represents the pressure outlet')
disp('N=Nnormal, which is the normal operating speed')
Nnormal=input('Enter the normal operating speed for the fan/pump:')
disp('enter data values for the fan or pump performance curve.Values should be entered in the corresponding order')
Pi=input('Enter the values in vector format for the PRESSURE values of the performance curve:')
Qi=input('Enter the values in vector format for the FLOW RATE values of the performance curve. enter in format [#;#;...]:')
disp('n is the number of corresponding data points entered')
n=input('Enter the number of corresponding data points:')
%
%Calculations section:
d=sum(Qi)
e=sum(Qi.^2)
f=sum(Qi.^3)
g=sum(Qi.^4)
h=sum(Pi)
i=sum(Pi.^2)
j=sum(Qi*Pi)
k=sum(Qi.^2*Pi)
c=(h-((n*k)/e)+(((n*f)/e)-d)*((j-((k*d)/e))/(e-((f*d)/e))))/(e-((n*g)/e)-(f-((g*d)/e))*((d-((n*f)/e))/(e-((f*d)/e))))
t=j-((k*d)/e)+c(((g*d)/e)-f)
B=e-((f*d)/e)
b=t/B
a=(k-b*f-c*g)/e
S=i-2*c*k-2*b*j-2*a*h+c.^2*g+2*b*c*f
T=(2*a*c+b.^2)*e+2*a*b*d+n*a.^2
SSE=S+T
SST=i-((h.^2)/n)
r^2=1-(SSE/SST)
P=a+b*Qdesrd+c*(Qdesrd.^2)
%Outputs section:
disp(Pdesrd)
disp(Qdesrd)
disp(a)
disp(b)
disp(c)
disp(r^2)
disp(Nnormal)
disp(P)
  3 Comments
Ashley Nelson
Ashley Nelson on 21 Feb 2017
when I run through the program this comes up
c =
1.0e-04 *
0.1003 0.0780 0.0557 0.0334 0.0111 -0.0111 -0.0334 -0.0557 -0.0780 -0.1003
Subscript indices must either be real positive integers or logicals.
Ashley Nelson
Ashley Nelson on 21 Feb 2017
i believe part of the problem is for j and k I am getting arrays when they should just be numbers. Help??

Answers (2)

Star Strider
Star Strider on 21 Feb 2017
You need an operator here:
t=j-((k*d)/e)+c(((g*d)/e)-f)
↑ ← *?
t=j-((k*d)/e)+c*(((g*d)/e)-f)
MATLAB does not recognise implied multiplication.

Walter Roberson
Walter Roberson on 21 Feb 2017
Your Pi is a row vector, say 1 x LP. Your Qi is a column vector, say LQ x 1. Qi*Pi is matrix multiplication of (LQ x 1) by (1 x LP) . That gives you a result which is LQ by LP. sum() works on the first non-scalar dimension by default, so that is going to be sum along the first dimension, so you are going to get a result which is 1 by LP. The same thing happens for Qi.^2*Pi .
You then have difficulties in later code because you are not expecting j and k to be row vectors.

Community Treasure Hunt

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

Start Hunting!