Mathematica FindMaximum Mathematica: Get Numerical Value from Cos[t]

  • Thread starter Thread starter Nusc
  • Start date Start date
  • Tags Tags
    Mathematica
AI Thread Summary
The discussion revolves around using Mathematica to evaluate the cosine function and find its maximum value within a specified range. The user initially struggles with obtaining a numerical output for Cos[t] after determining the maximum time using FindMaximum. Suggestions include ensuring proper syntax, such as adding commas and using the Evaluate function to facilitate calculations. There is a mention of issues with the FindMaximum command, particularly regarding its ability to find the greatest maximum in certain cases. The recommendation to use NMaximize is provided as a potential solution, acknowledging its occasional inaccuracies. Additionally, users discuss how to format output to avoid clutter on the page, emphasizing the importance of Mathematica's help files for troubleshooting.
Nusc
Messages
752
Reaction score
2

Homework Statement



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?

Homework Equations





The Attempt at a Solution



Evaluate won't work.
 
Physics news on Phys.org


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.
 


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?
 


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:


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?
 


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


Code:
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:
?NMaximize

Glad you figured out how to use the Evaluate function ... :rolleyes:
 

Similar threads

Replies
5
Views
3K
Replies
1
Views
2K
Replies
4
Views
3K
Replies
3
Views
2K
Replies
2
Views
1K
Replies
2
Views
2K
Replies
6
Views
4K
Replies
1
Views
2K
Back
Top