Cannot perform the operation: {positive constant} .* {real affine}. How to solve the multiplication of the matrix containing the value of `Inf`?

When I run my code, the following error appears. Hope to get your help.

错误使用 .* (line 173)
Disciplined convex programming error:
Cannot perform the operation: {positive constant} .* {real affine}

出错 CVXSolver (line 18)
sum(sum(sum(cost.*adjacency))) <= u_cost;

My main relevant code is as follows:

%------CVX optimization------:
cvx_begin
    variable adjacency(node_number, node_number, time_number) binary;
    maximize(sum(sum(sum(adjacency.*gain))));
    subject to
        sum(sum(sum(cost.*adjacency))) <= u_cost;               
cvx_end

Where cost is a matrix with the same dimensions as adjacency. The elements in the matrix are non-negative float numbers except for some elements whose values are Inf.

I have read two related posts. Someone pointed out that the element values of the constant matrix cannot be Inf and NaN, and avoid dividing by the integer 0 during calculation. But in Matlab, matrix multiplication with Inf elements is supported. How should I modify it to make it run normally, I am eager to get your suggestions.

What does 0 times Inf equal? MATLAB doesn’t know, so it produces the result, NaN. CVX does not allow NaN in CVX expressions.

You have to decide what you actually want the constraint to be. Them and only then, figure out how to achieve that in CVX, which among other things, will have to be done without having NaN enter into a CVX expression.

Thank you very much for your answers, I think I understand what the problem is. My problem has been effectively solved.

Hello, I’m sorry to bother you, I’d like to ask this ask how you solved it?

@zjl zjl] If you want help, you’ll need to post your program, preferably complete with all input data, and post all CVX and solver output. Copy and paste any code using the Prefromatted text icon in the post entry box. Do not show images of the code.