index out of bounds because numel(NV)=1.

This is my matlab code
N=7;
NV = sym(zeros(N,1));
for i=1:1:N
NV(i) = sym(sprintf('N%d', i));
end
xi = zeros(N-1,1);
for k=1:1:N-1
xi(k) = k/(2*k+1);
end
banana_N7 = @(NV)(( 1 / ((1-xi(1))*NV(1)) * ( (a+log(d)-log(NV(1)))^(-b-1) - (a + log(d) - log(xi(1) * NV(1)))^(-b-1)) - 1/NV(7) * (a + log(d) - log(NV(7)))^(-b-1))^2 + ( 1 / ((1-xi(2))*NV(2)) * ( (a+log(d)-log(NV(2)))^(-b-1) - (a + log(d) - log(xi(2) * NV(2)))^(-b-1)) - 1/NV(7) * (a + log(d) - log(NV(7)))^(-b-1))^2 + ( 1 / ((1-xi(3))*NV(3)) * ( (a+log(d)-log(NV(3)))^(-b-1) - (a + log(d) - log(xi(3) * NV(3)))^(-b-1)) - 1/NV(7) * (a + log(d) - log(NV(7)))^(-b-1))^2 + ( 1 / ((1-xi(4))*NV(4)) * ( (a+log(d)-log(NV(4)))^(-b-1) - (a + log(d) - log(xi(4) * NV(4)))^(-b-1)) - 1/NV(7) * (a + log(d) - log(NV(7)))^(-b-1))^2 + ( 1 / ((1-xi(5))*NV(5)) * ( (a+log(d)-log(NV(5)))^(-b-1) - (a + log(d) - log(xi(5) * NV(5)))^(-b-1)) - 1/NV(7) * (a + log(d) - log(NV(7)))^(-b-1))^2 + ( 1 / ((1-xi(6))*NV(6)) * ( (a+log(d)-log(NV(6)))^(-b-1) - (a + log(d) - log(xi(6) * NV(6)))^(-b-1)) - 1/NV(7) * (a + log(d) - log(NV(7)))^(-b-1))^2 + (( (Cm * b^2 * a^b / ( c*NV(7))) * (a+log(d)-log(NV(7)))^(-b-1)) - ( 1 / (NV(7) + (1 - xi(1)) *NV(1) + (1-xi(2))*NV(2) + (1-xi(3))*NV(3) + (1-xi(4))*NV(4) + (1-xi(5))*NV(5) + (1-xi(6))*NV(6)) * (Cr + (N-1) * Cp + Cm * b * a^b / c * (((a+log(d)-log(NV(1)))^(-b)) + (((a+log(d)-log(NV(2)))^(-b))) + (((a+log(d)-log(NV(3)))^(-b))) +(((a+log(d)-log(NV(4)))^(-b))) +(((a+log(d)-log(NV(5)))^(-b))) + (((a+log(d)-log(NV(6)))^(-b))) + (((a+log(d)-log(NV(7)))^(-b))) - ((a+log(d)-log(xi(1)*NV(1)))^(-b)) - ((a+log(d)-log(xi(2)*NV(2)))^(-b)) -((a+log(d)-log(xi(3)*NV(3)))^(-b)) -((a+log(d)-log(xi(4)*NV(4)))^(-b))- ((a+log(d)-log(xi(5)*NV(5)))^(-b))- ((a+log(d)-log(xi(5)*NV(5)))^(-b))))))^2);
[NV, fval] = fminbnd(banana_N7, 0, 1)
And the result is that "index out of bounds because numel(NV)=1."
I don't know what the problem is.
Thank you in advance

Answers (2)

The function handle you pass to fminbnd must accept a (numeric) scalar on input and return a numeric scalar. The function handle you give, banana_N7, accepts NV as its input argument, so during execution of the function handle, NV will be a numeric scalar. You attempt to access that numeric scalar at elements 2 and upwards.
If you were to change the name of the argument, NV, so that banana_N7 computed using the symbolic array NV, then the expression computed would be symbolic (involving N1 to N7) and that would not be a valid output from the function handle (because it would not be a numeric scalar).
Your banana_N7 also attempts to use the values of a number of undefined variables such as a, b, d, Cr, Cp.
There is no obvious correction to your function, as we cannot tell what you intended to do.
Youngchan
Youngchan on 15 May 2012
Thank you
There exist a,b,c,d,Cr,Cp values.
What I want to do is to find the minimum value of the equation of banana_N7 that have the variables NV.
what function is suitable for this problem?

1 Comment

The minimum value? So you would want to find the N1, N2, through to N7, that minimized the equation? If so then chances are that there would be no unique solution, and there would be many local minima that a regular search routine would get stuck in. You would probably need to use multistart from the Global Optimization Toolbox.
I am not going to bother to try running the equation through Maple to look for minima: the a^b together with the expressions to the power of (-b) make the problem symbolically intractable.

Sign in to comment.

Categories

Find more on Optimization in Help Center and File Exchange

Tags

Asked:

on 14 May 2012

Community Treasure Hunt

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

Start Hunting!