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

Andrew Newell
Andrew Newell 2011년 5월 19일
Why wouldn't we be gentle? This is a good question!

댓글을 달려면 로그인하십시오.

 채택된 답변

John D'Errico
John D'Errico 2011년 5월 20일

1 개 추천

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

댓글 수: 1

Zack
Zack 2011년 5월 20일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Andrew Newell
Andrew Newell 2011년 5월 19일

1 개 추천

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.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

질문:

2011년 5월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by