# Trouble Plotting the maximum values of a function

First off, I apologize if this question is either incredibly obvious, or has been clearly asked and answered before. I've been searching the forum for a while, and the questions and answers thusfar have either gone over my head (such as this question and this question) or don't seem to solve the issue I'm facing.

All I'm trying to do is plot the maximum values of a function over a given range. The functions I have so far are:

fp3[p_, a_, b_] := (1 + b)*p - b*(p^a)
v3[fp3_, p_, a_, b_] := 1 - fp3[1 - p, a, b]
pbar[pi_, ph_, pl_] := pi*pl + (1 - pi)*ph


Which are then used to create the function of interest:

valSplit2[v3_, fp3_, ph_, pl_, a_, b_, pi_, pbar_] :=
(fp3[pi, a, b]* v3[fp3, pl, a, b] - v3[fp3, pbar, a, b])) + (1 - fp3[pi, a, b])*(v3[fp3, ph, a, b] - v3[fp3, pbar, a, b])


Ultimately, I'd like to be able to dictate certain values (namely for a and b) and let Mathematica maximize the valSplit2 function. I'd like to then plot these values as pbar varies from 0 to 1. To do this, I'm defining another function:

maxSplit2[valSplit2_, v3_, fp3_, ph_, pl_, a_, b_, pi_, pbar_] :=
FindMaximum[{valSplit2[v3, fp3, ph, pl, a, b, pi, pbar], 1 >= ph > pl >= 0, pi*pl + (1 - pi)*ph == pbar, 1 >= pi >= 0}, {ph, pl, pi}]


Which includes the desired bounds for ph, pl, and pi. Even though this definition is clunky, I think it works (at least for discrete values), since asking for any individual value through:

N[maxSplit2[valSplit2, v3, fp3, ph, pl, 20, .05, pi, .03], 8]


For example, yields the correct maximized value. However, plotting:

Plot[maxSplit2[valSplit2, v3, fp3, ph, pl, 20, .05, pi, x], {x, 0, 1}]


Simply leads to a blank set of axes.

I'm sure that there's a problem either in the syntax, or in the types of variables I've defined. But since I'm just getting blank axes seemingly no matter what similar method I'm using (instead of an error message), I can't troubleshoot the problems successfully.

Any insight anyone has would be greatly appreciated!!

Thank you!

• ListLinePlot[ Evaluate[N@ maxSplit2[valSplit2, v3, fp3, ph, pl, 20, .05, pi, #][[1]] & /@ Range[0, 1, .01]]]? Note that we are using the first Part of maxSplit[...]. You could also use Plot but it takes a long time.
– kglr
May 25, 2018 at 11:52
• @kglr thank you so much for the comment! This is a huge improvement (no surprise there! haha)! When this is run, though, it seems like a few values are either being computed incorrectly, or there's some other minor issue, since there are massive dips (for example, at "20" on the x axis, the plotted value drops from roughly .016 to 0, but then shoots back up for the next point). Any ideas on what might be causing that? And just so I know, when you say "plot" would take a long time, are you referring to coding-time or computational time? Thank you so much!!! May 25, 2018 at 12:36
• As kglr mentioned, the problem lies in the use of FindMaximum to define maxSplit2. This does not return a single value, so Plot doesn't know what to do with it. If you want to plot the maximum value of your function, you should use e.g. NMaxValue; if you want to plot the value of x at which the maximum is attained, then you could use NArgMax. Notice also that you have an extra ) in your definition of maxSplit2 as posted here. May 25, 2018 at 14:30