How should the value of objective function be returned for fmincon?

1 vue (au cours des 30 derniers jours)
Hello,
I have an objective function that computes the difference between actual and predicted values. The value, f, computed below is returned to fmincon
f = (actual - predicted)
The size of actual and predicted is [ntime, nstate]. i.e ntime is the number of time points and nstate is the number of state variables
For instance, in my case both actal and predicted is of size 500 x 10 ( 500 time observations and 10 variables).
To lsqnonlin which accepts a vector values objective function , I could return `f = (actual - predicted)` directly. But I get an error that says, only a scalar value can be returned from the objective function to fmincon.
I tried the following in fmincon
f = (actual - predicted).*(actual - predicted);
f = sum(f, 'all'); % takes summation over rows (time points) and columns (variables)
But the solver didn't provide an optimal solution
Any suggestions on how to proceed?
Thanks

Réponse acceptée

Walter Roberson
Walter Roberson le 28 Mar 2020
f = sum((actual(:) - predicted(:)).^2);
  3 commentaires
Deepa Maheshvare
Deepa Maheshvare le 28 Mar 2020
Yes, it is
Walter Roberson
Walter Roberson le 28 Mar 2020
Yes, but .^2 should be more efficient than the .*

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Surrogate Optimization dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by