0

This is really a question about manipulating the output of Maximize. I have a function of 2 variables, defined thus:

 Pqpcum[r_, b_] = Integrate[2 Pi*x*Pqp[x, b], {x, 0, r}, Assumptions -> {b > 0}]

I want to find the point where the maximum of a certain function, defined below, occurs:

Abs[Pqpcum[x1, b] - Pqpcum[x1, 0]], x1]

The function Maximize returns an array, like this:

In[24]:= Maximize[Abs[Pqpcum[x1, 0.1] - Pqpcum[x1, 0]], x1]

Out[24]= {0.0204023, {x1 -> 1.77787}}

Now I want to plot the location of the maximum, which is 1.77787 in this case, as a function of b. Attempting to get the second element of the array returns an element like this:

{x1 -> 1.777869648006448`}

The above cannot be plotted. I need to do something like this:

Plot[Maximize[Abs[Pqpcum[x1, b] - Pqpcum[x1, 0]], x1][[2]],{b,0,0.2}]

except that the above doesn't return anything, since I have plotted the list. How can I go about doing it? I could discretize the data and manually copy-paste the location of maximum values to do a ListLinePlot, but it would be a pain to do it.

EDIT:

I found my answer- I can use ArgMax instead. It directly returns the location of the maximum, so the above can be done. But the question still remains- how in general can one manipulate a list that reads like {x1 -> 1.777869648006448} to get only the numeric value 1.777869648006448?

Abhinav
  • 143
  • 5
  • @Abhinav From your In[24]-Out[24] and what you wrote I have the impression that the coordinates of the maximum point are independent of b. Otherwise the dependence upon b would already show up explicitly in the Out[24]. That explains, why the plot returns nothing. In this situation I would try it with a simplest possible function Pqp[x, b], which would enable me to get integral exactly, just to make sure that the code works. – Alexei Boulbitch Oct 21 '13 at 09:04
  • @Kuba- Thanks! I needed to figure out how to use the replacement rule, but did not know what it was called, so I couldn't google it up. So now all I need to do is Plot[x1/.Maximize[Abs[Pqpcum[x1, b] - Pqpcum[x1, 0]], x1][[2]],{b,0,0.2}] How can I mark this question as solved? @Alexei - My In[24] is for a specific case where b takes the value 0.1. The general one is dependent on b, and it is the value that I needed to get. – Abhinav Oct 21 '13 at 10:04
  • @Abhinav It is going to be closed as a duplicate so don't worry about it. Also, you could have selected -> and press F1 to find out it's a Rule :) – Kuba Oct 21 '13 at 10:08

0 Answers0