# FindMaximum Mathematica

1. Jul 22, 2008

### Nusc

1. The problem statement, all variables and given/known data

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

]

]
,{c,0,10},{b,0,100}]

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. Jul 22, 2008

### confuted

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.

3. Jul 22, 2008

### Nusc

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
Cos[t]

numerically using the command that found t above?

4. Jul 22, 2008

### Nusc

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
5. Jul 22, 2008

### Nusc

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?

6. Jul 22, 2008

### Nusc

Re: Mathematica

Unfortunately, Maximize[] doesn't give you the greatest maximum but only the first maximum.

7. Jul 23, 2008

### confuted

Re: Mathematica

Code (Text):
If[..,
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):
?NMaximize
Glad you figured out how to use the Evaluate function ...