Thread Subject:
Matlab linprog -" LINPROG only accepts inputs of data type double." error

Subject: Matlab linprog -" LINPROG only accepts inputs of data type double." error

From: Andrew Alkiviades

Date: 21 Jun, 2012 21:05:49

Message: 1 of 20

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

Subject: Matlab linprog -" LINPROG only accepts inputs of data type double." error

From: Matt J

Date: 21 Jun, 2012 21:52:07

Message: 2 of 20

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);

Subject: Matlab linprog -" LINPROG only accepts inputs of data type

From: Andrew Alkiviades

Date: 21 Jun, 2012 21:55:26

Message: 3 of 20

On Thursday, 21 June 2012 22:52:07 UTC+1, Matt J wrote:
> 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);

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?

Subject: Matlab linprog -" LINPROG only accepts inputs of data type

From: Matt J

Date: 21 Jun, 2012 22:14:07

Message: 4 of 20

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?

Subject: Matlab linprog -" LINPROG only accepts inputs of data type

From: Andrew Alkiviades

Date: 21 Jun, 2012 23:35:43

Message: 5 of 20

On Thursday, 21 June 2012 23:14:07 UTC+1, Matt J wrote:
> 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?


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 for trying the cell2mat function which I have below as :

     
        C = cell(27,3);
for ii = 1:27

    PV = PV_output(:,:,ii);
 
    for jj = 1:3

        WT = WT_output(:,:,jj);
        
        
C{ii,jj}= horzcat(PV, WT);
    
  
A(ii,jj) = 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 ?

Subject: Matlab linprog -" LINPROG only accepts inputs of data type

From: Andrew Alkiviades

Date: 21 Jun, 2012 23:20:13

Message: 6 of 20

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

Subject: Matlab linprog -" LINPROG only accepts inputs of data type

From: Matt J

Date: 22 Jun, 2012 07:57:07

Message: 7 of 20

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

Subject: Matlab linprog -" LINPROG only accepts inputs of data type

From: Andrew Alkiviades

Date: 22 Jun, 2012 11:27:11

Message: 8 of 20

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?

Subject: Matlab linprog -" LINPROG only accepts inputs of data type

From: Torsten

Date: 22 Jun, 2012 11:52:08

Message: 9 of 20


Sure.
   [x{ii,jj}, fval, exitflag] = linprog(f,A,b(:,:),[],[],lb,ub); %%%
%CHANGED

Best wishes
Torsten.

Subject: Matlab linprog -" LINPROG only accepts inputs of data type

From: Andrew Alkiviades

Date: 22 Jun, 2012 12:07:15

Message: 10 of 20

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.
"

Subject: Matlab linprog -" LINPROG only accepts inputs of data type

From: Matt J

Date: 22 Jun, 2012 12:30:08

Message: 11 of 20

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?

Subject: Matlab linprog -" LINPROG only accepts inputs of data type

From: Torsten

Date: 22 Jun, 2012 12:33:16

Message: 12 of 20

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.

Subject: Matlab linprog -" LINPROG only accepts inputs of data type

From: Andrew Alkiviades

Date: 22 Jun, 2012 15:07:25

Message: 13 of 20

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

Subject: Matlab linprog -" LINPROG only accepts inputs of data type

From: Matt J

Date: 22 Jun, 2012 15:13:07

Message: 14 of 20

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.

Subject: Matlab linprog -" LINPROG only accepts inputs of data type

From: Andrew Alkiviades

Date: 22 Jun, 2012 15:49:07

Message: 15 of 20

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 currently have them as constants temporarily but do you know how I could code for this (assuming the expression is PV_OM = PVenergy*constant

Subject: Matlab linprog -" LINPROG only accepts inputs of data type

From: Andrew Alkiviades

Date: 22 Jun, 2012 15:24:04

Message: 16 of 20

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

Subject: Matlab linprog -" LINPROG only accepts inputs of data type

From: Matt J

Date: 22 Jun, 2012 17:35:07

Message: 17 of 20

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.

Subject: Matlab linprog -" LINPROG only accepts inputs of data type

From: Matt J

Date: 22 Jun, 2012 18:15:07

Message: 18 of 20

"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

Subject: Matlab linprog -" LINPROG only accepts inputs of data type

From: Andrew Alkiviades

Date: 23 Jun, 2012 18:21:02

Message: 19 of 20

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 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

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 PVenergy and WTenergy represents the respective correct equivalent (if that makes sense?!)

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

Subject: Matlab linprog -" LINPROG only accepts inputs of data type

From: Matt J

Date: 23 Jun, 2012 19:47:06

Message: 20 of 20

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.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us