Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
long summation function for fmincon

Subject: long summation function for fmincon

From: stephen

Date: 8 Dec, 2010 00:40:20

Message: 1 of 5

I have a very long function I want to use in fmincon. This is my first post so I don't know the best way to state the function but I will attempt it like this:

f = sum (from 1 to n) sum (1 to n) x(i)*x(j) + sum (1 to n) x(i)
n = 120

so there are 14400 terms

Is there an easier way than hard coding all the terms so it will go into fmincon?

Also, at some point I will want to add coefficients to these terms from a 120x120 matrix. How can I add that to the program?

Subject: long summation function for fmincon

From: Roger Stafford

Date: 8 Dec, 2010 00:59:06

Message: 2 of 5

"stephen " <sca2c@virginia.edu> wrote in message <idmk5k$5vv$1@fred.mathworks.com>...
> I have a very long function I want to use in fmincon. This is my first post so I don't know the best way to state the function but I will attempt it like this:
>
> f = sum (from 1 to n) sum (1 to n) x(i)*x(j) + sum (1 to n) x(i)
> n = 120
>
> so there are 14400 terms
>
> Is there an easier way than hard coding all the terms so it will go into fmincon?
>
> Also, at some point I will want to add coefficients to these terms from a 120x120 matrix. How can I add that to the program?
- - - - - - -
 f = sum(x);
 f = f*(f+1);

Roger Stafford

Subject: long summation function for fmincon

From: Roger Stafford

Date: 8 Dec, 2010 01:06:05

Message: 3 of 5

> "stephen " <sca2c@virginia.edu> wrote in message <idmk5k$5vv$1@fred.mathworks.com>...
> > Also, at some point I will want to add coefficients to these terms from a 120x120 matrix. How can I add that to the program?
> - - - - - - -
  In answer to your second question, if c is the coefficient matrix and x is a column vector, then

 f = x.'*c*x

will compute the first term using coefficients but I don't know what you want to do with the second term.

Roger Stafford

Subject: long summation function for fmincon

From: Matt J

Date: 8 Dec, 2010 14:44:05

Message: 4 of 5

"stephen " <sca2c@virginia.edu> wrote in message <idmk5k$5vv$1@fred.mathworks.com>...
> I have a very long function I want to use in fmincon. This is my first post so I don't know the best way to state the function but I will attempt it like this:
=======

This is a quadratic function, so you should probably consider using QUADPROG, as opposed to FMINCON. Depends on your constraints, I guess.

Subject: long summation function for fmincon

From: Matt J

Date: 8 Dec, 2010 15:02:15

Message: 5 of 5

"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <ido5jk$8bm$1@fred.mathworks.com>...
> "stephen " <sca2c@virginia.edu> wrote in message <idmk5k$5vv$1@fred.mathworks.com>...
> > I have a very long function I want to use in fmincon. This is my first post so I don't know the best way to state the function but I will attempt it like this:
> =======
>
> This is a quadratic function, so you should probably consider using QUADPROG, as opposed to FMINCON. Depends on your constraints, I guess.

And, if QUADPROG turns out to be applicable, you may also want to look at the HessMult option for large scale algorithms. The case you initially described (without "coefficients") has a Hessian of H=ones(120). The product H*Y (cf. also Roger's post) can be more efficiently implemented as

e=ones(120,1);
hmfun=@(Hinfo,Y) e*sum(Y,1);

Tags for this Thread

No tags are associated with this thread.

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.

Contact us