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

1 vue (au cours des 30 derniers jours)
Nicholas Moung le 13 Avr 2021
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);
Wy_d= STAT(:,8);
Wz_d= STAT(:,9);
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 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Multiobjective Optimization dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by