Message Boards Message Boards


[✓] Plot and print out values of a function in NestList?

Posted 9 months ago
6 Replies
1 Total Likes

Hi, I'm new to Mathematica and I'm having troubles in understanding how to evaluate a custom function that I applied NestList to. Here's my function:

f[x_, m_] := m*x /; 0 <= x < 1/2
f[x_, m_] := m*(1 - x) /; 1/2 <= x <= 1
x = 0.2
m = 2

Next I got NestList like this:

NestList[f, {0.2, 2}, 4]

which have given me following output:

{{0.2, 2}, f[{0.2, 2}], f[f[{0.2, 2}]], f[f[f[{0.2, 2}]]], 
 f[f[f[f[{0.2, 2}]]]]}

Now instead of printing f f f .... f f I'd like to see actual values of the function f after evaluation such as {value 1, value 2, value 3, ..., value n}. Moreover I'd like to plot such a NestList where values in NestList would be coordinates of n points on axis.

Any help, advice or example would be greatly appreciated.

EDIT: I'm studying Dynamic systems and trying to compute and plot so called "tent map"

6 Replies


You defined the function f incorrectly. If you want to pass it a list of two arguments your pattern must be a list. Also, all patterns for named variables must have underscores after them:

f[{x_,m_}] :=



Posted 9 months ago

![][1] I don't know what i did wrong but still i have the same problem. Do you know where could be a problem?


f operates on a list the first time, it returns a single number, then you send that number to f again. The function f does not know what to do with a single number unless you define another function of f that takes one number. You can see this in your output because you have f[.4] for example.

I am not really sure what you are trying to do.

One simple fix is to have f return a list with your value from above followed by m. Now the Nest will work.

f[{x_,m_}] := {m*x /; 0 <= x < 1/2, m}

(Same for other function)

Now the Nest will work.


Posted 8 months ago

Thank you for your help.

Finally was enough to use just this as you can see on the picture.

enter image description here

@Nikol Skorupova, please do not post code as images. This clearly explained in the forum rules:

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract