Hi, I have the following code
PVenergy = 1000;
WTenergy = 10000;
A = cell(27,3);
for ii = 1:27
PV = PV_output(:,:,ii);
for jj = 1:3
WT = WT_output(:,:,jj);
A{ii,jj}= horzcat(PV, WT);
f = [((CRF*CC_PV/PVenergy)+OM_PV); ((CRF*CC_WT/WTenergy)+OM_WT)]; % Objective function coefficients
b(:,:) = -Demand(:);
lb = zeros(2,1);
ub = [max_PV_area/PV_area; max_WT_area/WT_area]';
[x, fval, exitflag] = linprog(f,A,b(:,:),[],[],lb,ub)
end
end
Where PV_output is a 8760x1x27 and WT_output is a 8760x1x3. I am looking to use linprog to find the optimum x1 and x2 values of PV and WT by examining all the 81 possible combinations (from 27 and 3 )
I get the error " LINPROG only accepts inputs of data type double." and having checked the "class" of A is a cell and not double as linprog requires it. How do we convert the A to a double?
Also, if anyone has a better idea of how to code the optimisation for all the possible PV_output and WT_outputs please let me know!
Thank you
|
|
0
|
|
|
|
Reply
|
andrew.alkiviades (47)
|
6/21/2012 9:05:49 PM |
|
Andrew Alkiviades <andrew.alkiviades@gmail.com> wrote in message <ba952f9c-acbc-4b14-aeff-563c18b64a76@googlegroups.com>...
>
> I get the error " LINPROG only accepts inputs of data type double." and having checked the "class" of A is a cell and not double as linprog requires it. How do we convert the A to a double?
==============
Why have you created A as a cell in the first place? Why not just do
A = horzcat(PV, WT);
|
|
0
|
|
|
|
Reply
|
mattjacREMOVE (3177)
|
6/21/2012 9:52:07 PM
|
|
On Thursday, 21 June 2012 22:52:07 UTC+1, Matt J wrote:
> Andrew Alkiviades <andrew.alkiviades@gmail.com> wrote in message <ba952f9=
c-acbc-4b14-aeff-563c18b64a76@googlegroups.com>...
> >
> > I get the error " LINPROG only accepts inputs of data type double." and=
having checked the "class" of A is a cell and not double as linprog requir=
es it. How do we convert the A to a double?
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>=20
> Why have you created A as a cell in the first place? Why not just do
>=20
> A =3D horzcat(PV, WT);
Hi Matt thanks for your reply
since I have 27 "sets" of PV and 3 "sets" of WT, I want to find all the PV =
and WT combinations over the 8760 hour period examined (i.e 8760x1x27 and 8=
760x1x3). If I horzcat PV and WT how can I do so but simultaneously have, b=
e able to access and use any of the 87 possible PV WT combinations in linpr=
og and later on?=20
|
|
0
|
|
|
|
Reply
|
andrew.alkiviades (47)
|
6/21/2012 9:55:26 PM
|
|
Andrew Alkiviades <andrew.alkiviades@gmail.com> wrote in message <3a4c1a61-11a5-476f-8fb1-45f677315173@googlegroups.com>...
>
> Hi Matt thanks for your reply
>
> since I have 27 "sets" of PV and 3 "sets" of WT, I want to find all the PV and WT combinations over the 8760 hour period examined (i.e 8760x1x27 and 8760x1x3). If I horzcat PV and WT how can I do so but simultaneously have, be able to access and use any of the 87 possible PV WT combinations in linprog and later on?
================
But in the code you've shown, you're not calling linprog "later on". You are calling it in each pass through your 3x27 double loop. If you intend to call linprog 81 times, once on each combination, why is it necessary to save the data for later?
|
|
0
|
|
|
|
Reply
|
mattjacREMOVE (3177)
|
6/21/2012 10:14:07 PM
|
|
Matt Im not quite sure what you mean. I have called linprog within the for loop? What do you mean by saving the data for later?
Do I need the "Cell2mat function since the class of A is cell?
Also, do you think the for loop is the best way of constructing the 81 combinations of PV and WT?
Thanks
|
|
0
|
|
|
|
Reply
|
andrew.alkiviades (47)
|
6/21/2012 11:20:13 PM
|
|
On Thursday, 21 June 2012 23:14:07 UTC+1, Matt J wrote:
> Andrew Alkiviades <andrew.alkiviades@gmail.com> wrote in message <3a4c1a6=
1-11a5-476f-8fb1-45f677315173@googlegroups.com>...
> >
> > Hi Matt thanks for your reply
> >=20
> > since I have 27 "sets" of PV and 3 "sets" of WT, I want to find all the=
PV and WT combinations over the 8760 hour period examined (i.e 8760x1x27 a=
nd 8760x1x3). If I horzcat PV and WT how can I do so but simultaneously hav=
e, be able to access and use any of the 87 possible PV WT combinations in l=
inprog and later on?=20
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>=20
> But in the code you've shown, you're not calling linprog "later on". You =
are calling it in each pass through your 3x27 double loop. If you intend to=
call linprog 81 times, once on each combination, why is it necessary to sa=
ve the data for later?
Matt,
I need to save the data for later because I want to be able to code in such=
a way where I can access specific elements of the PV and WT combination
To be honest I don't know the format of how to progress from here except fo=
r trying the cell2mat function which I have below as :
=20
C =3D cell(27,3);=20
for ii =3D 1:27
PV =3D PV_output(:,:,ii);=20
=20
for jj =3D 1:3=20
WT =3D WT_output(:,:,jj);=20
=20
=20
C{ii,jj}=3D horzcat(PV, WT);
=20
=20
A(ii,jj) =3D cell2mat(C(ii,jj));
(Do you know what the A index format is on the last like (I believe that A(=
ii,jj) is incorrect)
Also, should I end the for loop after or before calling linprog?
Do you think there is a better way to code so as the have the PV and WT 81 =
combinations in matrix format ?
|
|
0
|
|
|
|
Reply
|
andrew.alkiviades (47)
|
6/21/2012 11:35:43 PM
|
|
It seems to me that you want to be saving the different 2x1 solutions returned by linprog in a 27x3 cell array x{i,j}, so that you can access the solutions later. There is no clear reason to be storing the PV,WT input data in a cell A{i,j} because you can already obtain any combination of this data through your existing matrices PV_output and WT_ouput.
Try running the code below and tell me in what way it is not what you want. I have changed only 3 lines of your original code and I have marked the changed lines with comments: %%%%CHANGED
PVenergy = 1000;
WTenergy = 10000;
x= cell(27,3); %%%%%CHANGED
for ii = 1:27
PV = PV_output(:,:,ii);
for jj = 1:3
WT = WT_output(:,:,jj);
A= horzcat(PV, WT); %%%%CHANGED
f = [((CRF*CC_PV/PVenergy)+OM_PV); ((CRF*CC_WT/WTenergy)+OM_WT)]; % Objective function coefficients
b(:,:) = -Demand(:);
lb = zeros(2,1);
ub = [max_PV_area/PV_area; max_WT_area/WT_area]';
[x{i,j}, fval, exitflag] = linprog(f,A,b(:,:),[],[],lb,ub); %%%%CHANGED
end
end
|
|
0
|
|
|
|
Reply
|
mattjacREMOVE (3177)
|
6/22/2012 7:57:07 AM
|
|
On Thursday, 21 June 2012 22:05:49 UTC+1, Andrew Alkiviades wrote:
> Hi, I have the following code
>
> PVenergy = 1000;
> WTenergy = 10000;
>
>
>
> A = cell(27,3);
> for ii = 1:27
>
> PV = PV_output(:,:,ii);
>
> for jj = 1:3
>
> WT = WT_output(:,:,jj);
>
>
> A{ii,jj}= horzcat(PV, WT);
>
> f = [((CRF*CC_PV/PVenergy)+OM_PV); ((CRF*CC_WT/WTenergy)+OM_WT)]; % Objective function coefficients
>
>
>
>
> b(:,:) = -Demand(:);
>
> lb = zeros(2,1);
>
> ub = [max_PV_area/PV_area; max_WT_area/WT_area]';
>
>
> [x, fval, exitflag] = linprog(f,A,b(:,:),[],[],lb,ub)
>
>
>
> end
> end
>
>
> Where PV_output is a 8760x1x27 and WT_output is a 8760x1x3. I am looking to use linprog to find the optimum x1 and x2 values of PV and WT by examining all the 81 possible combinations (from 27 and 3 )
> I get the error " LINPROG only accepts inputs of data type double." and having checked the "class" of A is a cell and not double as linprog requires it. How do we convert the A to a double?
>
> Also, if anyone has a better idea of how to code the optimisation for all the possible PV_output and WT_outputs please let me know!
>
> Thank you
thanks matt but I get an error "Subscript indices must either be real positive integers or logicals." on the line where linprog is called. any ideas why?
|
|
0
|
|
|
|
Reply
|
andrew.alkiviades (47)
|
6/22/2012 11:27:11 AM
|
|
Sure.
[x{ii,jj}, fval, exitflag] = linprog(f,A,b(:,:),[],[],lb,ub); %%%
%CHANGED
Best wishes
Torsten.
|
|
0
|
|
|
|
Reply
|
Torsten.Hennig1 (1087)
|
6/22/2012 11:52:08 AM
|
|
Thanks but now I get the following error
"The number of columns in A must be the same as the number of elements of f.
"
|
|
0
|
|
|
|
Reply
|
andrew.alkiviades (47)
|
6/22/2012 12:07:15 PM
|
|
Andrew Alkiviades <andrew.alkiviades@gmail.com> wrote in message <5c38653b-9325-497e-ab81-71de398d2649@googlegroups.com>...
> Thanks but now I get the following error
>
> "The number of columns in A must be the same as the number of elements of f.
=================
Well, is it true? Did you check how many columns A has and how many elements f has?
|
|
0
|
|
|
|
Reply
|
mattjacREMOVE (3177)
|
6/22/2012 12:30:08 PM
|
|
On 22 Jun., 14:07, Andrew Alkiviades <andrew.alkivia...@gmail.com>
wrote:
> Thanks but now I get the following error
>
> "The number of columns in A must be the same as the number of elements of f.
> "
What about
[x{ii,jj}, fval, exitflag] = linprog(f,A,-Demand,[],[],lb,ub); %%%
Best wishes
Torsten.
|
|
0
|
|
|
|
Reply
|
Torsten.Hennig1 (1087)
|
6/22/2012 12:33:16 PM
|
|
On Friday, 22 June 2012 13:33:16 UTC+1, Torsten wrote:
> On 22 Jun., 14:07, Andrew Alkiviades <andrew.alkivia...@gmail.com>
> wrote:
> > Thanks but now I get the following error
> >
> > "The number of columns in A must be the same as the number of elements of f.
> > "
>
> What about
> [x{ii,jj}, fval, exitflag] = linprog(f,A,-Demand,[],[],lb,ub); %%%
>
> Best wishes
> Torsten.
Hi Torsten, thanks but I still bet the error - The number of columns in A must be the same as the number of elements of f. the following size checks may help
>> size(A)
ans =
8760 2
>> size(f)
ans =
30 1
>> size(x)
ans =
27 3
>> size(Demand)
ans =
365 24
|
|
0
|
|
|
|
Reply
|
andrew.alkiviades (47)
|
6/22/2012 3:07:25 PM
|
|
Andrew Alkiviades <andrew.alkiviades@gmail.com> wrote in message <b5e675b3-4183-4e9b-9d71-4c548afca056@googlegroups.com>...
> On Friday, 22 June 2012 13:33:16 UTC+1, Torsten wrote:
> > On 22 Jun., 14:07, Andrew Alkiviades <andrew.alkivia...@gmail.com>
> > wrote:
> > > Thanks but now I get the following error
> > >
> > > "The number of columns in A must be the same as the number of elements of f.
> > > "
> >
> > What about
> > [x{ii,jj}, fval, exitflag] = linprog(f,A,-Demand,[],[],lb,ub); %%%
> >
> > Best wishes
> > Torsten.
>
> Hi Torsten, thanks but I still bet the error - The number of columns in A must be the same as the number of elements of f. the following size checks may help
>
> >> size(A)
>
> ans =
>
> 8760 2
>
> >> size(f)
>
> ans =
>
> 30 1
==============
This answers your question doesn't it? Your A matrix has 2 columns, but your f matrix has length 30. Therefore LINPROG thinks you have 30 unknown variables when you should only have 2. Re-examine the way you compute f.
|
|
0
|
|
|
|
Reply
|
mattjacREMOVE (3177)
|
6/22/2012 3:13:07 PM
|
|
well, I have f as
f = [((CRF*CC_PV/PVenergy)+OM_PV); ((CRF*CC_WT/WTenergy)+OM_WT)]; % Objective function coefficients
Where CRF is a constant .
Ideally I am trying to have a CC_PVm PVenergy, OM_PV, CC_WT, WTenergy and OM_WT that represent each of the specific 27 PV and 3 WT examinedin the 81 combination but have no way of starting something like this.
What I currently have is
discount_f = 0.05;
lifetime = 20;
CRF = ((discount_f*(1+discount_f)^lifetime)/(((1+discount_f)^lifetime)-1));
OM_PV = 50; % temporary but should be OM_PV for each specific PV panel
OM_WT = 1000;% temporary but should be OM_WT for each specific WT
PV_area = 3; % temporary but should be OM_PV for each specific PV panel
WT_area = 1000;% temporary but should be OM_WT for each specific WT
PVenergy = 1000; % temporary but should be OM_PV for each specific PV panel
WTenergy = 10000; % temporary but should be OM_WT for each specific WT
x= cell(27,3);
for ii = 1:27
PV = PV_output(:,:,ii);
for jj = 1:3
WT = WT_output(:,:,jj);
A= horzcat(PV, WT);
f{ii,jj} = [((CRF*CC_PV/PVenergy)+OM_PV); ((CRF*CC_WT/WTenergy)+OM_WT)]; % Objective function coefficients
b(:,:) = -Demand(:);
lb = zeros(2,1);
ub = [max_PV_area/PV_area; max_WT_area/WT_area]';
[x{ii,jj}, fval, exitflag] = linprog(f,A,-Demand,[],[],lb,ub);
end
end
but just can't see any way of coding this. The only thing I can do is an expression for each of the specifics OM_PV,OM_WT,CC_PV and CC_WT
|
|
0
|
|
|
|
Reply
|
andrew.alkiviades (47)
|
6/22/2012 3:24:04 PM
|
|
Hi, now I am really confused since I also need a PV_OM. WT_OM, CC_PV and CC=
_WT that is specific for each of the 27 and 3 PVs and WT respectively. I c=
urrently have them as constants temporarily but do you know how I could cod=
e for this (assuming the expression is PV_OM =3D PVenergy*constant
|
|
0
|
|
|
|
Reply
|
andrew.alkiviades (47)
|
6/22/2012 3:49:07 PM
|
|
Andrew Alkiviades <andrew.alkiviades@gmail.com> wrote in message <b7031972-34a0-4ad6-8a88-323296179588@googlegroups.com>...
> well, I have f as
>
> f = [((CRF*CC_PV/PVenergy)+OM_PV); ((CRF*CC_WT/WTenergy)+OM_WT)]; % Objective function coefficients
>
> Where CRF is a constant .
>
> Ideally I am trying to have a CC_PVm PVenergy, OM_PV, CC_WT, WTenergy and OM_WT that represent each of the specific 27 PV and 3 WT examinedin the 81 combination but have no way of starting something like this.
=============
One problem at a time. We first want to understand how your expression for f above gave you a 30x1 vector when you really want it to be a 2x1 vector.
Are all of the parameters CC_PVm PVenergy, OM_PV, CC_WT, WTenergy and OM_WT scalars? It doesn't look that way. If they were, then f should have the proper dimensions.
|
|
0
|
|
|
|
Reply
|
mattjacREMOVE (3177)
|
6/22/2012 5:35:07 PM
|
|
"Matt J" wrote in message <js2acb$lkv$1@newscl01ah.mathworks.com>...
>
> > Ideally I am trying to have a CC_PVm PVenergy, OM_PV, CC_WT, WTenergy and OM_WT that represent each of the specific 27 PV and 3 WT examinedin the 81 combination but have no way of starting something like this.
> =============
>
> One problem at a time. We first want to understand how your expression for f above gave you a 30x1 vector when you really want it to be a 2x1 vector.
>
> Are all of the parameters CC_PV, PVenergy, OM_PV, CC_WT, WTenergy and OM_WT scalars? It doesn't look that way. If they were, then f should have the proper dimensions.
==============
I'm going to take a wild guess here. I bet that you have CC_PV as a 27x1 vector and CC_WT as a 3x1 vector. That's why concatenating them gives you a 30x1 vector. I'm also willing to bet that you want to be computing each f using CC_PV(i) and CC_WT(j) inside your double for loop:
f = [((CRF*CC_PV(i)/PVenergy)+OM_PV); ((CRF*CC_WT(j)/WTenergy)+OM_WT)]; % Objective function coefficients
|
|
0
|
|
|
|
Reply
|
mattjacREMOVE (3177)
|
6/22/2012 6:15:07 PM
|
|
On Friday, 22 June 2012 19:15:07 UTC+1, Matt J wrote:
> "Matt J" wrote in message <js2acb$lkv$1@newscl01ah.mathworks.com>...
> >
> > > Ideally I am trying to have a CC_PVm PVenergy, OM_PV, CC_WT, WTenergy=
and OM_WT that represent each of the specific 27 PV and 3 WT examinedin th=
e 81 combination but have no way of starting something like this.
> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> >=20
> > One problem at a time. We first want to understand how your expression =
for f above gave you a 30x1 vector when you really want it to be a 2x1 vect=
or.
> >=20
> > Are all of the parameters CC_PV, PVenergy, OM_PV, CC_WT, WTenergy and O=
M_WT scalars? It doesn't look that way. If they were, then f should have th=
e proper dimensions.
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>=20
> I'm going to take a wild guess here. I bet that you have CC_PV as a 27x1 =
vector and CC_WT as a 3x1 vector. That's why concatenating them gives you a=
30x1 vector. I'm also willing to bet that you want to be computing each f =
using CC_PV(i) and CC_WT(j) inside your double for loop:
>=20
> f =3D [((CRF*CC_PV(i)/PVenergy)+OM_PV); ((CRF*CC_WT(j)/WTenergy)+OM_WT)]=
; % Objective function coefficients
Hi Matt, thanks for the reply
I shown the coding for "f" before and I haven't done it as you have guessed=
.. I want to have f as 2x1x81 where each of the CC_ and OM_ variables and PV=
energy and WTenergy represents the respective correct equivalent (if that m=
akes sense?!)
so currently f is as=20
f =3D [((CRF*CC_PV/PVenergy)+OM_PV); ((CRF*CC_WT/WTenergy)+OM_WT)];=20
but as you can see the first main problem is that, for example, CC_PV is a =
scalar that represents only one number, where in fact I want to examine 27 =
different PV panels with ofcource 27 different capital costs
|
|
0
|
|
|
|
Reply
|
andrew.alkiviades (47)
|
6/23/2012 6:21:02 PM
|
|
Andrew Alkiviades <andrew.alkiviades@gmail.com> wrote in message <81fd6c7b-f319-487a-b455-240c9b43546a@googlegroups.com>...
>
> I shown the coding for "f" before and I haven't done it as you have guessed. I want to have f as 2x1x81 where each of the CC_ and OM_ variables and PVenergy and WTenergy represents the respective correct equivalent (if that makes sense?!)
==============
I'm afraid it's very confusing, Andrew, mainly because you insist on not telling us what MATLAB variables you currently have and what their dimensions are. Please list all of your variables and their dimensions (e.g., using whos).
As far as I know, f still exists as a 30x1 vector as it did several posts ago. If it is not, you need to update us on what's changed. If it is 30x1 still, it should be clear to you that this is wrong. If each call to linprog is meant to solve a 2-variable problem, then f needs to be a length 2 vector, not a length 30 vector.
> so currently f is as
>
> f = [((CRF*CC_PV/PVenergy)+OM_PV); ((CRF*CC_WT/WTenergy)+OM_WT)];
>
> but as you can see the first main problem is that, for example, CC_PV is a scalar that represents only one number, where in fact I want to examine 27 different PV panels with ofcource 27 different capital costs
=============
That doesn't sound like a problem the Newsgroup can advise you on. If you only have 1 single scalar of data right now and you need 26 more, only you can know where to obtain the data from from. Again, though, you haven't explained clearly what data you currently have and in what form.
|
|
0
|
|
|
|
Reply
|
mattjacREMOVE (3177)
|
6/23/2012 7:47:06 PM
|
|
|
19 Replies
31 Views
(page loaded in 0.381 seconds)
|