Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

FindMaximum Mathematica

  1. Jul 22, 2008 #1
    1. The problem statement, all variables and given/known data

    Print[Plot[N[Cos[t]] == 0, {t, 0, 10}], ","
    "Time to reach 1=", t /. Last[FindMaximum[N[Cos[t]], {t, 5}]], ","



    I need Cos[t] to output a numerical value as obtained from FindMaximum, how do I do this?

    2. Relevant equations

    3. The attempt at a solution

    Evaluate won't work.
  2. jcsd
  3. Jul 22, 2008 #2
    Re: Mathematica

    Please post a complete code example or attach your .nb file (click the paper clip in the reply window)

    That said, it looks like you're missing commas at the end of your third and fourth lines. You may also need to look into using the Evaluate[] function in your fourth line.
  4. Jul 22, 2008 #3
    Re: Mathematica

    That piece should suffice. Does anyone else know what I'm talking about? You don't even need to put this in a loop.
    If I put this command in Mathematica
    "Time to reach 1=", t /. Last[FindMaximum[N[Cos[t]], {t, 5}]], ","
    How can I make Mathematica evaluate

    numerically using the command that found t above?
  5. Jul 22, 2008 #4
    Re: Mathematica

    Also how do you insert a linebreak to prevent Mathematica from writing output all across the page? I'm in math type and cannot use text.

    I got my expression to evaluate so don't worry about the above post.
    Last edited: Jul 22, 2008
  6. Jul 22, 2008 #5
    Re: Mathematica

    Actually wait, I take that back

    For each x there is a corresponding density function. Most are aperiodic and so will attain a maximum at a different time than the others. Unfortunately I did not take this into consideration and only used the following command.

    "Time to reach 1=", den21 /. Last[FindMaximum[N[den21], {t, 2}]], ","

    The interval 0-2 is short and some attain a maximum at t = 10, how do I implement this into the script?
  7. Jul 22, 2008 #6
    Re: Mathematica

    Unfortunately, Maximize[] doesn't give you the greatest maximum but only the first maximum.
  8. Jul 23, 2008 #7
    Re: Mathematica

    Code (Text):
    is not working code. Obviously.

    Try the NMaximize[] function. Like all numerical functions, it is not without error and will find incorrect solutions occasionally, but those cases are rare (I've only seen one).

    The help files are really your friend when looking for a specific Mathematica function. You can get to them with the "F1" key, or get quick help by placing a ? mark in front of the command you want:
    Code (Text):
    Glad you figured out how to use the Evaluate function ... :rolleyes:
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: FindMaximum Mathematica
  1. In mathematica (Replies: 4)

  2. Mathematica and Sums (Replies: 4)

  3. Mathematica Sums (Replies: 6)

  4. Mathematica NDSolve (Replies: 27)