# Plotting using table function

I'm trying to generate a plot in mathematica using the Table function. Below is an example of what I'm trying to produce:

f[x_, y_, z_]:= (x + y + z)^2
Table[f[1, 2, x=z], {z, 0, 10, 2}]= {9, 25, 49, 81, 121, 169}


Now I want to plot the output from Table[f[1, 2, z], {z, 0, 10, 2}] against the same range of z values inputed into the function (0, 2, 4, 6, 8, 10). I have tried all sorts but really can't get it to work. It should be pretty basic but I haven't used mathematica in a while-appreciate your help with this

Thanks

• ListPlot[{9, 25, 49, 81, 121, 169}, DataRange -> {0, 10}] Mar 6 at 17:26
• Thanks so much Daniel-I completely forgot about ListPlot. That DataRange option is pretty handy for this! Mar 6 at 17:28

One option could be to use the ListLinePlot with {{x,y},...} input. For this you need to transpose the x,y data that you have.

I changed your x=z in the code to just z. I did not see a reason to write x=z there.

ClearAll[x, y, z];
f[x_, y_, z_] := (x + y + z)^2
range = Range[0, 10, 2]
data = Table[f[1, 2, z], {z, range}]
mat = Transpose[{range, data}] The above is your {x,y} data. Now plot it using

ListLinePlot[mat, Mesh -> All, MeshStyle -> Red] • Thanks for your solution Nasser Mar 6 at 17:28