フィルターのクリア

How to use function file

1 回表示 (過去 30 日間)
Jeffrey Eiyike
Jeffrey Eiyike 2016 年 7 月 13 日
コメント済み: Jeffrey Eiyike 2016 年 7 月 25 日
%Fitness function
function y=myFitness(u)
y=0.004*u(1)-0.0031*u(2)+0.0075*u(3)+0.0015*u(4)-0.0086*u(5)+0.0077*u(6)+0.0060*u(7)-0.0060*u(8)-0.0011*u(9)+0.0093*u(10);
end
I have a code that calculate the co-efficient of u(1) to u(10). i want to change the co-efficient of u(1) to u(10) at every time steps before executing the main.m
main.m
ObjFcn=@myFitness;
nvars=10;
LB= [0 0 0 0 0 0 0 0 0 0];
UB=[500 600 120 180 60 80 30 50 30 50];
[u,fval]=ga(ObjFcn,nvars,[],[],[],[],LB,UB);

採用された回答

Jan
Jan 2016 年 7 月 13 日
編集済み: Jan 2016 年 7 月 13 日
function y = myFitness(u, c)
y = c * u(:);
end
function main
c = [0.004, -0.0031, 0.0075, 0.0015, -0.0086, 0.0077, 0.0060, -0.0060, ...
-0.0011, 0.0093];
ObjFcn = @(u) myFitness(u, c);
nvars = 10;
LB = [0 0 0 0 0 0 0 0 0 0];
UB = [500 600 120 180 60 80 30 50 30 50];
[u, fval] = ga(ObjFcn, nvars, [], [], [], [], LB, UB);
c = c + 0.01; % Or what ever the change should look like
ObjFcn = @(u) myFitness(u, c);
[u, fval] = ga(ObjFcn, nvars, [], [], [], [], LB, UB);
... etc
  2 件のコメント
Jeffrey Eiyike
Jeffrey Eiyike 2016 年 7 月 13 日
thanks for the help.
Jeffrey Eiyike
Jeffrey Eiyike 2016 年 7 月 25 日
Minimize e
subject to
e+x_{i} -0.5 >= 0 , i member of {1,2,3}
e+x_{1}+ x_{i} -1.25 >= 0 , i member of {2,3}
e+x_{2}+ x_{3}-1 >= 0 ,
x_{1}+x_{2}+x_{3}= 1.75
x_{i}- 0.5 >= 0 i member of {1,2,3}
I want to compute x_{1},x_{2} and x_{3} when is at its minimum e=0
Can you help me with this

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by