# Can someone suggest the error which comes as The following error occurred converting from cvx to double: Conversion to double from cvx is not possible.The details is given as below

`````` clc;clear all; close all;

Ai=0.04; R= 2.65e-8; Ci= 100; Ce= 6.5;x=4; dst=2710; w=311.15; pf=0.85;
V=11; x=4;
n=4;
L=data(5:8);
I=data(1:4);
cost=0;
loss=0;

cvx_begin
variable X(n);
%expression cost(5);
%expression loss(5);

for i=1:n
cost(i)= pi *X(i)^2*L(i)*R*dst*Ci*Ai/4;
loss(i)=3*I(i)^2*R*L(i)*Ce*8760/(( pi*X(i)*X(i)));
cost=cost+cost(i);
loss=loss+loss(i);
Z(i)= (R*L(i)*pf/(pi*x(i)*x(i)) + w*2e-7*log(0.558*0.526/x(i)));
VD(i)= I(i)*Z(i);
V(i)=(V-VD(i))/V;
end

T_cost=sum(cost)+sum(loss);

minimize((T_cost))

subject to
V(i)<=0.1;
d(i)>=0
cvx_end
``````

You need to use expression holders (declaration) for all of `cost, loss, Z, VD, V`. http://cvxr.com/cvx/doc/basics.html#assignment-and-expression-holders

I don’t know what you are trying to do with

``````cost=cost+cost(i);
loss=loss+loss(i);
``````

but I am not confident it is doing what you want, even though I don’t know what that is. You are summing over `cost` and `loss` later in the code after you assigned all their elements in the for loop. So I doubt you want any other summing.