MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#" onclick="window._kiq.push(['set', { 'event': 'Turn off MT' }]);">ここ</a>」をクリックしてください。


Results for an optimization problem are coming different which usually does not happen.

さんによって質問されました 2019 年 4 月 2 日
最新アクティビティ AR
さんによって コメントされました 2019 年 4 月 5 日
Hi, I have coded the following model in MATLAB and GAMS, but the answers I am getting are different, which I could not conclude why is it happening.
where, .
Here , Also and are the enteries of the second, third, fourth, fifth and sixth row respectively of the attached excel file.
I = xlsread('Book1.xlsx', 'B2:F3');
GO = xlsread('Book1.xlsx', 'B4:F5');
BO = xlsread('Book1.xlsx', 'B6:F6');
n=5; m=2;s=2; q=1;
for j=1:n
for i=1:m
for j=1:n
for i=1:s
for j=1:n
for i=1:q
A1=zeros(m,n+1); A1(:,2:n+1)=I;A2=zeros(s,n+1);A2(:,2:n+1)=(-1)*GO;
E=zeros(1,n); B=zeros(1,n);
x = linprog(f,A,b,Aeq,beq,lb,ub);
The value of B orβ I got is which does not match with the answer when I calculate it using GAMS.
Please help me out with this, if I am doing any mistake in my code. That will be a great help.
Thank you.

  4 件のコメント

Yes, I have checked both are the solutions. In fact the value of beta calculated by GAMS is more than the value given by MATLAB.
I suggest you attach a .mat file with the solutions generated by both solvers (both beta and lambda).
Thanks for your help, my issue is resolved. :)

サインイン to comment.

1 件の回答

回答者: John D'Errico
2019 年 4 月 3 日
編集済み: John D'Errico
2019 年 4 月 3 日

It is a little hard to follow these equations, since you change nomenclature. Lets see, it looks like x becomes I. y is GO, and z is BO. But then you use a subscript of 5 in one place in the mathematics, but in other places it appears as a superscript. Was that intended as an exponent, or a misplaced subscript? I'm going with subscript.
Then I read in your arrays, and I saw 2 digit numbers. That leads me to an obvious question. I would first conjecture if the numbers in the arrays I, GO, BO are truly exactly known to 2 decimal places. So I see this:
>> I
I =
1.03 1.75 1.44 10.8 1.3
-0.05 -0.17 -0.56 -0.22 -0.07
>> GO
GO =
0.56 0.74 1.37 5.61 0.49
-0.09 -0.24 -0.35 -0.98 -1.08
>> BO
BO =
-0.44 -0.31 -0.21 -3.79 -0.34
A common mistake made by people when they try to compare results between different solvers is they move their data across systems using too few digits, assuming that since all that is printed out are 2 digits approximations, then those decimal places are all that was necessary.
So, when you used the other solver, were these the exact same numbers employed in the solve, or are they just approximations? If the latter, then you cannot assume two solvers would yield identically the same results. In fact, the difference might be significant. (Sorry, but this is a VERY common mistake made by people, so I would need to ask the question. It is the equivalent of a computer repairperson asking if the computer is actually plugged in, or has a charged battery, when hearing that a computer fails to boot up.)
Going beyond that point, you have 6 unknowns, thus beta and 5 lambda's. Two equality constraints, 4 inequalities. beta is unbounded, lambda is bounded below by 0. linprog happily arrived at a solution.
So, next, I would look at if you constructed the arrays properly. A, for example. Beta appears as the first unknown. Looking at the first equation, assuming I got the mapping from x to I, we have R and x as:
R =
0 0.72 0.41 9.77 0.27
0.51 0.39 0 0.34 0.49
I =
1.03 1.75 1.44 10.8 1.3
-0.05 -0.17 -0.56 -0.22 -0.07
There again, I is x.
Hmm. Linprog assumes linear inequality constraints of the form: A*x <= b. And your first inequality would be
sum(lambda(j)*x(1,j)) <= x(i,5) + beta*R(1,5)
where the sum is over j.
Now, what is A(1,:)?
ans =
0.27 1.03 1.75 1.44 10.8 1.3
Now we should see where you screwed up. You have the WRONG sign for the element A(1,1).
Beta is a variable, and unknown. So you need to move it to the left of the inequality. Therefore, you had to write
A1(:,1) = -R(:,k);
But you did not. I've not checked any further, as this seems to be a clear error in your transcription. You probably need to check the other coefficients of beta in the other equations too.
I'd suggest you use better nomenclature, better variable names, as that makes your code easier to read and debug. I'd also suggest you use white space more, as dense code is hard to read, to find subtle errors like this. If I was not wondering if you had made exactly that error, I might not have found it as quickly as I did. The reason I looked immediately at A(1,1), is your equations have beta on the wrong side of the inequality. You had to remember to flip the sign, and you did not do so.

  1 件のコメント

Thank you so much for your response and time. There was a mistake in my model and I have corrected that there in the model. I apologise for that and thank you so much for your advice. :)

サインイン to comment.

Translated by