# Maximise a function over one parameter that is continuous, and one that is discrete

I have a function that I would like to maximise with respect to two parameters: one continuous, another which is discrete.

A simple example of this might be the following:

data = RandomVariate[NormalDistribution[], {1000}];
z[c_, d_Integer] := Sum[data[[i]]^c, {i, 1, d}];


I would like to maximise this function $z$ over choice of $c$ - a continuous variable; and $d$ - a discrete one.

At the moment, I have been iteratively searching for a solution over $c$, then using this value for $c$, in order to maximise (using the Mathematica function $Maximize$ with the domain type specified as $Integers$) the function over $d$. I then repeat the continuous maximisation using the value of $d$ found, continuing ad infinitum.

Does anyone know of a solution that will simultaneously search for a maximum over both variables?

Note that this is a merely supposed to be an indicative example, not the actual function, so please do not suggest 'tricks' that are only relevant to this particular function form.

Best,

Ben

• Consider the function z[c, Round[d]] – J. M.'s ennui May 28 '15 at 17:43
• Thanks for your comment. I have tried the edits shown in the new question - it seems to sort of work. I get a warning/error. Any ideas? – ben18785 May 28 '15 at 17:51
• Wasn't the warning self-explanatory? Somehow, you have an idea of a "reasonable region", no? – J. M.'s ennui May 28 '15 at 17:58
• Ok, I will close the question. I suspect the example I have given isn't quite perfect! Thanks for your help. Best, Ben – ben18785 May 28 '15 at 18:01
• Syntax might be an issue. And the specifics of the problem. For this example one can do: data = RandomVariate[NormalDistribution[], {1000}]; z[c_, d_Integer] := Sum[Abs[data[[i]]^c], {i, 1, d}];NMinimize[{z[c, d], Element[d, Integers], 1000 >= d >= 1, c >= 0}, {c, d}] and get a viable result. – Daniel Lichtblau May 29 '15 at 16:18

The following workaround suggested by user Guess who it is works ok:

NMaximize[{z[c, Round[d]],d>0},{c,d},Reals]


Your function z[c, d] is independent of c

RandomSeed[1];

data = RandomVariate[NormalDistribution[], {1000}];
z[c_, d_Integer] := Sum[data[[i]]^d, {i, 1, d}];

MaximalBy[{#, z[c, #]} & /@ Range[2, 1000], Last]


{{1000, 1.455004716249383*10^489}}

Since the data contains negative values, even powers are highly likely to give the largest values.

MaximalBy[{#, z[c, #]} & /@ Range[2, 1000, 2], Last]


{{1000, 1.455004716249383*10^489}}

• Hi, my apologies for the error in the function; it should have been to the power $c$. Not sure whether the above answer still applies, but many thanks nonetheless. Best, Ben – ben18785 May 28 '15 at 21:41