Genetic Algorithm for multiple variables
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi everyone, I'm new to matlab and would like to use the GA function. I am having issues writing a proper fitness function I believe. I was wondering if anyone could help me. I am working on two GA problems one the function that I'm trying to optimize is:
max f(x1, x2) = 2x(1)^2 + x(2)^2 + 3x(3)^2
When I've tried to put this function into matlab, it gives me errors for having two variables.
The second function that I'm trying to use with GA is:
Min f(a,b,c,d) = 18abcd
Any information that anyone could provide would be greatly appreciated. Thanks.
댓글 수: 0
답변 (1개)
Alan Weiss
2017년 3월 10일
There are at least two issues here.
1. All fitness functions must be a function of ONE VARIABLE. However, this variable, usually called x, can be a vector or matrix, so this is not a restriction. For example, your fitness function would be
fun = @(x)-(2x(1)^2 + x(2)^2 + 3x(3)^2)
(Why do I have a negative sign? ga minimizes, so to get the maximum, minimize the negative.) And to me this seems to be a function of THREE variables, not two.
2. This is a smooth objective function. You should not use ga to minimize a smooth objective, you should use fmincon. I assume that you have some nonlinear constraints. If you have only linear constraints, you should use lsqlin.
3. By now you should realize that your second objective function should be coded as
fun = @(x)18*x(1)*x(2)*x(3)*x(4)
or maybe the negative of that if you are trying to maximize.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
댓글 수: 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!