Genetic Algorithm for multiple variables
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Alan Weiss
il 10 Mar 2017
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 Commenti
Vedere anche
Categorie
Scopri di più su Genetic Algorithm in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!