이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
fmincon doesn't give me the same results as in the previous version !!
조회 수: 1 (최근 30일)
이전 댓글 표시
Mary Ben
2013년 10월 25일
Hi, please I need your help! In fact, I have just started using the version R2013a of Matlab. To my surprise fmincon doesn't give me the same results as in the previous version (that run without any problem on another Matlab version R2007b and I have had a good results). Thanks Best Regards
댓글 수: 17
Matt J
2013년 10월 25일
There have been changes since R2007b, so it doesn't seem crazy that there might be differences in output.
But what makes you so sure the new solution isn't equivalent to the old one?
Mary Ben
2013년 10월 25일
Thank you for your answer, The resultas obtained allow to draw a curve. Before it seems correct, but now no !!! I have another thing!!
John D'Errico
2013년 10월 25일
It is virtually impossible to answer this as asked. Did something change? Of course it probably did in a 6 year span of time. Is any change assuredly what has caused your problem? Not necessarily, because all too often there are other issues. How did you transfer things to the new release? Too often one sees numerical issues, because the user simply copied some numbers from the command window, losing a great deal of precision. Did you use the new version properly? There is simply not enough accurate information provided here to make an answer.
Mary Ben
2013년 10월 25일
Yes I know it's vague what I say. I'm really stuck there, I don't have an explanation!!!for two days all went fine but once I changed the version, the results change also!!! my problem is not numeric and my code works well, but I want to know if in fmincon there is such a parameter I need to change to get a good result, for example, the number of iterations or other? Thanks
Walter Roberson
2013년 10월 25일
You did not include the code for "func", and for the run you showed, you did not indicate whether it was the R2007b or R2013a execution; which-ever it was, you did not show the other one.
Mary Ben
2013년 10월 26일
The blue curve in the file is the result with R2013a (not correct). I think is not interresting to show you the code of "func.m", my problem is no there! because it works well with R2007b. also 'func.m" is very long and had many parameters to explain you. My problem is how can I change a parameter in the matlab function "fmincon" to have a good results as in R2007b version or have you another solution?
Walter Roberson
2013년 10월 26일
Well I was going to run the code against multiple versions of MATLAB to study the behaviour. But it turns out I don't have the necessary toolbox anyhow.
Matt J
2013년 10월 26일
편집: Matt J
2013년 10월 26일
I think is not interresting to show you the code of "func.m", my problem is no there! because it works well with R2007b.
We just can't take your word for it that the mistake is in MATLAB and not in your own code, and certainly not without an example that we can run that reproduces the problem. The odds are against the issue being in fmincon. If there were a systematic problem in fmincon R2013, more people would be seeing it.
In any case, there is no simple switch that tells fmincon to behave as in R2007b.
If your func.m is too long, create a simpler example for us. If you cannot create a simple example that reproduces the differences, it's all the more likely that it is some weakness in func.m specifically that R2007 doesn't expose. Sometimes code seems to be behaving well when it isn't. A person might like how warm their house is in the winter time and think everything's great, until they discover that it's on fire!
Walter Roberson
2013년 10월 27일
The source you emailed me is not long, and could easily be posted here. However, it relies upon loading a number of data files that we do not have access to.
Also, it requires the Statistics toolbox for normcdf, as well as the Optimization toolbox for fmincon
채택된 답변
Walter Roberson
2013년 11월 1일
kmeans() involves randomization. You might not be using the same random algorithm between the two versions, or you might be using different seeds.
댓글 수: 9
Mary Ben
2013년 11월 2일
yes it's true but the difference is not huge! So in my opinion is not here the problem! well I'll try to use the same inputs to see if fmincon give me the same results
Matt J
2013년 11월 2일
Remember, we're still not sure how stable your problem is, or how many local minima it may have. Differences in initialization could matter greatly.
Mary Ben
2013년 11월 5일
please I need your help, I have the folowing error: [xl ,fval , exitflag,outputStruct]=fmincon(@func,x0,A,inB,[],[],[],[],[], options) ??? Index exceeds matrix dimensions.
Error in ==> func at 68 prd3=evec3(position3,1:m)*xl(1:m);
Error in ==> fmincon at 517 initVals.f = funfcn{3}(X,varargin{:});
Caused by: Failure in initial user-supplied objective function evaluation. FMINCON cannot continue. Thanks a lot
Matt J
2013년 11월 5일
편집: Matt J
2013년 11월 5일
It would help a lot if you got into the habit of using the
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/176280/image.png)
formatting button to put the code in your posts in a more readable and distinct font. I have been reformating for you up until now.
As for the error, you need to use
>>dbstop if error
to trap it. It will cause execution to stop inside your fun.m when it produces an error. You can then investigate what happened.
Walter Roberson
2013년 11월 5일
You will need
dbstop if caught error
In your line
prd3=evec3(position3,1:m)*xl(1:m);
do you want matrix multiplication, , or do you want element-by-element multiplication, . ?
The error message is probably suggesting that x1 does not have at least "m" entries.
Mary Ben
2013년 11월 5일
I want multiply a matrix evec3(position3,1:m) by a vector xl (1:m). such as m=10 , position3= 20.
추가 답변 (4개)
Mary Ben
2013년 10월 27일
I created a simple example of my function. please See attached file to get information on my func.m
댓글 수: 29
Mary Ben
2013년 10월 29일
편집: Matt J
2013년 10월 29일
please See attached file of my results.
function main()
m=10;
x0=zeros(m,1);
xl=[];
options = optimset('Display','iter');
[xl]=fmincon(@func,x0,A,inB,[],[],[],[],[], options);
To3=[];pr3=[];
for i=1:m
pr3=[pr3 xl(i)*Ab1(:,i)];
end
Prd3=sum(pr3');
To3=B1'+Prd3;
y = linspace(0,1,256);
figure,plot(y,To3,'b');
Matt J
2013년 10월 29일
ExampleFunc.zip contains data used by func.m, but I cannot see where it contains the solution you obtained from R2007 and R2013.
Mary Ben
2013년 10월 29일
for the solution of R2007b I can't get it back, but I can send you the solution of R2013a
Matt J
2013년 10월 29일
편집: Matt J
2013년 10월 29일
Your function main() will not work because you haven't defined A, inB, Ab1 and others. Please give complete code that can be run start to finish.
for the solution of R2007b I can't get it back
What do you mean you can't get it back? You created this example just a few days ago and you verified at that time that it produces a significantly different answer from R2007b.
Mary Ben
2013년 10월 29일
yes but the contraints are so large!! I try to send them one by one but I can't!!
Matt J
2013년 10월 29일
편집: Matt J
2013년 10월 29일
Myriam, I am confused about what you're saying you can provide. If I have both R2007 and R2013 installed on my computer, do you have a small example that I can run that you think will give me significantly different results on each? And, can you give me a .mat file with the final result of fmincon that you expect me to obtain in each case?
Mary Ben
2013년 10월 29일
no I don't have because the Image Iuse it's very large, with R20013a I obtain: xl =
0.2191
-0.3425
0.0989
0.0018
0.0092
-0.0336
0.0166
-0.0019
0.0054
-0.0275
Walter Roberson
2013년 10월 30일
Matt J
2013년 10월 30일
편집: Matt J
2013년 10월 30일
no I don't have because the Image Iuse it's very large, with R20013a I obtain:
If we can't run it, there's no use in sending us part of it. My suggestion would be this:
- Re-install R2007b, but do not uninstall R2013a.
- Re-run your code on both R2007b and R2013a.
- Save the fmincon results from both versions to .mat files. By "results", I mean not only xl but also [fval, exitflag,outputStruct]
- Load both solutions xl from the .mat files into R2007b. Compute the objective function values of both solutions and similarly the results of constraint functions. Save those. Do the same in R2013a.
- Report/post all of the above to us.
My best guess for now is that your function might have multiple global minima. Problems with a continuum of non-unique global solutions are unstable and small changes in implementation can give drastically different results. In any case, the above data will give us a hint whether this is what's occuring.
Matt J
2013년 10월 31일
please See attached file my results with R2008b and R2013a.
Were these run on the same data? From the plots, it doesn't look like it.
Matt J
2013년 10월 31일
편집: Matt J
2013년 10월 31일
Both in the first .zip file and the second one that you posted, the data scatter plots in R2008 and R2013 look different. Also, the initial f(x) values printed out by fmincon are definitely different. In R2008, I see f(x0)=41.1541 whereas in R2013, I see f(x0)=41.1526.
Therefore, your function implementation, your data, your initial guess or a combination of these have changed.
Mary Ben
2013년 10월 31일
yes it's true!! but I use the same code and data for all. I meant for R2008b and R20013a, and at the same time it give me both results differents!! I don't understand how it's changed!!
Mary Ben
2013년 11월 1일
yes but at least, why not give me closer results!!! The second curve is totally different!!
Mary Ben
2013년 11월 1일
you meant func.m? no I use the same function!! and it's no related with the points I think?! In fact, to have the points in the plot, I use kmean algorithm for partiton image. As you have noticed it wasn't the same distribution of points!!!
Matt J
2013년 11월 1일
편집: Matt J
2013년 11월 1일
In the Word doc you sent, the R2008 fmincon output printed the following initial iteration data to the screen
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/176199/image.png)
whereas the R2013 fmincon output was
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/176201/image.png)
Do you understand what the entries f(x)=41.1541 and f(x)=41.1526 mean? Do you understand why it is significant that they are different? They are the initial values f(x0) of your objective function before fmincon has started to do any work. If you are minimizing the same f(x) starting from the same initial point x0 in both R2008 and R2013, these values should be very much the same.
Since they are not the same then, to repeat, you have a difference either in f() or in x0. It is not an fmincon issue. You should put those things under a microscope and see why f(x0) is not the same in both versions.
Matt J
2013년 11월 1일
it's normal to obtain a different f(x0) because f() is related to the points of the plot
If f() depends partly on the scattered point data and you are using a different set of points in each test then why do you expect the tests to be comparable!?!?!
Matt J
2013년 11월 1일
Well, you need to verify that. Before you blame a difference between R2008 and R2013, you need to run the exact same experiment in both.
Matt J
2013년 11월 1일
Incidentally, alpha shapes might be a better way of extracting the lower envelope. See, for example
댓글 수: 2
Mary Ben
2013년 11월 2일
thank you for your help! the function you sent me it draws a curve from points but in my code I want to optimize a function f () to obtain a vector x in order to plot the lower envelop.
Matt J
2013년 11월 2일
You should be able to obtain an envelope for the points by choosing parameters appropriately.
Mary Ben
2013년 11월 5일
편집: Mary Ben
2013년 11월 5일
[xl ,fval , exitflag,outputStruct]=fmincon(@func,x0,A,inB,[],[],[],[],[], options)
Caught-error breakpoint was hit in func at line 68. The error was:
Index exceeds matrix dimensions.
68 prd3=evec3(position3,1:m)*xl(1:m);
댓글 수: 12
Matt J
2013년 11월 5일
Something like the following
>> x=rand(1,5); x(6)
Index exceeds matrix dimensions.
happened at line 68 in your objective function. DBSTOP should have put you on that line, where you can check the sizes of evec3 and xl.
Matt J
2013년 11월 5일
편집: Matt J
2013년 11월 5일
but when I start using fmincon I have xl=[]
You may have verified fun(x0) when x0 is the input, but the error is being generated by a different input x1 (which you don't know). The whole point of using DBSTOP is to trap the event where fmincon sends x1 to fun() and to freeze program execution at that moment. You can then see what x1 is and investigate why it leads to xl=[].
Matt J
2013년 11월 5일
You may have forgotten that we haven't see the code, don't know what it's doing, and don't know what lines come before and after line 68. We therefore can't know what line 68 is trying to accomplish and how it should be changed.
Matt J
2013년 11월 5일
편집: Matt J
2013년 11월 5일
If N is the number of unknown variables, you must pass fmincon an initial guess vector x0 of length N. Among other things, this is how fmincon knows how many unknowns to try to solve for.
Incidentally, it is bad practice to load fixed data to your fun.m from .mat files. See here for better ways to pass fixed known parameters to functions,
Mary Ben
2013년 11월 7일
편집: Mary Ben
2013년 11월 7일
I have downloaded a program written in C, and wish to run it in Matlab. To do this is use the mex to compile it into Matlab. This has worked for me with R20013a. However, I tried to use it today with R2008b and I got the error;
>> mex FiltreShenCastan.c
Error: Could not find the compiler "cl" on the DOS path.
Use mex -setup to configure your environment properly.
C:\PROGRA~1\MATLAB\R2008B\BIN\MEX.PL: Error: Unable to locate compiler.
??? Error using ==> mex at 213
Unable to complete successfully.
>>
I need your help. Thanks!
댓글 수: 4
Matt J
2013년 11월 7일
Use mex -setup to specify a compiler. You would have had to do this in any new installation of MATLAB.
Mary Ben
2013년 11월 7일
I did it but the same error appear!!
% >> mex -setup
Please choose your compiler for building external interface (MEX) files:
Would you like mex to locate installed compilers [y]/n?
Select a compiler:
[1] Microsoft Visual C++ 2008 Express in C:\Program Files ( (x86)\Microsoft Visual Studio 9.0
[0] None
Compiler: 1
Please verify your choices:
Compiler: Microsoft Visual C++ 2008 Express
Location: C:\Program Files (x86)\Microsoft Visual Studio 9.0
Are these correct [y]/n? y
*****************************************************************************
Error: Could not find the 64-bit compiler. This may indicate that the
"X64 Compilers and Tools" or the Microsoft Windows Software
Development Kit (SDK) is not installed. To build 64-bit MEX- files
Microsoft Visual C++ 2008 Express Edition requires that these two
packages are installed properly.
************************************************************************* ****
Trying to update options file: C:\Users\mariem\AppData\Roaming\MathWorks\MATLAB\R2008b\mexopts.bat From template: C:\PROGRA~1\MATLAB\R2008b\bin\win64\mexopts\msvc90freeopts.bat
Done . . .
************************************************************************ Warning: The MATLAB C and Fortran API has changed to support MATLAB variables with more than 2^32-1 elements. In the near future you will be required to update your code to utilize the new API. You can find more information about this at: http://www.mathworks.com/support/solutions/data/1-5C27B9.html? solution=1-5C27B9 Building with the -largeArrayDims option enables the new API. ***********************************************************************
Matt J
2013년 11월 7일
Hmmm. What about what it says about SDK? Are you sure it's installed? To be certain, it might be worthwhile just reinstalling both MS Visual C++ and SDK.
In any case, if you continue to have problems, I would post it as a new question/topic. It will have better visibility to the community that way.
참고 항목
카테고리
Help Center 및 File Exchange에서 Function Handles에 대해 자세히 알아보기
태그
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)