# Optimal value (cvx_optval): +Inf?

Hello everyone, I was working on minimum cost flow by using cvx optimization hw my code is giving NaN as an result and I could not find the problem.

My code is :

% Define the problem data
start_nodes = [0, 0, 1, 1, 1, 2, 2, 3, 4];
end_nodes = [1, 2, 2, 3, 4, 3, 4, 4, 2];
capacities = [15, 8, 20, 4, 10, 15, 4, 20, 5];
unit_costs = [4, 4, 2, 2, 6, 1, 3, 2, 3];
supplies = [20, 0, 0, -5, -15];

% Number of nodes and arcs
num_nodes = max([start_nodes, end_nodes]) + 1;
num_arcs = length(start_nodes);

% Define CVX variables
cvx_begin
variables flows(num_arcs)

``````% Objective: minimize the total cost
minimize(sum(unit_costs * flows))

% Constraints: flow conservation and capacity constraints
subject to
for i = 1:num_nodes
% Flow conservation for each node
sum(flows(start_nodes == i)) - sum(flows(end_nodes == i)) == supplies(i);
end

% Capacity constraints for each arc
flows >= 0;
flows <= capacities';
``````

cvx_end

% Display results
fprintf(‘Minimum Maliyet: %.2f\n’, cvx_optval);
fprintf(‘Düğüm Akışları:\n’);
for i = 1:num_arcs
fprintf(‘Düğüm %d → Düğüm %d: Akış %.2f\n’, start_nodes(i), end_nodes(i), flows(i));
end

============================================================

Calling SDPT3 4.0: 21 variables, 7 equality constraints
** For improved efficiency, SDPT3 is solving the dual problem.**
------------------------------------------------------------

** num. of constraints = 7**
** dim. of linear var = 18**
** dim. of free var = 3 *** convert ublk to lblk**

** SDPT3: Infeasible path-following algorithms**

** version predcorr gam expon scale_data**
** NT 1 0.000 1 0 **
it pstep dstep pinfeas dinfeas gap prim-obj dual-obj cputime
-------------------------------------------------------------------
** 0|0.000|0.000|9.3e-01|4.8e+00|2.5e+04| 1.571191e+03 0.000000e+00| 0:0:00| chol 1 1 **
** 1|1.000|0.822|1.1e-06|8.6e-01|3.1e+03| 7.014267e+02 7.423164e+01| 0:0:00| chol 1 1 **
** 2|1.000|0.107|1.5e-07|7.8e-01|3.7e+03|-2.642837e+04 7.487358e+01| 0:0:00| chol 1 1 **
** 3|1.000|0.028|9.9e-08|7.7e-01|6.5e+05|-2.806723e+07 7.516860e+01| 0:0:00| chol 1 1 **
** 4|1.000|0.020|3.8e-06|7.7e-01|1.2e+09|-5.499777e+10 4.721509e+01| 0:0:00| chol 1 1 **
** 5|1.000|0.005|8.7e-05|7.7e-01|4.3e+12|-1.158920e+14 9.042147e+01| 0:0:00| chol 1 1 **
** 6|1.000|0.001|1.1e-04|7.8e-01|5.2e+15|-9.229664e+16 2.328617e+01| 0:0:00| chol 1 2 **
** 7|1.000|0.002|2.1e-03|7.9e-01|2.4e+18|-3.259927e+19 7.699859e+01| 0:0:01|**
** sqlp stop: dual problem is suspected of being infeasible**
-------------------------------------------------------------------
** number of iterations = 7**
** residual of dual infeasibility **
** certificate X = 4.39e-19**
** reldist to infeas. <= 9.92e-19**
** Total CPU time (secs) = 0.51 **
** CPU time per iteration = 0.07 **
** termination code = 2**
** DIMACS: 2.9e-03 0.0e+00 2.0e+00 0.0e+00 -1.0e+00 7.5e-02**
-------------------------------------------------------------------

------------------------------------------------------------
Status: Infeasible
Optimal value (cvx_optval): +Inf

Minimum Maliyet: Inf
Düğüm Akışları:
Düğüm 0 → Düğüm 1: Akış NaN
Düğüm 0 → Düğüm 2: Akış NaN
Düğüm 1 → Düğüm 2: Akış NaN
Düğüm 1 → Düğüm 3: Akış NaN
Düğüm 1 → Düğüm 4: Akış NaN
Düğüm 2 → Düğüm 3: Akış NaN
Düğüm 2 → Düğüm 4: Akış NaN
Düğüm 3 → Düğüm 4: Akış NaN
Düğüm 4 → Düğüm 2: Akış NaN

Do you have any idea?

Follow the advice in Debugging infeasible models - YALMIP, all of which also applies to CVX, except for section 1.