fmincon changes dimensions of decision variables during execution
Show older comments
I'm currently trying to perform XPS curve fitting of biochar via the fmincon function (I'm trying to link the C1s spectrum and O1s spectrum). fmincon uses as initial conditions a matrix (2X22) with al the parameters necesarry to generate signal peaks (subpeaks). The first row contains the parameters for the C1s spectrum and the second row the parameters for the O1s spectrum. The function that is being used just uses these parameters to generate the peaks and then calculates some terms (for example residuals, differences in the area of certain peaks, ...). All these terms are being add up and this variable is the output of my function. However when I try to run it, fmincon changes after a while the matrix dimensions of x0 to 1X6 without any reason. Lower and upper bounds are being used for the parameters while no (non)linear (in)equalities are being added.
I've already searched for similar questions but only found one where the same phenomenon occured. In this question the matrix dimensions were changed aswell by fmincon. https://www.mathworks.com/matlabcentral/answers/124754-the-fmincon-sets-a-wrong-dimension-for-my-decision-variables-and-that-gets-me-errors-on-dimension-di
I need the matrix dimensions to remain the same to generate the peaks.
Thanks in advance!
3 Comments
John D'Errico
on 19 Mar 2021
Edited: John D'Errico
on 19 Mar 2021
Fmincon does not occasionally change the size of your variables However, there is a very good chance that you do.
Start by learning to use the debugger, to debug your code. Watch to see if that variable ever changes size/shape. You will find a bug in your code, not in fmincon.
And, yes, I know you won't believe me. But look at it from this perspecive: how often have we seen people claim there is a bug in some piece of code that has been used millions of times without error? Compare that to how often we see a new user claim there is a bug in MATLAB, when it is actually a bug in their own code? Which is more probable? So, sorry, but not a bug in fmincon. As I said, a good excuse to learn to use the debugger.
Matt J
on 19 Mar 2021
Or at the very least, show us the code and tell us where in the code you are observing a change in the dimensions of x0.
Maxime Dekegeleer
on 19 Mar 2021
Answers (0)
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!