%%Fitness function
function MCWQIAVG = mytrial(D1,D2,D3)FEavgx = 0;FEavgy = 0;FEavgz = 0;for t = 1:26 x = D1*exp(0.03*t); if x>=0 && x<=0.1 FE = 1; end if x>0.1 && x<0.2 FE = -10*x+2; end if x>=0.2 && x<=0.5 FE = 0; end if x>0.5 && x<0.6 FE = 10*x-5; end if x>=0.6 && x<=1 FE = 1; end FEavgx = (FEavgx + FE)/2;endfor t = 1:26 x = D2*exp(0.03*t); if x>=0 && x<=0.1 FE = 1; end if x>0.1 && x<0.2 FE = -10*x+2; end if x>=0.2 && x<=0.5 FE = 0; end if x>0.5 && x<0.6 FE = 10*x-5; end if x>=0.6 && x<=1 FE = 1; end FEavgy = (FEavgy + FE)/2;endfor t = 1:26 x = D3*exp(0.03*t); if x>=0 && x<=0.1 FE = 1; end if x>0.1 && x<0.2 FE = -10*x+2; end if x>=0.2 && x<=0.5 FE = 0; end if x>0.5 && x<0.6 FE = 10*x-5; end if x>=0.6 && x<=1 FE = 1; end FEavgz = (FEavgz + FE)/2;endMCWQIx = 100-(FEavgx/(0.05*FEavgx+0.05));MCWQIy = 100-(FEavgy/(0.05*FEavgy+0.05));MCWQIz = 100-(FEavgz/(0.05*FEavgz+0.05));MCWQIAVG = (MCWQIx + MCWQIy + MCWQIz)/3;end%%this is the fitness function that I have defined and the main portion is mentioned below
rng defaultfitnessfcn = @mytrialnvars = 3;lb = [0.2,0.2,0.2];ub = [0.4,0.4,0.4];[x,favl]= ga(fitnessfcn,nvars,lb,ub)%they are showing an error in the main portion mentioned above
%need help in correcting the error
MATLAB: Error in the code metioned below
gaMATLAB
Related Question
- How do you rewrite the nested if statement as a loop
- Function sf =aaa(u) | Error: Function definitions are not permitted in this context.
- Is there a command to plot unit vectors in 3D
- How do you rewrite the nested if statement as a loop
- Does ode45 say that I don’t have enough input arguments
- How to sort only first column in matlab
Best Answer