Mathematica Mathematica:how to plot a maximum point in a graph

AI Thread Summary
The discussion revolves around plotting the maximum point of the sine function using Mathematica without manually entering coordinates. The user initially plots the sine function from 0 to Pi and uses FindMaximum to determine the maximum point. They express a desire to automate the plotting of this maximum point. One suggestion provided is to create a test function with specific coordinates and plot those points, adjusting for scaling if necessary. Another solution involves using the output of FindMaximum directly to obtain both the x and y coordinates for the maximum point. The user is guided to modify their ListPlot command to automatically use the y-value from the FindMaximum function, allowing for a dynamic plot that reflects the maximum value without manual input. The final code shared demonstrates how to achieve this by using the sine function's value at the maximum point directly in the ListPlot command.
shafieza_garl
Messages
20
Reaction score
0
anyone can help me to plot a point.

Code:
 r = Plot[Sin[j], {j, 0, Pi}];
what i am doing is i use FindMaximum first to know the point of maximum.
Code:
FindMaximum[Sin[j], {j, Pi}]

then i manually key in the x,y coordinate from the search.

Code:
onedot = ListPlot[{{1.5707963267948966, 1}}, 
   PlotStyle -> {Hue[0.67], AbsolutePointSize[7]}];
Show[r, onedot]

is there any way i can plot the maximum point without key-in manually using the findmaximum point.
thanks
 
Physics news on Phys.org
shafieza_garl said:
anyone can help me to plot a point.

Code:
 r = Plot[Sin[j], {j, 0, Pi}];
what i am doing is i use FindMaximum first to know the point of maximum.
Code:
FindMaximum[Sin[j], {j, Pi}]

then i manually key in the x,y coordinate from the search.

Code:
onedot = ListPlot[{{1.5707963267948966, 1}}, 
   PlotStyle -> {Hue[0.67], AbsolutePointSize[7]}];
Show[r, onedot]

is there any way i can plot the maximum point without key-in manually using the findmaximum point.
thanks

One suggestion I have is to create a test function with {-1,0} {0,maxpoint} and {+1,0) and then plot that data like any other data. If you need to adjust scaling or if Mathematica produces a very narrow graph then make the non-max points larger in the respective directions.

If you need the point at its original position then just add the x coordinate to every x point in the dataset.
 
r = Plot[Sin[j], {j, 0, Pi}];
onedot = ListPlot[{j, 1} /. Rest[FindMaximum[Sin[j], {j, Pi}]], PlotStyle -> {Hue[0.67], AbsolutePointSize[7]}];
Show[r, onedot]
 
Bill Simpson said:
r = Plot[Sin[j], {j, 0, Pi}];
onedot = ListPlot[{j, 1} /. Rest[FindMaximum[Sin[j], {j, Pi}]], PlotStyle -> {Hue[0.67], AbsolutePointSize[7]}];
Show[r, onedot]

thanx 4 ur reply.1 more question. if i don't want to put value 1 by myself and i want the same as finding the j-value(using findmaximum).
Code:
onedot = ListPlot[{j, k} /. Rest[FindMaximum[Sin[j], {j, Pi}]],  PlotStyle -> {Hue[0.67], AbsolutePointSize[7]}];
is this possible to do?
thanks again.
 
r = Plot[Sin[j], {j, 0, Pi}];
onedot = ListPlot[{j, Sin[j]} /. Rest[FindMaximum[Sin[j], {j, Pi}]], \
PlotStyle -> {Hue[0.67], AbsolutePointSize[7]}];
Show[r, onedot]
 

Similar threads

Replies
2
Views
2K
Replies
1
Views
2K
Replies
1
Views
2K
Replies
1
Views
2K
Replies
4
Views
2K
Replies
2
Views
1K
Back
Top