Hi everyone ,
I got an error message when I called “inv_pos” function in my code.
I just start learning how to use CVX , and I have no idea how to deal with the error.
I read the The DCP ruleset and other topics related to my problem in the forum , but I still can not get a answer.
Please give me a hand
Here is my CVX code :
% CVX Procedure
cvx_begin
variable TSPN_XY(length(Routing_Info)-2,2) % TSPN_XY is an array with (x,y) coordinate in each row
minimize(Total_Routing_Dist(TSPN_XY)) % Total_Routing_Dist is a function calculate the summary distance like norm([x2 y2]-[x1 y1])+norm([x3 y3]-[x2 y2]) ...
subject to
Total_Energy_Consumption = 0;
for i = 2:length(Routing_Info)-1 % TSPN_XY[1] is related to Routing_Info[2] , hence i start from 2 to (last_index_of_Routing_Info - 1) , we don't take first & last node (0,0) into consideration here
norm(Routing_Info(i,[1 2])-TSPN_XY(i-1,:)) <= TSPN_Radius; % constrain 1
if(i == 2)
UAV_Propulsion_Energy = Cal_UAV_propulsion_energy_consumption(norm(TSPN_XY(i-1,:)-[0,0])); % flying distance between (0,0) and first IoTD
else
UAV_Propulsion_Energy = Cal_UAV_propulsion_energy_consumption(norm(TSPN_XY(i-1,:)-TSPN_XY(i-2,:))); % flying distance current IoTD(i-1) and last IoTD(i-2)
end
D1 = (Routing_Info(i,1)-TSPN_XY(i-1,1))^2;
D2 = (Routing_Info(i,2)-TSPN_XY(i-1,2))^2;
D3 = 20^2;
Dist = D1+D2+D3;
IoTD_to_UAV_DataRate = Data_Rate(Dist);
UAV_Hovering_Energy = Cal_UAV_hovering_energy_consumption(Routing_Info(i,3)/IoTD_to_UAV_DataRate);
UAV_MEC_Energy = Cal_UAV_MEC_energy_consumption(Routing_Info(i,4));
Total_Energy_Consumption = Total_Energy_Consumption + UAV_Propulsion_Energy; %+ UAV_Hovering_Energy + UAV_MEC_Energy;
end
Total_Energy_Consumption = Total_Energy_Consumption + Cal_UAV_propulsion_energy_consumption(norm(TSPN_XY(length(Routing_Info)-1,:)-[0,0])); % add the flying energy consumption from last node back to (0,0)
Total_Energy_Consumption <= UAV_Energy_Budget; % constrain 2
cvx_end
Below is the error message , it occurred when CVX executed at line31 , which called a user-defined function I wrote .
In cvxprob (line 28)
In cvx_begin (line 41)
In TSPN (line 14)
Error using cvx/pow_cvx
Disciplined convex programming error:
Illegal operation: pow_p( {convex}, {-1} )
Error in cvx/inv_pos (line 5)
y = pow_cvx( x, -1, ‘pow_p’ );
Error in Data_Rate (line 15)
DataRate = BW*(log2(1+(IoTD_Power*IoT_Channel_Power_Gain)inv_pos(DistNoise_Variance)));
Error in TSPN (line 31)
IoTD_to_UAV_DataRate = Data_Rate(Dist);
I called inv_pos
at line 31 in my CVX code , I marked it with red lines in the screenshot.
(Sorry for squeezing the code in screenshot , because I am just new at the forum , and I can only update one media in a post.)
If you need more information or explanation of my problem , please feel free to let me know.
I will provide it as soon as possible.
I will be grateful if someone could help me