CVX error when trying to minus two scalar variables

Hi all,

I am trying to minimize the following objective:

obj = sum(sum_square(p1(:,2:30)-p1(:,1:29)));

subject to:

CD = randn(29,1);
CL = randn(29,1);
Wf = [];
for i = 1:29
disp(i) = norm([p1(1,i+1),p1(2,i+1)]-[p1(1,i),p1(2,i)])*1000
V1 = (700/3.6) + ((920/3.6)-(700/3.6))*rand(1)
CL(i) = (W1(i).*g)/(0.5*density*(V1^2)*S)
CD(i) = CDo + ((CL(i).^2)/(3.14*AR*e))
T = ((CD(i)/inv_pos(CL(i)))*(W1(i)*g))/1000                   
Wf = [Wf,SFC*T*(disp(i)/V1)]
W1(i+1) = W1(i)-Wf
W1 >= 0;
Wf >= 0;
Wf <= W1;
end

Predefined values: W1, density, g, p1, SFC

I get the following error:

The following error occurred converting from cvx to double:
Error using double
Conversion to double from cvx is not possible.
Error in fueloptimal (line 156)
W1(i+1) = W1(i)-Wf

W1 and Wf are scalar variables so I don’t understand why CVX will not accept that equation.

Can someone please help?!

The problem is not the difference, it’s assigning it to the vector W1. You can’t assign a CVX expression to a standard MATLAB vector. Have you declared that using an expression statement? i.e., expression W1(30)? Try that.

Also, because those last inequalities are inside the loop, they’re going to be repeated 29 times. I don’t think that’s what you want.

I have tried declaring it as an expression but when I do I get the following error:

The following error occurred converting from cvx
to double:
Error using double
Conversion to double from cvx is not possible.

Error in fueloptimal (line 152)
CL(i) = (W1(i).g)/(0.5density*(V1^2)*S)

When I declare CD, CL, Wf, W1 all as expressions the model runs smoothly without any troubles but it won’t give me an output matrix for W1 it just spits out CVX expression. Is there a way around this to get W1 and V1 as matrices?

Actually, they should be output as matrices. I’m not sure why they are not. I don’t have a fix for you, unfortunately. You can submit a bug report to http://support.cvxr.com but I don’t know if I can fix it… you may have to recalculate these values.

I remove the semicolon and all I get is ‘CVX expression’. Is there a command I can use to get an output?