Reputation: 11
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
Upvotes: 1
Views: 1109
Reputation: 3977
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.
Upvotes: 1