How do I have to create a scalar function with multiple equations for "particleswarm" function

1 次查看(过去 30 天)
Hello!
I'm using 'particleswarm' for optimization of parameters in matlab and I'm getting error on returning objective function to scalar. Could someone please help me with this. Thank you in advance!
My function is:
function F = SimFnc2(X,t,Wx_r,Wy_r,Wz_r)
%Initial values
dt=1/32;
g=9.8065;
t=1:2003; %number of points
%Importing data from STAT
STAT=importdata('STAT.txt');
nx= STAT(:,10);
ny= STAT(:,11);
nz= STAT(:,12);
Wx_d= STAT(:,7);
Wx_r=deg2rad(Wx_d);
Wy_d= STAT(:,8);
Wy_r=deg2rad(Wy_d);
Wz_d= STAT(:,9);
Wz_r=deg2rad(Wz_d);
Theda_iz=STAT(:,13);
Gamma_iz=STAT(:,14);
Erx=X(1);
Ery=X(2);
Erz=X(3);
Theda=(((Wy_r+Ery).*sin(Gamma_iz))+((Wz_r+Erz).*cos(Gamma_iz)));
Gamma=((Wx_r+Erx)-(tan (Theda_iz).*((Wy_r+Ery).*cos(Gamma_iz)-(Wz_r+Erz).*sin(Gamma_iz))));
F=[Theda;Gamma];
end
And I'm getting the following error report:
Error using particleswarm>makeState (line 703)
Objective function must return scalar values.
Error in particleswarm>pswcore (line 169)
state = makeState(nvars,lbMatrix,ubMatrix,objFcn,options);
Error in particleswarm (line 151)
[x,fval,exitFlag,output] = pswcore(objFcn,nvars,lbRow,ubRow,output,options);
Error in Sol_SimFnc (line 15)
[x,fval]=particleswarm(@SimFnc2,nVar)

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multiobjective Optimization 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by