Minimizing a prebuilt cost function
Afficher commentaires plus anciens
I hope this reaches everyone well.
I have been attempting to minimize a complex function, deependent on a 6x7 inital guess matrix. I have built code that will output a weighted least squares difference between the expiremental and predicted data. Is there a way to use fmincon, fminsearch, etc... to minimize this value formed via the cost function?
To sumarize, I have a model that I transformed into a function with its only input being that 6x7 inital guess matrix, which outputs a value that exhibits the difference between the numerical simulated and expiremental. I wish to minimize this value, using fmincon, or any other solver to form guesses input into this function.
Thank you for your time!
Kevin
10 commentaires
Torsten
le 9 Fév 2023
So your model tries to identify 6*7 = 42 model parameters ?
You should reduce the number of unknowns to be fitted drastically before using an optimizer.
Kevin Hanekom
le 9 Fév 2023
Modifié(e) : Kevin Hanekom
le 9 Fév 2023
Sure. Use "lsqnonlin".
It requires that - given a vector of parameters - you supply the differences between numerically simulated and experimental data. The solver tries to adjust the parameters such that the sum of the differences squared is minimized.
Kevin Hanekom
le 9 Fév 2023
Modifié(e) : Kevin Hanekom
le 9 Fév 2023
Torsten
le 9 Fév 2023
So "TsWuSph" is a function that - given values for x0 - returns your model values ?
And you know that cfinal(3,3) is just one element of the matrix "cfinal", namely the element at position (3,3) ?
And "guess" is a numerical object of the same size as x0 that supplies initial values for the parameters ?
And you should return just TsWuSph(x0) - cfinal(3,3) if this is really what you want to minimize (I doubt it !).
Kevin Hanekom
le 9 Fév 2023
Kevin Hanekom
le 9 Fév 2023
Modifié(e) : Kevin Hanekom
le 9 Fév 2023
Torsten
le 9 Fév 2023
We don't know F(1,2).
We don't know TsWuSph.
We don't know cfinal.
So we cannot tell you anything about what happens and what possibly has to be changed.
Yes to all! The absolute difference between, TsWuSph(x0) - cfinal(3,3), is what I wish to minimize.
Since cfinal(3,3) is a scalar value, that would be equivalent to solving for multiple unknowns x0 given a single equation. It is a considerably under-determined problem.
Kevin Hanekom
le 10 Fév 2023
Modifié(e) : Kevin Hanekom
le 10 Fév 2023
Réponse acceptée
Plus de réponses (1)
Just to sumarize, x0 should only be a single unkown output in this case.
c=cfinal(3,3);
[x, fval] = fminsearch( @(x0) abs(TsWuSph(x0)-c) , Guess)
Catégories
En savoir plus sur Particle Swarm dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!