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

Posted 1 year ago
1040 Views
|
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
Sort By:
Posted 1 year ago
 Nikol,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_}] := Regards Neil
Posted 1 year 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? Attachments:
Posted 1 year ago
 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.
Posted 1 year ago
 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.Regards