MATLAB: Solving equation returns vector. Sum of vector=0. How

condition optimisationfsolveoptimisation

Dear all,
I attempt to solve an optimisation problem. I want to solve the equation…
function [funzeta1] = Fz1(zzeta1)
funzeta1=-Ub.*zzeta1+cos((pi.*xint.*2.0)/v(1)).*(v(3).*(exp((pi.*zzeta1.*-2.0)/v(1))+exp((pi.*zzeta1.*2.0)/v(1))).*(1.0/2.0)-v(2).*(exp((pi.*zzeta1.*-2.0)/v(1))-exp((pi.*zzeta1.*2.0)/v(1))).*(1.0/2.0))+((Ub-Ui1).*(d.*zzeta1+zzeta1.^2.*(1.0/2.0)))/(d-di1)+(v(1).*zzeta1)/T-Psi1;
end
…using fsolve to determine zzeta1. As xint is a vector, zzeta1 is a vector as well, which is desired! However, C1=sum(zzeta1) shall be zero and I need zzeta1 for further computations. I had both funcitons, funzeta1 and C1 in one function and C1 returned, but I can't return both values, as C1 is a scalar and zzeta1 is a vector, so I obviously would get the error message that both can't be concatenated
How do I do it?
Any help is very appreciated.
Kind regards

Best Answer

Isn't it just a matter of adding an additional equation?
function [funzeta1] = Fz1(zzeta1)
funzeta1=-Ub.*zzeta1+cos((pi.*xint.*2.0)/v(1)).*(v(3).*(exp((pi.*zzeta1.*-2.0)/v(1))+exp((pi.*zzeta1.*2.0)/v(1))).*(1.0/2.0)-v(2).*(exp((pi.*zzeta1.*-2.0)/v(1))-exp((pi.*zzeta1.*2.0)/v(1))).*(1.0/2.0))+((Ub-Ui1).*(d.*zzeta1+zzeta1.^2.*(1.0/2.0)))/(d-di1)+(v(1).*zzeta1)/T-Psi1;
funzeta1=[funzeta(:);sum(zzeta1)]; %additional equation
end