My fitness function for timetabling in ga

2 ビュー (過去 30 日間)
yiwen yim
yiwen yim 2018 年 3 月 15 日
コメント済み: Star Strider 2018 年 3 月 15 日
Im trying to write the fitness function for my timetabling project. however, it keeps giving me an error saying _"Undefined function or variable 'x1'.
Error in my_fun (line 5) y = w1*x1 + w2*x2 + w3*x3;"_
May i ask for help how to correct this error? Its a really simple code. Im still trying the most basic and experimenting on how to make it work. Please advice. the piece of code is as follows.
function y = my_fun(x)
w1 = 0.8;
w2 = 0.8;
w3 = 0.8;
y = w1*x1 + w2*x2 + w3*x3;

採用された回答

Star Strider
Star Strider 2018 年 3 月 15 日
You need to subscript the ‘x’ variables, since they are elements of a vector.
You can also create ‘my_fun’ as an anonymous function:
w1 = 0.8;
w2 = 0.8;
w3 = 0.8;
my_fun = @(x) w1*x(1) + w2*x(2) + w3*x(3);
  2 件のコメント
yiwen yim
yiwen yim 2018 年 3 月 15 日
alright. thanks for the help.
Star Strider
Star Strider 2018 年 3 月 15 日
As always, my pleasure.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by