Soma
Soma

Reputation: 743

is it possible use non-linear function ifor objective in julia?

how is it possible to use non-linear function for objective and constraints. for example some function erroes are happened

#-----Model parameters--------------------------------------------------------
sig=0.86;
landa=50;
E=T0=T1=.0833;
T2=0.75;
gam2=1; gam1=0;
a1=5; a2=4.22; a3=977.4; ap=977.4;
C1=949.2; c0=114.24;
#---------------------------------------------------------------------------
ALT=Model(solver=IpoptSolver());
# variables-----------------------------------------------------------------
f(x) = cdf(Normal(0, 1), x);
JuMP.register(ALT, :f, 1, f; autodiff = true);
@variable(ALT, h >= 0);
@variable(ALT, L >= 0);
@variable(ALT, n, Int);
#-----------------------------------------------------------------------------
k1(x)=h/(1-f(L-sig*sqrt(n))+f(-L - sig*sqrt(n)));

k2(x)=(1-(1+landa*h)*exp(-landa*h))/(landa*(1-exp(-landa*h)));

k3(x)=E*n+T1*gam1+T2*gam2;

k4(x)=1/landa+h/(1-f(L-sig*sqrt(n))+f(-L-sig*sqrt(n)));

k5(x)=-(1-(1+landa*h)*exp(-landa*h))/(landa*(1-exp(-landa*h)))+E*n+T1*gam1+T2*gam2;

k6(x)=(exp(-landa*h)/1-exp(-landa*h))*(a3/(2*f(-L)))+ap;

k7(x)=1-f(L-sig*sqrt(n))+f(-L-sig*sqrt(n));

F(x)=c0/landa+C1*(k1(x)-k2(x)+k3(x))+((a1+a2*n)/h)*(k4(x)+k5(x)+k3(x))+k6(x);

FF(x)=k4(x)-k2(x)+E*n+T1+T2+(1-gam1)*((exp(-landa*h)/1-exp(-landa*h)*T0)/(2*f(-L)));

#objective function---------------------------------------------------------

f1(x)=F(x)/FF(x);

f2(x)=1/k7(x);

#-------------------------------------------------------------------------------------------------------

@NLconstraint(ALT,rf1,f1(x)<=1000000000000);

@NLconstraint(ALT,lf1,f1(x)>=-1000000000000);

#------------------------------------------------------------------------------------------------------

@NLobjective(ALT, Min, f1(x));

status=solve(ALT);
#-------------------------------------------------------------------------------------------------------

but this error is happened

ERROR: Unrecognized function "f1" used in nonlinear expression.

how can I remove this error? would you please help me? thanks a lot.

Upvotes: 1

Views: 64

Answers (1)

Oscar Dowson
Oscar Dowson

Reputation: 2574

You need to register all the functions used in @NLconstraint and @NLobjective.

Upvotes: 1

Related Questions