solving equation returns vector. Sum of vector=0. How?

1 view (last 30 days)
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

Accepted Answer

Matt J
Matt J on 21 Nov 2014
Edited: Matt J on 21 Nov 2014
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

More Answers (0)

Categories

Find more on Partial Differential Equation Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!