Subscript indices must either be real positive integers or logicals
2 views (last 30 days)
Show older comments
I am getting "Subscript indices must either be real positive integers or logicals" error in line rslossavg=(i-1)*rslossavg/i+rosenbrock(x)/i;.. Can anyone help me? Thanks.
n=2000;
cases=50;
x_0=[1 1]';
grad='gradloss';
g_0 = grad(x_0);
a=1;
A=0;
alpha=0.8;
beta=1;
s_0=0;
rslossavg=0;
rslossavgsq=0;
t=2.0096;
v=0.5;
for i=1:cases
replication=i;
x=x_0;
g=g_0;
s=s_0;
ak=(a/(1+A)^alpha);
for k=1:n
x=x-ak*g
gnew=feval(grad,x)'
if gnew'.*g<0
s=s+1;
else
end
tk=abs(s/k-1/2);
if tk>=v
ak=a/(k+A+1)^alpha;
else
ak=a/(k+A+1)^beta;
end
g=gnew';
end
rslossavg=(i-1)*rslossavg/i+rosenbrock(x)/i;
rslossavgsq=(i-1)*rslossavgsq/i+(rosenbrock(x)^2)/i;
end
mean=rslossavg;
stdevmean=(((cases/(cases-1))*(rslossavgsq-mean^2))^.5)/(cases^.5);
% Confidence intervals
[mean-t*stdevmean,mean+t*stdevmean]
[EDITED, Jan, <http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup code formatted]
0 Comments
Answers (1)
Jan
on 20 Dec 2012
Edited: Jan
on 20 Dec 2012
rosenbrock seems to be a variable and not a function as one could expect. Then rosenbrock(x) requires a positive integer x as index. What does this reply:
which('rosenbrock', '-all');
There are some other problems:
x_0=[1 1]';
grad='gradloss';
g_0 = grad(x_0);
Now grad is the string 'gradloss' and in consequence g_0 is the string 'gg'. Is this intented? I guess you want:
grad = @gradloss
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!