fmincon changes dimensions of decision variables during execution

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 commentaires

John D'Errico
John D'Errico le 19 Mar 2021
Modifié(e) : John D'Errico le 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.
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.
Although I found the bug (so the file works), I still wonder why or rather in which cases fmincon changes the dimensions of the matrix. I've rechecked the file and did not find anything about changing the dimensions (neither did the bug). The bug made the whole thing rather weird (I don't know how else to put it).
I used the debugger to find out in the first place that the dimensions changed during the iterations. My first thought was of course that there must be a bug somewhere but I couldn't find anything in the file that caused the dimensions to change. Hence my question. I'm most likely confused! Anyway it works now, thank you for the responses!

Connectez-vous pour commenter.

Réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by