# Print function value at specified coordinate

Below is the code to evaluate the function. I am trying to print the function values at a specified coordinate as shown in ActCoor.

 t = 9600;
HillPlot =
Plot[E^(-((-2000 + 0.5 (-t + 2 x))^2/139392)), {x, 0, 12000},
PlotRange -> Full, PlotStyle -> {Green, Dashed}]
ActCoor = Do[Print[x], {x, 0, 12000, 500}]


Above gives me the plot.

f[x_] := E^(-((-2000 + 0.5 (-t + 2 x))^2/139392))
(*ptint solution at ActCoor*)
Do  ii = 1 : ActCoor
PhiAn = Evaluate[f[ii]]


Here I tried to print the function values at ActCoor but no success. I also tried with

p = Cases[HillPlot, Line[p_] :> p, All]

But it gives the function values at random x-coordinate.

Any suggestion would be appreciated.

One additional edit need to be done. All x coordinate and their function values need to repeat. Like, {0,0,500,500,1000,1000,......,11500,11500,12000} except last node.

• Use actCoor=Range[0, 12000, 500] to define an array of equally spaced coordinates, but also consider using Subdivide. Then, evaluate f[ actCoor ] to get the function values. If you want ordered pairs $(x, f(x))$, use Thread[ {actCoor, f[ actCoor ] } ], or Transpose[ {actCoor, f[ actCoor ] } ]. There are other ways: see Table and Array. Maybe use ColumnForm, MatrixForm or Grid to display the ordered pairs. Nov 24 '20 at 10:43
• perfect! This works. Nov 24 '20 at 10:57
• Is it possible here to print x-coordinate twice except last coordinate? Like {0,0,500,500,1000,1000,1500,1500.........,11500,11500,12000} Nov 24 '20 at 11:24

Printis the wrong command, try Text:

t = 9600;
f[x_] := E^(-((-2000 + 0.5 (-t + 2 x))^2/139392))
HillPlot =
Show[{Plot[f[x], {x, 5000, 9000}, PlotRange -> Full,PlotStyle -> {Green,Dashed}],
Graphics[Table[ Text[ {x, f[x]} , {x, f[x]}] , {x, 6000, 8000, 500}]]}]


If you want to display only the table try

TableForm@Table[{x, f[x]}, {x, 0, 12000, 1000}]


• Your suggestion is great. It helps me to learn new syntax. This prints the solution values in to the graph. But expected is to print into the notebook for comparison purpose. Thanks. Nov 24 '20 at 11:01
• Thanks, try TableForm@Table[{x, f[x]}, {x, 0, 12000, 1000}]  (see my answer) Nov 24 '20 at 11:03

I think it might be worthwhile to solve this problem so that the tabulated points are symmetric about the function's maximum. To do so, we start by finding where that maximum occurs. In this case, the maximum is easily found by expection. This is demonstrated like so:

With[{t = 9600},
f[x_] := E^(-((-2000 + 0.5 (-t + 2 x))^2/139392))]
With[{xmax = 6800},
Plot[f[x], {x, 5000, 8600},
Epilog -> {Dashed, Line[{{xmax, 0}, {xmax, 1}}]},
PlotRange -> All]]


Now that we know the maximum is at 6800, we can code for a table that show $$k$$ equally spaced points below and above the maximum. We will also make a plot showing the nicely spaced points. Like so:

With[{xmax = 6800, dx = 200, k = 7},
Module[{pts, plot},
pts = Table[{x, f[x]}, {x, xmax - k dx, xmax + k dx, dx}];
plot =
Plot[f[x], {x, 0, 12000},
PlotRange -> All,
Epilog -> {Red, AbsolutePointSize@6, Point[pts]},
ImageSize -> Medium];
Column[{TableForm[pts, TableHeadings -> {None, {"x", "f[x]"}}], plot},
Spacings -> 1.5]]]