Group Abstract Group Abstract

Message Boards Message Boards

0
|
9.3K Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to define findMaximum inside a table function?

Posted 10 years ago
Attachments:
POSTED BY: ash ash
3 Replies

The first step is come up with a simple example of your question. This will make it easier to show how this is done.

Here's a simplified version of your problem:

exampleFunctions = Table[a Sin[a x], {a, 0, 1, 0.1}];
Plot[exampleFunctions, {x, 0, 10}, PlotRange -> All]

How can we run FindMaximum on every function in eampleFunctions? Using Map:

getMaxValue[function_] := FindMaximum[function, {x, 0}]
maxvals = Map[getMaxValue, exampleFunctions]

Note that this doesnt' 100% work for this example. We would have to tweak how we find the max values. Still we can plot these max values:

dataToPoints[{yval_, {x -> xval_}}] := {xval, yval}
maxPoints = Map[dataToPoints, maxvals]
ListPlot[maxPoints]

And naively join the plots together:

Show[Plot[exampleFunctions, {x, 0, 10}, PlotRange -> All],  ListPlot@maxPoints]
POSTED BY: Sean Clarke
Posted 10 years ago

Sorry! I dint follow the code quite well, I tried something like this and it did not work...

Cpdata = Table[
  solNp = NSolve[(dNpdt /. sol) == 0, Np];
  Cp = (a Np (1 + \[Gamma]rs) (-1 + \[Delta]))/(
    b Np (-1 + \[Delta]) - (1 + \[Gamma]rs)^2 \[Mu]p) /. solNp[[1]],

  {Datm, 0.3, 3, 0.2}, {\[Delta], 0, 0.4, 0.01}]

getMaxValue[Cpdata_\[Delta]] := FindMaximum[Cpdata, {x, 0.4}]
maxvals = Map[getMaxValue, Cpdata]
POSTED BY: ash ash

It looks like there's variable definitions missing here.

Debugging code is a skill and not an easy one to learn. In the code you attached above you are generating a huge list of Interpolations. Then you are trying to find the maximum value for each of them individually.

If you are having trouble, then do this: Create only one of the interpolating functions. Then find its maximum value. The plot it and it's maximum value.

When you get stuck, step back, find a simpler version of the problem and then work on it.

POSTED BY: Sean Clarke
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard