Use fsolve function in genetic algorithm toolbox

조회 수: 7 (최근 30일)
Sepanta Gharib
Sepanta Gharib 2018년 7월 8일
댓글: Walter Roberson 2019년 5월 1일
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.
  댓글 수: 1
Walter Roberson
Walter Roberson 2018년 8월 21일
Please do not close questions that have an answer.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
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
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
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 CenterFile Exchange에서 Genetic Algorithm에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by