Info

This question is closed. Reopen it to edit or answer.

Genetic Algorithms LOTS OF ERROR HELP HELP HELP

1 view (last 30 days)
ARJUN SINGH
ARJUN SINGH on 16 Apr 2014
Closed: MATLAB Answer Bot on 20 Aug 2021
Hello Everyone!
I'm new to matlab and I'm working on getetic algorithms my fitness function is:
y = (a(1,i)*(1-exp(-b(i)*T(i)))) + (a(2,i)*(1-(1+b(i)*T(i))*exp(-b(i)*T(i)))) + (a(3,i)*(1-(1+ b(i)*T(i)+((b(i)*T(i))^2)/2)*exp(-b(i)*T(i))));
AND I write it in editor in this way:
function y = m(a,b,T)
a=[313,332,298;107,97,64;81,76,32];
b=[0.00368,0.00234,0.0018];
T=zeros(1,3); %Initilization of T with zeros
for i=1:3
y = (a(1,i)*(1-exp(-b(i)*T(i)))) + (a(2,i)*(1-(1+b(i)*T(i))*exp(-b(i)*T(i)))) + (a(3,i)*(1-(1+ b(i)*T(i)+((b(i)*T(i))^2)/2)*exp(-b(i)*T(i))));
T(:,i);
end
My constraint function
is shown in picture and I wrote it in this way:
function [c,ceq] = mrc(C,m)
C=[5,5,5;10,10,10;15,15,15]
m=zeros(3,3)
R=zeros(1,3)
l;
for v = 1:3
c = [
T(v)- 5000;
2.7- R(v);
C(1)(v)*m(1)(v)*T(v) + C(2)(v)*m(2)*T(v) + C(3)(v)*m(3)(v)*T(v)-10000;
]
end
ceq = [];
The input parameters are shown in image:
Where variables denote:
There are lots and lots of error some of them are: *()-indexing must appear last in an index expression.(constraint function) *Cannot access T(3) Because value of T(2) is .......(fitness function) *not enough input parameter(IN ga tool box)
Output must look like:
Every help would be appreciated for any other detail please email me to arjunbrain96@gmail.com Please help I really need it and if you were able to get the same output as shown in picture that would be great! send me the code too :P

Answers (1)

Walter Roberson
Walter Roberson on 16 Apr 2014
Your line
C(1)(v)*m(1)(v)*T(v) + C(2)(v)*m(2)*T(v) + C(3)(v)*m(3)(v)*T(v)-10000;
needs to be
C(1,v)*m(1,v)*T(v) + C(2,v)*m(2)*T(v) + C(3,v)*m(3,v)*T(v)-10000;
In MATLAB, indexing a 2D array with a single index does not extract a row: instead it extracts a single element in a process known as "linear indexing".

Community Treasure Hunt

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

Start Hunting!