fminsearchbnd morphs the matrix

I'm trying to run fminsearchbnd while passing these variables: Plats (4 value vector) Pcn (7,4 matrix) Mm (constant) Avail (7,10 matrix) Percs (10,4 matrix)
I'm trying to give fminsearchbnd "Percs" (percentages) as the argument to use, but it keeps morphing the size and going out of bounds.
function x = solver(Percs, Plats, Pcn, Mm, Avail)
%Easy way to round everything to 2 decimal places
format bank;
Req = zeros(7,4);
for i=1:7
for j=1:4
Req(i,j) = Plats(j)*Pcn(i,j)*Mm;
end
end
Pulled = zeros(7,10);
Rem = zeros(7,10);
for i=1:10
for j=1:7
%-*-*-*-*-Line 47 below-*-*-*-*-
Pulled(j,i) = (Percs(i,1)*Req(j,1)*.01) + ...
(Percs(i,2)*Req(j,2)*.01) + ...
(Percs(i,3)*Req(j,3)*.01) + ...
(Percs(i,4)*Req(j,4)*.01);
Rem(j,i) = Avail(j,i) - Pulled(j,i);
end
end
x = sum(Req,2) - sum(Pulled,2);
end
The idea is to get x as close to zero as possible while finding the optimal percentages (Perc) and keeping the remaining (Rem) numbers at or above a certain threshold (could be zero or -70 for example). I haven't figured out how to incorporate the threshold on Rem yet, but I'm already running into problems.
I'm running the below command:
xsol = fminsearchbnd(@(Percs) solver(Percs, Plats, Pcn, Mm, Avail), Percs, LB, UB)
LB and UB are 10,4 matrices of 0's and 100's respectively.
I'm receiving the following error:
Attempted to access Percs(2,1); index out of bounds because size(Percs)=[1,40].
Error in ==> solver at 47
When I type size(Percs) immediately at the prompt, it says ans = 10.00 4.00.
This is the first time I've ever used MATLAB, if you couldn't tell. Please be gentle ;)
What am I doing wrong?

1 comentario

Andrew Newell
Andrew Newell el 19 de Mayo de 2011
Why wouldn't we be gentle? This is a good question!

Iniciar sesión para comentar.

 Respuesta aceptada

John D'Errico
John D'Errico el 20 de Mayo de 2011

1 voto

I've just uploaded a new version of fminsearchbnd, which should solve the problem, and sent Zack a copy via direct e-mail.

1 comentario

Zack
Zack el 20 de Mayo de 2011
Per our email conversation, I am getting a trial for optimization toolbox due to the large number of parameters my problem requires. Thanks again!
Hopefully the new version of fminsearchbnd will help someone else.

Iniciar sesión para comentar.

Más respuestas (1)

Andrew Newell
Andrew Newell el 19 de Mayo de 2011

1 voto

In fminsearchbnd, line 83 is
x0 = x0(:);
This seems to be the source of the problem. This function is from the File Exchange and I suggest you contact its author directly.

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 19 de Mayo de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by