CVX: In an assignment A(:) = B, the number of elements in A and B must be the same.

2 visualizaciones (últimos 30 días)
Hi all,
I am very new to Matlab and CVX. I have only been using them for the last few months and my background is in engineering not mathematics. I am having the following problem. I am trying to minimise the following objective function:
sum(sum_square(p1(:,2:30)-p1(:,1:29)))
Based on the requirements of the following equations:
for i = 1:29
V = 900;
CL(i) = (W(i).*g)/(0.5*density*(V^2)*S);
CD(i) = CDo + ((CL(i).^2)/(3.14*AR*e));
T = ((CD(i)/CL(i))*(W(i)*g))/1000; %convert to KN
cp(i) = {p1(1,i), p1(2,i); p1(1,i+1), p1(2,i+1)};
disp(i) = pdist(cp(i),'euclidean')*1000; %convert to m
Wf(i) = SFC*T*(disp(i)/V);
W(i+1) = W(i)-Wf(i);
end
Given variables: W, g, V, S, CDo, SFC, density
When I run this I get the following error:
Error using cvx/subsasgn (line 39)
In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in fueloptimal (line 79) cp(i) = {p1(1,i), p1(2,i); p1(1,i+1), p1(2,i+1)};
Can anybody help me with this problem?
Thank you in advance.

Respuesta aceptada

Image Analyst
Image Analyst el 25 de Sept. de 2014
In this line
cp(i) = {p1(1,i), p1(2,i); p1(1,i+1), p1(2,i+1)};
you're setting cp(i) to a cell. That's what the braces mean - it's a cell. Inside the cell you can have an array, a string, a structure, another cell, just about anything. See the FAQ for a good intuitive explanation: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F
But you can't have p1(1,i), p1(2,i); p1(1,i+1), p1(2,i+1) inside a cell because that's not an array. Those values need to be enclosed by brackets to turn them into an array. And once they're an array, THEN you can stick them into a cell and make that the i'th cell of the cell array called "cp". Understand? You will if you read the FAQ.
I'll do it in two steps just to be explicit:
thisArray = [p1(1,i), p1(2,i); p1(1,i+1), p1(2,i+1)];
cp(i) = {thisArray}; % Equivalent to cp{i} = thisArray;
  7 comentarios
Image Analyst
Image Analyst el 29 de Sept. de 2014
Editada: Image Analyst el 29 de Sept. de 2014
What is CVX? I don't have enough information or code to run this, so until we have that we can't help.
Nevermind - found it: http://cvxr.com/cvx/
I'm not going to download that and install it, so just give nominal values for all those variables you have so we have something that will at least run without saying "W undefined", etc.
Zena Assaad
Zena Assaad el 30 de Sept. de 2014
W(1) = 77000;
g = 9.81;
SFC = 0.94;
g = 9.81;
m = 77000;
S = 122.60;
CDo = 0.024;
Cd2 = 0.0375;
b = 34.10;
e = 0.8;
AR = (b^2)/S;
density = 0.3494;
These are all the known values defined before I run the above for loop. I do intend to make velocity a variable at a later stage with the equation being: V = sqrt(2*g*displacement). I have a 3x30 matrix (p1) that defines the three dimensional position at different intervals (row 1 = x, row 2 = y, row 3 = z). The displacement will be taken from that matrix by finding the Euclidean distance between consecutive x and y points (row 1 and row 2).

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by