Message Boards Message Boards

4 Replies
3 Total Likes
View groups...
Share this post:

picking particular values of the function

Posted 10 years ago

Hi guys! Its probably a very simple question..

Suppose you have some function f(x).

ListPlot[Table[f, {x, 1, 5}]]  

gives you all values of the function for x=1,2,3,4,5 But, what is the syntax if I'd like to take particular values, say f(1) and f(3)?

Many thanks, D

4 Replies

Even better. Thanks David.

POSTED BY: Isaac Abraham

A slightly simpler version of Issac Abraham's approach would be (using the function Map, see

ListPlot[f/@{1, 3, 8, 2.5}]

Issac's approach requires that the function that you use have the Attribute, Listable, which may often be the case for simple functions, but may not be true for more complicated ones. The approach that I gave does not depend on a Listable Attribute.

POSTED BY: David Reiss

For specific values, you may also try

f[x_]:=x^2(*or any other function*);
ListPlot[(*Function*) f[x](*replace x*)/. x ->(*with specific list of x values*){1, 3, 8, 2.5}]
POSTED BY: Isaac Abraham
Posted 10 years ago

If you aim is to plot a discrete (but not necessarily arithmetic progression) you could use (where f here is x^2):

ListPlot[Table[x^2, {x, {1, 3}}]]

or use DiscretePlot:

DiscretePlot[x^2, {x, {1, 3}}]
POSTED BY: Mark Dooris
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract