keep getting "too many output arguments" error while using the optimization tool box

1 vue (au cours des 30 derniers jours)
i was trying to use the tool box to do an optimazation but it just not working. i keep getting the same error meaasage.
here's my objective function
function f=spring_fun(x)
f=(pi^2*x(2)*x(3)^2*(x(1)+2))/4;
end
and my constraints function:
function g=springcon(x)
G=25.5e6; %shear modulus A
%G=41.4e6; %shear modulus T
%G=79.3e6; %shear modulus S
Fmax=5000;
Cf=(4*(x(2)/x(3))-1)/(4*(x(2)/x(3))-4)+(0.615*x(3))/x(2);
K=(G*x(3)^4)/(8*x(1)*x(2)^3);
singma_p=1500/K;
lf=(Fmax/K)+(1.05*(x(1)+2)*x(3));
smax=1.3e9;
sigma_pm=6;
Dmax=3;
dmin=0.2;
lmax=14;
sigma_w=1.25;
Fp=1500;
g(1)=(8*Cf*Fmax*x(2)/pi*x(3)^3)-smax;
g(2)=lf-lmax;
g(3)=dmin-x(3);
g(4)=x(2)-Dmax;
g(5)=3-(x(2)/x(3));
g(6)=sigma_p-sigma_pm;
g(7)=sigma_p+((Fmax-Fp)/K)+1.05*(x(1)+2)*x(3)-lf;
g(8)=sigma_w-((Fmax-Fp)/K);
it just say "too many output argument" can someone tell me what's going on?please.
thank you.

Réponses (1)

Brendan Hamm
Brendan Hamm le 30 Nov 2018
Your non-linear constraint function needs to pass 2 output arguments back with the following calling signature:
function [c,ceq] = nonlcon(x)
The outputs will enforce the constraints,
If you do not have one of the constraints then you can assign the output the empty array. For example with no non-linear equality you pass the empty array for that output.
function [c,ceq] = nonlcon(x)
c = x.^4; % Constraint we do have
ceq = []; % No equality constraint
end

Catégories

En savoir plus sur Get Started with Optimization Toolbox dans Help Center et File Exchange

Produits


Version

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by