http://www.mathworks.com/matlabcentral/newsreader/view_thread/298355
MATLAB Central Newsreader  long summation function for fmincon
Feed for thread: long summation function for fmincon
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Wed, 08 Dec 2010 00:40:20 +0000
long summation function for fmincon
http://www.mathworks.com/matlabcentral/newsreader/view_thread/298355#802766
stephen
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:<br>
<br>
f = sum (from 1 to n) sum (1 to n) x(i)*x(j) + sum (1 to n) x(i)<br>
n = 120<br>
<br>
so there are 14400 terms<br>
<br>
Is there an easier way than hard coding all the terms so it will go into fmincon?<br>
<br>
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?

Wed, 08 Dec 2010 00:59:06 +0000
Re: long summation function for fmincon
http://www.mathworks.com/matlabcentral/newsreader/view_thread/298355#802767
Roger Stafford
"stephen " <sca2c@virginia.edu> wrote in message <idmk5k$5vv$1@fred.mathworks.com>...<br>
> 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:<br>
> <br>
> f = sum (from 1 to n) sum (1 to n) x(i)*x(j) + sum (1 to n) x(i)<br>
> n = 120<br>
> <br>
> so there are 14400 terms<br>
> <br>
> Is there an easier way than hard coding all the terms so it will go into fmincon?<br>
> <br>
> 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?<br>
      <br>
f = sum(x);<br>
f = f*(f+1);<br>
<br>
Roger Stafford

Wed, 08 Dec 2010 01:06:05 +0000
Re: long summation function for fmincon
http://www.mathworks.com/matlabcentral/newsreader/view_thread/298355#802768
Roger Stafford
> "stephen " <sca2c@virginia.edu> wrote in message <idmk5k$5vv$1@fred.mathworks.com>...<br>
> > 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?<br>
>       <br>
In answer to your second question, if c is the coefficient matrix and x is a column vector, then<br>
<br>
f = x.'*c*x<br>
<br>
will compute the first term using coefficients but I don't know what you want to do with the second term.<br>
<br>
Roger Stafford

Wed, 08 Dec 2010 14:44:05 +0000
Re: long summation function for fmincon
http://www.mathworks.com/matlabcentral/newsreader/view_thread/298355#802889
Matt J
"stephen " <sca2c@virginia.edu> wrote in message <idmk5k$5vv$1@fred.mathworks.com>...<br>
> 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:<br>
=======<br>
<br>
This is a quadratic function, so you should probably consider using QUADPROG, as opposed to FMINCON. Depends on your constraints, I guess.

Wed, 08 Dec 2010 15:02:15 +0000
Re: long summation function for fmincon
http://www.mathworks.com/matlabcentral/newsreader/view_thread/298355#802894
Matt J
"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <ido5jk$8bm$1@fred.mathworks.com>...<br>
> "stephen " <sca2c@virginia.edu> wrote in message <idmk5k$5vv$1@fred.mathworks.com>...<br>
> > 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:<br>
> =======<br>
> <br>
> This is a quadratic function, so you should probably consider using QUADPROG, as opposed to FMINCON. Depends on your constraints, I guess.<br>
<br>
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<br>
<br>
e=ones(120,1);<br>
hmfun=@(Hinfo,Y) e*sum(Y,1);