Error " index must be a positive integer or logical "

Hello all. My code is quite simple, but I dont get why there's a problem with the index " i ". Can you help me?
R1=47
R2=86
w1=15.18
w2=3.9
cm1=4.41
cm2=2.81
n=13
R=3
z=9
x=1
ni=13
v=0
while x<=z
i=0
Ri=R1
while i<ni
cmi=cm1-i((cm1-cm2)/ni);
wi=w1-i(w1-w2)/ni;
i=i+1
R1=R1+R
betai=asind(cmi/wi);
betaii=deg2rad(betai)+v
polar(betaii,Ri); grid on; hold on;
end
v=v+2*pi/z
x=x+1
end
and the error is: Screenshot_3.jpg

Answers (1)

That image of an error message does not agree with the code.
You have i((cm1-cm2)/ni) . MATLAB does not have implicit multiplication, so that is a request to index i at location (cm1-cm2)/ni . You probably want i*((cm1-cm2)/ni) and a similar fix on the next line.
There is no point in using deg2rad(betai) in that context when you could simply have used asin instead of asind and so received the answer in radians directly.

8 Comments

Well, very good remark, i've missed some asterrix-es when multiplying by index. Now the code runs fine, no errors, but resulted polar plot is empty.Normally, final result should be profile of centrifugal pump blades. I've added some comments, maybe it helps in understading.
R1=47 % inlet radi
R2=86 % outlet radi
w1=15.18
w2=3.9
cm1=4.41
cm2=2.81
R=3 % discretization pitch
z=9 % blades number
x=1 % index
ni=13 % number of discretization intervals
v=0
while x<=z
i=0
Ri=R1
while i<ni
cmi=cm1-i*((cm1-cm2)/ni);
wi=w1-i*(w1-w2)/ni;
i=i+1
Ri=Ri+R
betai=asind(cmi/wi);
betaii=betai+v
polar(betaii,Ri, '-k' ); grid on; hold on;
end
v=v+2*pi/z % circular pitch between two blades
x=x+1
end
polar() does the same thing as plot(): if you do not tell it to use a marker, then the only time it draws anything is if there are at least two consecutive finite values to plot in any one call. Your betaii and Ri are scalar when you make the polar() call, so there is not at least two consecutive finite values in the one call, so nothing visible will get drawn. If you were to change the '-k' to include a plot symbol such as '-kv' then you would see things being drawn.
Chances are that you want a single continuous line drawn. To do that, you should record the betaii and Ri values into vectors instead of plotting them immediately, and then after the loop you should polar() the entire vectors.
"To do that, you should record the betaii and Ri values into vectors instead of plotting them immediately"
yep, I've just realized that in variables table I don't have any vector, just single values vor every parameter. So how would I do this??
betaii(i) = betai+v;
Ri(i) = Ri(end) + R;
and postpone the polar() call.
ok. Now I have arrays, 13x13, both Ri and betai, but anyway, the plot is empty again. So where to postpone polar command? you can see modified code below. also in attachement is the desired result.
R1=47 % inlet radi
R2=86 % outlet radi
w1=15.18
w2=3.9
cm1=4.41
cm2=2.81
R=3 % discretization pitch
z=9 % blades number
x=1 % index
ni=13 % number of discretization intervals
v=0
while x<=z
i=0
Ri=R1
while i<ni
cmi=cm1-i*((cm1-cm2)/ni);
wi=w1-i*(w1-w2)/ni;
i=i+1
betai=asind(cmi/wi);
betaii(i)=betai+v
Ri(i)=Ri(end)+R
end
polar(betaii(i),Ri(i), '-k' ); grid on; hold on;
v=v+2*pi/z % circular pitch between two blades
x=x+1
end
"the plot is empty again"
The plot is not really empty. On each loop iteration you plot exactly one data point. Because there is only one data point and you did not specify any marker, then there is no line and no marker, and you will not be able to see anything. But if you look in the axes children you will find that data point is right there, in the middle of the plot.
Then on the next iteration you replace that point with a new point. And so on, until finally you have plotted and deleted each point, leaving only one point (with no marker and no line) on the final plot.
To plot the data you will need to make two main changes to your code:
  1. collect the data into vectors using indexing,
  2. plot the vectors after the loop.
sorry, but I am a beginner in programming. If you really want to help, just send code that works.
Last modification: I moved plot outside of while, like the last codeline. You can see the plot in attachement (sure, totally wrong). Also, I have to mention that values of those doubles 13x13 betaii and Ri are good, they matches calculations I've made by hand. Then, why plot is wrong?

Sign in to comment.

Categories

Find more on Mathematics in Help Center and File Exchange

Asked:

on 27 Mar 2019

Edited:

on 28 Mar 2019

Community Treasure Hunt

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

Start Hunting!