Re: Optimizing a function with a list as a parameter
- To: mathgroup at smc.vnet.net
- Subject: [mg103109] Re: Optimizing a function with a list as a parameter
- From: Francesco <b.gatessucks at gmail.com>
- Date: Tue, 8 Sep 2009 05:58:27 -0400 (EDT)
- References: <h829kh$3s4$1@smc.vnet.net>
f[x_List] := Plus @@ (x^2) myMax[func_, args_, constr_] := Maximize[Join[{func[args]}, constr[[#,1]] <= args[[#]] <= constr[[#, 2]] & /@ Range[Length[args]]], args] In[14]:= f[{a, b, c}] Out[14]= a^2 + b^2 + c^2 In[25]:= myMax[f, {a, b, c}, {{-0.1, 1}, {-0.2, 2}, {-0.3, 3}}] Out[25]= {14., {a -> 1., b -> 2., c -> 3.}} -Francesco On 09/07/2009 07:36 AM, Mike Miller wrote: > I have a time-series like function which gives an output based on a > list of real numbers(i.e. you can run the function on a list of > 1,2,3,... real numbers). The issue I'm encountering is how to maximize > the function for a given list length(subject to a set of constraints). > I could fix the function to a fixed number of real numbers(i.e. f > [x_Real, y_Real] instead of f[x_List]) and treat x and y as the first > two elements of the list, and call Maximize on the function, but this > is not really elegant. I want to be able to easily change the number > of elements in the list. > > What is the best way to optimize a function like I described, which > takes a list as an argument, for a fixed list length? > > Thanks, > Mike >