Iterative Function with Last 10 Values for Any Input Constant K

  • Context: Mathematica 
  • Thread starter Thread starter peter.a
  • Start date Start date
  • Tags Tags
    Function Mathematica
Click For Summary

Discussion Overview

The discussion revolves around the iterative function defined as f(x) = x^7 + k, where participants explore how to iterate this function multiple times and store the last 10 values for various constants k. The conversation includes attempts to generalize the approach for different functions and the challenges faced in applying the code correctly in Mathematica.

Discussion Character

  • Exploratory
  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant describes the function f(x) = x^7 + k and seeks to iterate it 50 times starting from x0 = 1, aiming to store the last 10 values for different constants k.
  • Another participant provides a code snippet to implement the function and iterate it, substituting k with a specific value.
  • A request for clarification on how to apply the code to other functions is made, indicating difficulties encountered when trying to adapt the code.
  • A participant shares an example of a different function and its iteration, but does not receive a clear answer to their issues.
  • One participant expresses frustration with the complexity of their Mathematica code and suggests that the approach may be unconventional, questioning the necessity of deep nesting in the function calls.
  • Another participant mentions their inexperience with Mathematica and their reliance on online tutorials, indicating a desire to understand the programming model better.
  • Suggestions for resources, such as books on Mathematica, are offered to help improve understanding of the software.

Areas of Agreement / Disagreement

Participants express various challenges and uncertainties in applying the code correctly, with no consensus reached on the best approach to iterate different functions or on the effectiveness of the current methods discussed.

Contextual Notes

Some participants note issues with understanding the documentation and the implications of deep nesting in function calls, suggesting that the complexity may lead to difficulties in achieving their goals.

Who May Find This Useful

Individuals interested in iterative functions, programming in Mathematica, or those seeking to understand how to manipulate functions for different constants may find this discussion relevant.

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 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 18 ·
Replies
18
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K