Thread Subject: How to write this matrix for linprog

Subject: How to write this matrix for linprog

From: Hailey Yang

Date: 23 Jul, 2008 14:34:03

Message: 1 of 8

I am trying to use linprog to do optimization, but I have
difficulty to write up the A matrixes for A*x<=b

My problem is written as:

sum_j (w_ijk + z_ijk)<=d_ik for all i=1:I and k=1:K

the decision variables are w and z, d is a parameter.

I wrote up something for this, but it is a really long
code. So I kind of feel there is a simple code to write
this up. Could anyone help me with this? Thank you very
much!

Subject: How to write this matrix for linprog

From: Bruno Luong

Date: 23 Jul, 2008 16:33:02

Message: 2 of 8

"Hailey Yang" <haileyyang@hotmail.com> wrote in message
<g67fgq$685$1@fred.mathworks.com>...

>
> My problem is written as:
>
> sum_j (w_ijk + z_ijk)<=d_ik for all i=1:I and k=1:K
>
> the decision variables are w and z, d is a parameter.
>

Sorry, but you are not written a problem.

What you wrote is an merely expression (formula). I can't
see what you want to solve.

Bruno

Subject: How to write this matrix for linprog

From: Hailey Yang

Date: 23 Jul, 2008 18:12:02

Message: 3 of 8

Thank you for your reply.

Yeah, I know. I didn't list the complete problem, but just
some constraints that the problem is subject to. I think I
can write the rest of the problem up in MATLAB code. But
for this constraint, I don't know how to write it.

In addition, my understanding is that to use linprog, w and
z will have to be stored in one vector X.

Hailey

"Bruno Luong" <b.luong@fogale.fr> wrote in message
<g67mfu$brj$1@fred.mathworks.com>...
> "Hailey Yang" <haileyyang@hotmail.com> wrote in message
> <g67fgq$685$1@fred.mathworks.com>...
>
> >
> > My problem is written as:
> >
> > sum_j (w_ijk + z_ijk)<=d_ik for all i=1:I and k=1:K
> >
> > the decision variables are w and z, d is a parameter.
> >
>
> Sorry, but you are not written a problem.
>
> What you wrote is an merely expression (formula). I can't
> see what you want to solve.
>
> Bruno

Subject: How to write this matrix for linprog

From: Bruno Luong

Date: 23 Jul, 2008 18:35:04

Message: 4 of 8

"Hailey Yang" <haileyyang@hotmail.com> wrote in message
<g67s9i$5ao$1@fred.mathworks.com>...

>
> In addition, my understanding is that to use linprog, w and
> z will have to be stored in one vector X.
>

Exactly. A lot of problem in numerical simulation data needs
to be reshaped in a long vector before feeding into an
algorithm.

I your case, if your unknown variables are two
three-dimensional variables w, and z

w: size [ni,nj,nk]
z: size [ni,nj,nk]

You need to consider a long and thin vector x composed as

x = cat(1,reshape(w,ni*nj*nk),reshape(w,ni*nj*nk));

Or using MATLAB short syntax

x = [w(:); z(:)];

From this reshaping, you will be able to structure and build
the matrix A and b accordingly.

Bruno

Subject: How to write this matrix for linprog

From: Bruno Luong

Date: 23 Jul, 2008 18:37:02

Message: 5 of 8

Sorry should read:
>
> x = cat(1,reshape(w,ni*nj*nk,1),reshape(w,ni*nj*nk,1));
>

Bruno

Subject: How to write this matrix for linprog

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 23 Jul, 2008 18:47:42

Message: 6 of 8

In article <g67toe$qa1$1@fred.mathworks.com>,
Bruno Luong <b.luong@fogale.fr> wrote:
>Sorry should read:

>> x = cat(1,reshape(w,ni*nj*nk,1),reshape(w,ni*nj*nk,1));

The second w should be z.

You could also use

x = cat(1,reshape(w,[],1),reshape(z,[],1));

but Bruno's other suggestion

x = [w(:);z(:)];

is more compact (and probably more efficient.)
--
This is a Usenet signature block. Please do not quote it when replying
to one of my postings.
http://en.wikipedia.org/wiki/Signature_block

Subject: How to write this matrix for linprog

From: Bruno Luong

Date: 23 Jul, 2008 18:58:03

Message: 7 of 8

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <g67uce$pdp$1@canopus.cc.umanitoba.ca>...
>
> The second w should be z.
>

Of course, thank you for the correction Walter.

Bruno

Subject: How to write this matrix for linprog

From: Hailey Yang

Date: 23 Jul, 2008 19:29:03

Message: 8 of 8

Thank both of you so much!

Hailey

"Bruno Luong" <b.luong@fogale.fr> wrote in message
<g67uvr$c21$1@fred.mathworks.com>...
> roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
> message <g67uce$pdp$1@canopus.cc.umanitoba.ca>...
> >
> > The second w should be z.
> >
>
> Of course, thank you for the correction Walter.
>
> Bruno

Tags for this Thread

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
optimization Hailey Yang 23 Jul, 2008 10:35:06
linprog Hailey Yang 23 Jul, 2008 10:35:06
rssFeed for this Thread

Contact us at files@mathworks.com