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 firstPartofmaxSplit[...]. You could also usePlotbut it takes a long time. – kglr May 25 '18 at 11:52FindMaximumto definemaxSplit2. This does not return a single value, soPlotdoesn'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 useNArgMax. Notice also that you have an extra)in your definition ofmaxSplit2as posted here. – MarcoB May 25 '18 at 14:30