Mathematica Iterative Function with Last 10 Values for Any Input Constant K

AI Thread Summary
The discussion revolves around iterating a function f(x) = x^7 + k, starting with x0 = 1, and storing the last 10 values after 50 iterations for various constants k. Users express challenges in applying the code to different functions and understanding the output, particularly when using NestList in Mathematica. There is a suggestion that the approach may be overly complex and that a simpler method could achieve the desired results. Additionally, the importance of grasping the underlying concepts of Mathematica programming is emphasized, with recommendations for resources to aid learning. Overall, participants seek clarity on function iteration and effective Mathematica usage.
peter.a
Messages
19
Reaction score
0
say I have a function f(x)=x^7+k
I want to iterate x(n+1)=f(xn), 50 times
starting with x0=1
and keep the last 10 values
i want to assigh these values to some function''y'' and be able to use y to calculate this iteration for any input constant K. ie say K=0, K=0.5 etc, and then i want to store these values for different values of constants?Is this possible?I can't figure it out

i have tried this far
f:=x^7+k
y:=Take[NestList[f, 0, 50], -10]
 
Physics news on Phys.org
In[1]:= f[x_]:=x^7+k;y=Take[NestList[f,x,50],-10]

And then

In[3]:= y/.k->0.5
 
Could you explain to me how it works, so i can apply it to other functions, when i try and use thje code for a different function f i get errors?
 
Do you have a specific example that does not work?

"I typed some stuff in, some stuff came out, some stuff is wrong, what do I do?" is extremely difficult to provide an answer for.

In[1]:= f[x_]:=Sin[x];y=NestList[f,x,5]

Out[1]= {x, Sin[x], Sin[Sin[x]], Sin[Sin[Sin[x]]], Sin[Sin[Sin[ Sin[x]]]], Sin[Sin[Sin[Sin[Sin[x]]]]]}

In[2]:= f[x_]:=1/(x+1);y=NestList[f,x,5]

Out[3]= {x, (1 + x)^(-1), (1 + (1 + x)^(-1))^(-1), (1 + (1 + (1 + x)^(-1))^(-1))^(-1), (1 + (1 + (1 + (1 + x)^(-1))^(-1))^(-1))^(-1), (1 + (1 + (1 + (1 + (1 + x)^(-1))^(-1))^(-1))^(-1))^(-1)}
 
Hi Bill
This is exactly what I am stuck on;

I have a function as follows defined;

f[a_][x_] := x^2 + a;
Then i define
w[a_] := Take[NestList[f[-1.8], 0, 1000], 100]
Similar to what you mentioned in the previous post

Now i want to evaluate this for different values of the constant a from -1.8, to 0.3, store the results in a table, supress the results because they will be very long, and then make a plot of "a" versus x using listplot.

I cannot figure it out.
 
To be honest, in a way I think you are torturing the Mathematica code. By that I mean that I think you may be reading the documentation and trying to interpret it in a way to get where you want to go, but I think you are using it in a rather unconventional way. That is often a recipe for problems.

For example, rarely do you see someone write "I have a Mathematica function of 2 variables f[x][y]. The untortured version of that would be f[x,y]. But perhaps you have good reasons, some or even lots of experience and understand the deep reasons why you are writing this the way you are.

You are also using vast deep nestlists and then discarding much of this. Are you sure you understand that nesting something 1000 levels deep may end up with thousand digit coefficients and polynomials to degrees in the thousands?

What do you REALLY want to accomplish? Forget Mathematica for a moment. What are you REALLY trying to get at? Maybe with that information it would be possible to do something much simpler to get you where you want to go.
 
Must have been a double mouse click, sorry.
 
It is also possible that the forum may go down for a little while about this time of night. If you don't get a quick reply please realize that might be the reason.
 
Yeah it wasn't working for a bit and i double posted as well. In answer to your question i am new to mathematica and am just practising working through different things. I am following what i see in the online tutorials for the most part.
 
  • #10
Ah... that explains some things.

If you can get your hands on them then there have been a variety of books published in the past that try to walk the reader through beginning to understand the mental model behind programming in Mathematica. It isn't impossible to learn this using only the help system, but I think that would be more difficult. "Mathematica Navigator" seems like a fairly good book for this. The older editions are for earlier versions of Mathematica and even the latest one hasn't caught up with the last features, but any edition might be a good introduction if you know just enough to watch out for small incompatibilities.
 

Similar threads

Replies
1
Views
2K
Replies
1
Views
2K
Replies
18
Views
4K
Replies
3
Views
2K
Replies
2
Views
3K
Replies
5
Views
2K
Replies
1
Views
3K
Back
Top