Clear Filters
Clear Filters

How can I use gamma function in optimization problem

3 views (last 30 days)
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 Comments
Matt J
Matt J on 22 Nov 2022
Edited: Matt J on 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)
Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
xoptimal = 1.4616
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
Solving problem using fmincon. Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
xoptimal = 1.4616
Michele Carone
Michele Carone on 22 Nov 2022
thank you @Matt J, I didn't know this new possibility of recent matlab.

Sign in to comment.

Accepted Answer

Matt J
Matt J on 25 Sep 2018
Edited: Matt J on 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 Comments
Walter Roberson
Walter Roberson on 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
Matt J on 27 Sep 2018
Edited: Matt J on 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).

Sign in to comment.

More Answers (0)

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!