Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

How do I place the x and y values of the points I have found (maxandmindistance) above the point in a plot?

Here is my code so far:

Distance[t_] := t*(t - 1)*(t - 1.5)^2*(t - 3)
Velocity[t_] := Simplify[Distance'[t]]
maxandmindistance = Solve[Velocity[t] == 0, t]
Show[Plot[Distance[t], {t, 0, 3}], 
 Graphics[{Red, PointSize[Large], 
   Point[{t, Distance[t]} /. maxandmindistance]}]]

This results in a function with dots along it. They are the maximum and minimum values for the function. The problem is that the coordinates (x,y values) are not shown.

share|improve this question
    
Can you explain clearly what you expect and what happens instead? –  halirutan Nov 15 '12 at 9:48
    
Apologies. I end up with a line function with dots along it. They are the maximum and minimum values for the function. The problem is that the coordinates (x,y values) are not shown. –  General Stubbs Nov 15 '12 at 9:51
add comment

1 Answer

up vote 4 down vote accepted

Did you mean this?

Distance[t_] := t*(t - 1)*(t - 1.5)^2*(t - 3)
Velocity[t_] := Simplify[Distance'[t]]
maxandmindistance = Solve[Velocity[t] == 0, t];
coords = # + Chop[#2 - #] &[Round@#, #] &@({t, Distance[t]} /. 
maxandmindistance);
Show[Plot[Distance[t], {t, 0, 3}, 
  PlotRange -> {{0, 3.5}, {-2.5, 1.5}}], 
 Graphics[{Red, PointSize[Large], 
   Point[{t, Distance[t]} /. maxandmindistance],
   Table[{Black, Text[ToString[coords[[i]]], coords[[i]] + .3]}, {i, 
     Length[coords]}]
   }]]

enter image description here

If needed, you can also double-click on the image and adjust the formatting and the position of each text label to obtain the output you like most.

enter image description here

share|improve this answer
    
When I entered that in and stretched the graph so that the text did not overlap, the co ordinates just left. They were not attached to the point. –  General Stubbs Nov 15 '12 at 10:14
    
@GeneralStubbs What do you mean with "stretched the graph"? –  VLC Nov 15 '12 at 10:17
    
I took one of the corners of the plot and extended it making it larger. –  General Stubbs Nov 15 '12 at 10:18
    
@GeneralStubbs It doesn't happen to me. The text is defined to be at the same coordinates as the red points plus a shift of .3 to the right and upwards, so it always moves in sync with the red points when stretching the image. –  VLC Nov 15 '12 at 10:25
    
@GeneralStubbs See the update on how to manually adjust the position of the text labels. –  VLC Nov 15 '12 at 10:35
show 6 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.