Genetic Algorithm Toolbox
Hello all,
I am using matlab genetic algortihm tool to solve a function. I can have a result when I give numbers to my variables but genetic algorithm toolbox can not solve and gives an error message as "Subscripted assignment dimension mismatch."
But if there is any dimension mismatch on my function even it could not give the result when I solve it by giving the numbers isn't it?
I am giving my function here
%Objective Function
function [CT] = objfun(CW,D)
DEW=1000;
SS=4.74;
i=10;
L=100;
j=10;
CE=5;
DP=2;
CW(1:i,1:j)=CW;
CVM(1:i,1:j)=0;
L(1:i,1:j)=L;
D(1:i,1:j)=D;
for a=1:1:i
for b=1:1:j
CV(a,b) = CW(a,b)/(CW(a,b)+SS*(1-CW(a,b)));
DEM(a,b) = 1*(SS*CV(a,b)+(1-CV(a,b)));
CSI(a,b)=0.0039*(CV(a,b)^0.803);
if 0.3 <= CW(a,b) && CW(a,b)< 0.45;
FCW(a,b) = 0.2067*CW(a,b)+1.035;
end
if 0.45 <= CW(a,b) && CW(a,b)< 0.55;
FCW(a,b) = 1.52*CW(a,b)+0.444;
end
if 0.55 <= CW(a,b) && CW(a,b)< 0.70;
FCW(a,b) = 6.1*CW(a,b)-2.075;
end
if CW(a,b) < 0.3;
C2(a,b)=0.75;
CVM(a,b)=1.1;
end
if 0.3 <=CW(a,b) && CW(a,b)< 0.7;
C2(a,b)=2.135;
CVM(a,b)=FCW(a,b)*(DP.^0.75)*0.75*(SS^0.5);
end
if CW(a,b) > 0.7;
fprintf('No economical solution exists');
end;
CQM(a,b)=CVM(a,b)*pi/4;
C1(a,b)=CE*365*24*DEM(a,b)*CQM(a,b)*CSI(a,b)*(CVM(a,b)^1.77)*L(a,b)/101.94;
C3(a,b)= 210.89*L(a,b);
C4(a,b)= 1.3744;
C(a,b)=C1(a,b)*D(a,b)^C2(a,b)+C3(a,b)*D(a,b)^C4(a,b);
CT1= sum(C);
CT=sum(CT1,2)
end
end
end
If anyone could help me I would be very glad.
Thanks...
I am using matlab genetic algortihm tool to solve a function. I can have a result when I give numbers to my variables but genetic algorithm toolbox can not solve and gives an error message as "Subscripted assignment dimension mismatch."
But if there is any dimension mismatch on my function even it could not give the result when I solve it by giving the numbers isn't it?
I am giving my function here
%Objective Function
function [CT] = objfun(CW,D)
DEW=1000;
SS=4.74;
i=10;
L=100;
j=10;
CE=5;
DP=2;
CW(1:i,1:j)=CW;
CVM(1:i,1:j)=0;
L(1:i,1:j)=L;
D(1:i,1:j)=D;
for a=1:1:i
for b=1:1:j
CV(a,b) = CW(a,b)/(CW(a,b)+SS*(1-CW(a,b)));
DEM(a,b) = 1*(SS*CV(a,b)+(1-CV(a,b)));
CSI(a,b)=0.0039*(CV(a,b)^0.803);
if 0.3 <= CW(a,b) && CW(a,b)< 0.45;
FCW(a,b) = 0.2067*CW(a,b)+1.035;
end
if 0.45 <= CW(a,b) && CW(a,b)< 0.55;
FCW(a,b) = 1.52*CW(a,b)+0.444;
end
if 0.55 <= CW(a,b) && CW(a,b)< 0.70;
FCW(a,b) = 6.1*CW(a,b)-2.075;
end
if CW(a,b) < 0.3;
C2(a,b)=0.75;
CVM(a,b)=1.1;
end
if 0.3 <=CW(a,b) && CW(a,b)< 0.7;
C2(a,b)=2.135;
CVM(a,b)=FCW(a,b)*(DP.^0.75)*0.75*(SS^0.5);
end
if CW(a,b) > 0.7;
fprintf('No economical solution exists');
end;
CQM(a,b)=CVM(a,b)*pi/4;
C1(a,b)=CE*365*24*DEM(a,b)*CQM(a,b)*CSI(a,b)*(CVM(a,b)^1.77)*L(a,b)/101.94;
C3(a,b)= 210.89*L(a,b);
C4(a,b)= 1.3744;
C(a,b)=C1(a,b)*D(a,b)^C2(a,b)+C3(a,b)*D(a,b)^C4(a,b);
CT1= sum(C);
CT=sum(CT1,2)
end
end
end
If anyone could help me I would be very glad.
Thanks...
0
Comments
[php] [/php]
code tags.
thanks.
First of all thanks for your interest, I wrote this on my previous message but it is not seen.
Anyway, I think I solved my problem on my dimension mismatch. I erased the lines
CW(1:i,1:j)=CW;
and
D(1:i,1:j)=D;
and the error disappearded.
But there is a new error disapperad now and I now want your help for the new error
now the toolbox says D is undefined, but it is my variable. Do you think I do any mistake by defining my variables.
I am posting my new function on the next message,
Thanks for your kind helps...
I'm sorry I've not been responding to this...i've been driving across the country with no access to 'net or matlab.
How are you calling this function with the genetic algorithm toolbox? I can't really troubleshoot without being able to replicate the exact error.
And genetic algortihm toolbox is easy to use, I just write my function name and number of variables on the blanks, I solved some examples by hand and with it and it works but it gives error to my function, I couldnt understand
simdiden tesekkürler
Siz çok daha İngilizce olarak eğer sonrası yardım almak için muhtemeldir. Hoşgeldiniz icrontic
CSI(a,b)=0.0039*(CV(a,b)^0.803);
Merhabalar,
Ben matlabdaki gatoolla biraz uğraştım, buralarada yazdım bir şeyler ama geri dönen bir şey olmadı. Bende çözemedim vazgeçtim.
Sonra, C'de bi kod bulup onunla GA işlemini yaptırdım. Kalyanmoy Debin yazdıgı bir kod. benim işimi gördü sende kullanmak istersen bu ismi aratırsan, kendi sitesi var zaten ordaki kodu kullanabilirsin.
Kolay gelsin