Use fsolve function in genetic algorithm toolbox
1 次查看(过去 30 天)
显示 更早的评论
I have a one-variable nonlinear equation that needs to be solved with the " fsolve" function. This equation also has a parameter that should be optimized by the genetic algorithm. To use the genetic algorithm toolbox, I have to write a separate objective function file for it which should contain the " fsolve" function. But how to define the parameter to be optimized in the first line? I can not define the input variable due to the " fsolve" function.
采纳的回答
Walter Roberson
2018-7-8
fun = @(x, param) 5 + exp(-(x-param).^2);
guess = 0.12345;
ga( @(param) fsolve( @(x) fun(x, param), guess), .... )
2 个评论
Mehdi
2019-5-1
Is there a way that you could give a numerical example that I could actually run in MATLAB for better understanding? Thank you!
Walter Roberson
2019-5-1
fun = @(x, param) exp(x-param) - 1/10;
guess = 0.12345;
[P,fval] = ga( @(param) (5+fsolve( @(x) fun(x, param), guess, optimoptions('fsolve', 'Display', 'none'))).^2, 1, [], [], [], [], [], [], [], gaoptimset('display', 'iter', 'TolFun', 1e-9, 'Generations', 1000))
This looks for an x and a param such that exp(x-param) is 1/10 and x is as close as possible to -5.
Here, "close to -5" is expressed as (5+value)^2 being minimal, which would best occur when value was -5
... It could do better. ga() is not such a great optimizer.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Genetic Algorithm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!