How can I use gamma function in optimization problem

3 次查看(过去 30 天)
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 个评论
Matt J
Matt J 2022-11-22
编辑:Matt J 2022-11-22
@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 2022-11-22
thank you @Matt J, I didn't know this new possibility of recent matlab.

请先登录,再进行评论。

采纳的回答

Matt J
Matt J 2018-9-25
编辑:Matt J 2018-9-27
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 个评论
Walter Roberson
Walter Roberson 2018-9-26
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 2018-9-27
编辑:Matt J 2018-9-27
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).

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Gamma Functions 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by