'How to use the values from FindRoot?

Im trying to use FindRoot to mark points on a graph.

What I want to do is Draw a line on the graph at the x and y points of the max of the function using this:

g = 2 Sin[t];
g2 = FindMaxValue[g, t];
g3 = FindRoot[g == g2, {t, 1}];
Plot[g, {t, 0, 3}, GridLines -> {{g3}, {g2}}]

But FindRoot produces {t -> 1.5708} which doesn't work in the gridlines command so i have to manually type it in like this:

g = 2 Sin[t];
g2 = FindMaxValue[g, t];
g3 = FindRoot[g == g2, {t, 1}];
Plot[g, {t, 0, 3}, GridLines -> {{1.5708}, {g2}}]

Is there a way of getting the value of g3 just as a number? Thanks



Solution 1:[1]

FindRoot returns a "Rule" instead of a value. This is common among many Mathematica functions.

Use

g3 =t/. FindRoot[g == g2, {t, g2}];

and that will extract the value from that Rule.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Bill