Problem using lsqnonlin for minimization of a function
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Paulo Henrique Cardoso
le 22 Déc 2015
Réponse apportée : jgg
le 22 Déc 2015
a) yexp is a vector [100,1] containing data taken from an experimental model
b) ymod(x) is a function that calculates, for a given x, another vector [100,1]. There is a known value for x that makes yexp-ymod(x)=0
I want to use lsqnonlin to solve the minimization problem yexp-ymod; below, what I have tried:
1) Created the function handle myfunction=@(x)ymod(values)-yexp, where values I have definided as a vector [68,1] of possible values for x.
2) Inputed result=lsqnonlin(@myfunction, x0)
However, the program is giving me back for result the same value as given for x0, which is wrong.
What should I do in order to have lsqnonlin correctly solving my problem?
0 commentaires
Réponse acceptée
jgg
le 22 Déc 2015
The problem is your function handle:
myfunction=@(x)ymod(values)-yexp
The value x is never used in your function, so the optimizer has nothing to optimize: your function is a constant. You probably want something like:
myfunction=@(x)(ymod(x)-yexp);
This will take in a value x and return the output vector of values. Then, your optimum will be
result=lsqnonlin(@myfunction, x0)
The only issue is you "possible values" comment; I'm not sure what you mean by this. Are there only 68 possible values for x? If so, why not just loop over all of the values instead of optimizing. It will be much faster.
If you mean that x is bounded, then you can use the lb,ub parameters in lsqnonlin to control the value of x. If it's more complicated than just a bound, you might need to use a different solver.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Surrogate Optimization dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!