FindMaximum Mathematica: Get Numerical Value from Cos[t]

  • Context: Mathematica 
  • Thread starter Thread starter Nusc
  • Start date Start date
  • Tags Tags
    Mathematica
Click For Summary

Discussion Overview

The discussion revolves around using Mathematica to obtain numerical values from the cosine function, specifically in the context of finding maximum values using the FindMaximum function. Participants explore coding issues, syntax errors, and the behavior of different Mathematica functions in this context.

Discussion Character

  • Homework-related
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant seeks a method to obtain a numerical value from Cos[t] after using FindMaximum, indicating that Evaluate does not work for their needs.
  • Another participant suggests that missing commas in the code may be causing issues and recommends using the Evaluate[] function.
  • A different participant questions the necessity of a loop for the command to evaluate Cos[t] numerically and seeks clarification on how to implement this.
  • One participant mentions a concern about the density function and its maximum values occurring at different times, suggesting that the initial time interval used may be too short.
  • Another participant notes that Maximize[] does not find the greatest maximum but only the first maximum, implying a limitation in its use.
  • A participant recommends using NMaximize[] instead, acknowledging that it may occasionally yield incorrect solutions, but generally finds it reliable.

Areas of Agreement / Disagreement

Participants express differing views on the effectiveness of various Mathematica functions for finding maximum values, with no consensus on the best approach. Some participants agree on the need for proper syntax, while others debate the limitations of the functions discussed.

Contextual Notes

Participants mention specific coding issues, such as missing commas and the need for line breaks in output, which may affect the clarity and functionality of their scripts. There is also a recognition of the potential for numerical functions to yield incorrect results under certain conditions.

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 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K