필터 지우기
필터 지우기

finding stable point for complicated contrained function - tried ga

조회 수: 3 (최근 30일)
nobody
nobody 2022년 1월 28일
댓글: Star Strider 2022년 1월 28일
Hello,
I have function with two variables and a few parameters:
function [delta] = fun(x,par)
... %does a lot of things
delta=abs(delta) %I use abs() since ga looks for minimum, not root, as I understand
%this is the last line of the function and prints to output for my testing,
%see below
I want to find the stable points aka where delta(1)==0 & delta(2)==0 for a given set of parameters.
x shall be restricted to 0 <= x(1) <= 1 and to 1-x(1)(1-x(1))*2 <= x(2) <= 1
I am not familiar enough with search and solve algorithms to understand which one would work for my function and my problem. I could even make it work with fsolve, just by brute force with many starting conditions and excluding the solutions outside the restrained area after the fact ... but of course that's quite shit and it still fails sometimes.
I wanted to try the genetic algorithm.
Since x(1)<=1, -x(1)<=0 and x(2)<=1 I would use (I guess for x(1) I could use lb and ub instead, right?)
A=[1,0;-1,0;0,1];b=[1,0,1];
and since 1-x(1)(1-x(1))*2 <= x(2) I would use
function [c,ceq] = nonLinConstrain(x)
c = (1-x(1)*(1-x(1))*2) - x(2);
ceq=[];
I first tried to run it with fixed parameters (basically without parameters)
function [delta] = fun(x,par)
if nargin<2
par=blabla;
end
...
using the command
x = ga(@fun,2,A,b,[],[],[],[],@nonLinConstrain);
But even here I get an error, which I can't quite understand. It seems to fail after receiving outputs for the second time
delta =
0.1000 0.1800
delta =
0.1000 0.1800
Error using makeState (line 67)
Your fitness function must return a scalar value.
Error in gacon (line 54)
state = makeState(GenomeLength,SubFitness,Iterate,subtype,options);
Error in ga (line 418)
[x,fval,exitFlag,output,population,scores] = gacon(FitnessFcn,nvars, ...
I would appreciate tips concerning
1) Why this won't run?
2) How to use changing parameters with ga
3) If I should try other solvers?
Thank to you all!
  댓글 수: 1
Star Strider
Star Strider 2022년 1월 28일
Here:
function [delta] = fun(x,par)
the value for ‘delta’ needs to be a scalar.
There is not enough information to provide a more detailed solution.

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

답변 (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