Message Boards Message Boards

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

How to define findMaximum inside a table function?

Posted 9 years ago

Hi,

I wanted to define findmaximum in the attached file and wonder how to do it.. if you see the plot that i made in the mathematica fille , I have a Cp range for delta on the x-axis.. just wondering if there Is there any code to highlight the maximum Cp value inorder to find the correspoding delta ?

from the generated table, I can manually figure out that at D = 0.3 (the lowest blue line),

the delta is 0.12 and the Cpo = 754.693

but just wondering if there is any code to highlight the maximum Cp values and the delta where it is in maximum?

any sort of help would be very much useful..!

thanks in advance

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 9 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

Group Abstract Group Abstract