Problem using lsqnonlin for minimization of a function
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
jgg
2015-12-22
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 个评论
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!