Clear Filters
Clear Filters

Incorrect number or types of inputs or outputs for function vec.

117 views (last 30 days)
cvx_begin
variable beam(K + 1, K) complex;
variable r_c(1, K);
variable R_p(1, K);
common_rate = sum(Group .* r_c);
rate = 0;
for i = 1 : K
upper_limit = R_p(i) + Group(i) .* r_c(i) - D_min(i);
rate = rate + (((theta * (1 - exp(- upper_limit * theta))) .* (upper_limit >= 0)) + upper_limit .* (upper_limit <= 0)) + D_min(i);
end
maximize(rate)
subject to
for i = 1 : K
g_private_i = Update_g_private_k(channel, beam, private_beta, alpha_private, Group, i, delt);
R_p(i) <= g_private_i;
0 <= R_p(i);
[R_c, ~] = Update_g_common_k(channel, beam, alpha_common, common_beta, Group, i, delt);
end
for j = 1 : K
0 <= r_c(j);
end
common_rate <= R_c;
% 功率约束
square_pos(norm(beam, 'fro')) <= P_max;
cvx_end
报错原因:
Incorrect number or types of inputs or outputs for function vec.
出错 cvx/sparsify>replcols (第 142 行)
cvx___.readonly( ndxs ) = vec( cvx_readlevel( bN ) );
出错 cvx/sparsify (第 61 行)
[ x, forms, repls ] = replcols( x, tt, 'full', forms, repls, isobj );
出错 cvx/exp (第 68 行)
xt = sparsify( xt, 'exponential' );
出错 Cvx_solver (第 49 行)
rate = rate + (((theta * (1 - exp(- upper_limit * theta))) .* (upper_limit >= 0)) + upper_limit .* (upper_limit <= 0)) + D_min(i);

Answers (1)

Ruchika Parag
Ruchika Parag on 17 Jul 2024
Edited: Ruchika Parag on 17 Jul 2024
Hi, 麒麟,
我将用英语回答这个问题,因为我的母语不是中文.
The error you are encountering suggests that there is an issue with the 'exp' function in the CVX environment. This could be due to improper handling of the exponential function within the CVX optimization framework. Some steps and modifications you can try are as follows:
  1. Vectorization and Element-wise Operations: Ensure that all operations involving vectors and matrices are properly vectorized and use element-wise operations where necessary.
  2. CVX Compatibility: Ensure that the expressions inside the 'maximize' and 'subject to' blocks are compatible with CVX's constraints and objective function requirements.
  3. Simplify Expressions: Break down complex expressions into simpler parts to make it easier to identify where the issue might be.
Here is a modified version of your code with these considerations:
cvx_begin
variable beam(K + 1, K) complex;
variable r_c(1, K);
variable R_p(1, K);
common_rate = sum(Group .* r_c);
rate = 0;
for i = 1 : K
upper_limit = R_p(i) + Group(i) * r_c(i) - D_min(i);
% Define a temporary variable for the exponential term
exp_term = exp(-upper_limit * theta);
% Ensure element-wise operations
rate = rate + ((theta * (1 - exp_term)) * (upper_limit >= 0)) + upper_limit * (upper_limit <= 0) + D_min(i);
end
maximize(rate)
subject to
for i = 1 : K
g_private_i = Update_g_private_k(channel, beam, private_beta, alpha_private, Group, i, delt);
R_p(i) <= g_private_i;
0 <= R_p(i);
[R_c, ~] = Update_g_common_k(channel, beam, alpha_common, common_beta, Group, i, delt);
end
% Ensure non-negativity of r_c
r_c >= 0;
% Ensure common rate constraint
common_rate <= R_c;
% Power constraint
square_pos(norm(beam, 'fro')) <= P_max;
cvx_end
By making these changes, you should be able to address the error and ensure that your optimization problem is correctly formulated for CVX. Hope this helps!
  1 Comment
Kyrin
Kyrin on 18 Jul 2024
Thanks for the advice, I'm still having problems after modifying it this way.
Incorrect number or types of inputs or outputs for function vec.
出错 cvx/sparsify>replcols (142 )
cvx___.readonly( ndxs ) = vec( cvx_readlevel( bN ) );
出错 cvx/sparsify (61 )
[ x, forms, repls ] = replcols( x, tt, 'full', forms, repls, isobj );
出错 cvx/exp (68 )
xt = sparsify( xt, 'exponential' );
出错 Cvx_solver (51 )
exp_term = exp(-upper_limit * theta);

Sign in to comment.

Categories

Find more on Wavelet Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!