# How do I graph only integers using the list function?

I have plotted the following function using the following code:

integers = Table[Integer[n], {n, 20}];
ListPlot[Table[{x,
x^(-1)*Sum[((6.674*(10^(-11))*(10^17) (4))/((100^2 -
400 (2 Cos[(2 Pi k)/x] - 3 Sin[(2 Pi k)/x]) +
29)^1.5)), {k, 0, x - 1}]}, {x, integers}]]


The function oscillated because it takes values that are not integers. I have searched around and the above does not work. I'm new to mathematica. How can I change the code to make it only use integer values of x?

• Try it with integers = Range[20] . – LouisB Sep 21 '17 at 3:50
• thanks, another question-where do I put this: AxesOrigin -> {0, 0} – Omkar Vaidya Sep 21 '17 at 3:55
• @OmkarVaidya at the end of ListPlot after a comma: ListPlot[...., here] – Alucard Sep 21 '17 at 3:57
• @Alucard what if I want to change the range of the function? Perhaps from 3 to 100? – Omkar Vaidya Sep 21 '17 at 4:08
• @OmkarVaidya do you mean the points or the range of the listplot? in the first case write Range[3,100], otherwise add PlotRange->{{yourxmin,yourxmax},{yourymin,yourymax}} after AxesOrigin. don't forget the comma between the 2 options. – Alucard Sep 21 '17 at 4:40

You can useDiscretePlot:

f[x_] := Sum[((6.674*(10^(-11))*(10^17) (4))/((100^2 -
400 (2 Cos[(2 Pi k)/x] - 3 Sin[(2 Pi k)/x]) + 29)^1.5)), {k,
0, x - 1}]/x
DiscretePlot[f[n], {n, 1, 20}, PlotRange -> Full]


• Note that the original post has a factor of x^(-1) in front of the Sum. – LouisB Sep 21 '17 at 9:34
• @LouisB thank you. I missed that. I guess it still illustrates use of DiscretePlot. Will change if/when I get time. – ubpdqn Sep 21 '17 at 9:36

There is a lot to be said for making code easier to read. In this case we can write

data = Table[{x, x^(-1)*Sum[((6.674*(10^(-11))*(10^17) (4))/((100^2 -
400 (2 Cos[(2 Pi k)/x] - 3 Sin[(2 Pi k)/x]) +
29)^1.5)), {k, 0, x - 1}]}, {x, 20}];

ListPlot[data]
ListPlot[data, AxesOrigin->{0,25}]


Notice that we do not define integers because Table takes care of that for us. One advantage of the above is that we can examine our data with

data // Dataset


and we can add options to our ListPlot to build up the command we want. The optional arguments are added in any order after the required arguments. They always have the form of rules, like PlotRange->{All,{25,30}}

We can see the coordinates of a plotted data point by using ListPlot[Tooltip[data]] as the basic command and hovering the mouse pointer over the point whose coordinates we want.

• I also wanted to know how to check the coordinates of a point on the graph. I used the drawing tool, but the y-values of the points are too close to see a difference. – Omkar Vaidya Sep 21 '17 at 4:25
• @OmkarVaidya I add a paragraph that shows a basic example of how to display the coordinates of a plot data point. If you search this site for "Tooltip" you will see some clever examples of how to use this command. – LouisB Sep 21 '17 at 5:02
• Thanks for that! The problem is that it only shows 4 decimal places, and all the points show the same value (27.1063). How can i change this? – Omkar Vaidya Sep 21 '17 at 5:42