I've just started using Mathematica for one my university modules, so I tried replicating the results from our practical.

I've defined a function

f[x_]:= ax - R/2 x^2

After this, if I define

ListA = Table [f[j/5] /.a -> 5 /.R -> 1/4,{j,0,75}] 

And then plot it with Plot1 = ListPlot[ListA] my graph will start from 1, rather than 0 (screenshot below) enter image description here

However, if I define

ListB = Table [f{j/5},f[j/5] /.a -> 5 /.R -> 1/4,{j,0,75}]

And then plot it with Plot2 = ListPlot[ListB], the graph starts from 0, as seen below enter image description here

Can anyone explain to me the logic in these commands? I've tried searching for the answer both on StackExchange and in Google and couldn't find anything. I really appreciate it!

P.S. Is there any way to manually adjust the colour-coding of syntax? I've figured out that it changes to green/orange when I stop typing, but some colour-coding is different from the original code, so I am not sure what to do with it. This is my first time posting on StackExchange, so I am still figuring it out

  • 1
    $\begingroup$ In definition of "f" you use "ax", but in "ListA" and "ListB" you use "a". Then, the definition of "ListB" is wrong syntax. Table take 2 arguments not 3 $\endgroup$ Commented Jan 23, 2023 at 18:02
  • $\begingroup$ Welcome to the community. Take a look at DiscretePlot. Side note, you can replace multiple items simultaneously like /. {a -> 5, R -> 1/4} $\endgroup$
    – Ben Izd
    Commented Jan 23, 2023 at 18:04
  • $\begingroup$ @DanielHuber I think I made a mistake of not put a space between 'a' and 'x'. I just want to define a function with a constant 'a' and a variable 'x' $\endgroup$
    – Windak
    Commented Jan 23, 2023 at 18:21
  • $\begingroup$ There's something funny with your code, but... It is a common convention in Mathematica that if a list of numeric values (instead of lists for multi-dimensional data) is given as input to a function which expects multi-dimensional data, it is interpreted as {{1, val1}, {2, val2}, ...} by default, starting "x coordinate" from 1. In the case of ListPlot this fact is implied by the documentation definition of the first syntax form, where you can see $\{y_1,\ldots,y_n\}$ being interpreted as $\{\{i,y_i\},\ldots,\{n,y_n\}\}$ which corresponds with $\{\{1,y_1\}\},\ldots,\{n,y_n\}\}$. $\endgroup$
    – kirma
    Commented Mar 1, 2023 at 5:56

1 Answer 1


f[x_] := **a x** - R/2 x^2 ;

ListA = Table[f[j/5] /. a -> 5 /. R -> 1/4, {j, 0, 75}]

Plot1 = ListPlot[ListA]

ListB = Table[f {j/5}, f[j/5] /. a -> 5 /. R -> 1/4, {j, 0, 75}]
  • 2
    $\begingroup$ This does not evaluate as posted. Please check for correctness and repost. Thanks. $\endgroup$
    – Syed
    Commented Jan 30, 2023 at 6:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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