How can I use gamma function in optimization problem
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Daud
am 25 Sep. 2018
Kommentiert: Michele Carone
am 22 Nov. 2022
epsilon_c = 10e-9; % unitless
lambda = 1e-3; % seconds
P_t = -30; % dB
d = 10; % m
L_H = 40; % bits
L_U = 16; %bits
M_1 = 10; %dB
N_o = -204; %dB
A_o = 30; %dB
m = 1;
alpha = 3;
%%%Variables for Solution
K = optimvar('K', 1, 1, 'Type', 'integer', 'LowerBound', 0, 'UpperBound', 10);
z = optimvar('z', 1, 1, 'Type', 'integer', 'LowerBound', 0, 'UpperBound',10);
%%%Linear Constraints
L = L_H+(K*L_U); % Packet length
R_b = L/lambda; % minimum bit rate
decisioncons = (K/2) - z <= 0;
beta = ((epsilon_c*gamma(m*z+1))^(1/(m*z))*P_t)\(m*N_o*M_1*A_o*d^alpha);
bandwidthcons = B(2^(R_b/B)-1) <= beta;
%%%Solve the Problem
commm = optimproblem('ObjectiveSense','minimize');
commm.Objective = B;
commm.Constraints.decisioncons = decisioncons;
commm.Constraints.bandwidthcons = bandwidthcons;
options = optimoptions('intlinprog','Display','final');
[commmsol,fval,exitflag,output] = solve(commm,'options',options);
sol = commmsol.B
Error:
Undefined function
'gamma' for input
arguments of type
'optim.problemdef.OptimizationExpression'.
3 Kommentare
Matt J
am 22 Nov. 2022
Bearbeitet: Matt J
am 22 Nov. 2022
@Michele Carone No, you can use the gamma function in the solver-based framework, e.g.,
xoptimal=fmincon(@(x) gamma(x).^2, 1,[],[],[],[],0,5)
Also, in reecent matlab, you can make it work with the problem-based framework using fcn2optimexpr,
x=optimvar('x','Lower',0,'Upper',5);
GamSquare=fcn2optimexpr(@(z) gamma(z).^2, x);
sol0.x=1;
xoptimal = solve(optimproblem('Objective',GamSquare),sol0).x
Michele Carone
am 22 Nov. 2022
Akzeptierte Antwort
Matt J
am 25 Sep. 2018
Bearbeitet: Matt J
am 27 Sep. 2018
Your bandwidthcons are not linear, so optimproblem is not applicable here. Since there are only 100 combinations of K and z that satisfy the bounds, you should probably just use exhaustive search.
3 Kommentare
Walter Roberson
am 26 Sep. 2018
gamma() is not defined for datatype optim.problemdef.OptimizationVariable
The defined arithmetic operations for the datatype are:
.\ (ldivide) -- only when the variable is on the right side, nonscalar constant left permitted
- (minus)
\ (mldivide) -- only when the variable is on the right side and left side is scalar
^ (mpower) -- only variable^2
/ (mrdivide) -- only when variable is on left side and right side is scalar
* (mtimes) -- nonscalar left and right permitted and variable^2 terms permitted as long as total degree of any term does not exceed 2
+ (plus)
.^ (power) -- only variable.^2
./ (rdivide) -- only when variable is on left side; right side can be non-scalar
.* (times) -- nonscalar left and right permitted and variable^2 terms permitted as long as total degree of any term does not exceed 2
- (uminus, unary minus)
+ (uplus, unary plus)
Matt J
am 27 Sep. 2018
Bearbeitet: Matt J
am 27 Sep. 2018
And the reason gamma() is not defined for datatype optim.problemdef.OptimizationVariable is because you are not supposed to be doing any nonlinear operations on it, since optimproblem is only intended for linear programming (prior to R2018b).
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Surrogate Optimization finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!