Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Mathematica function help

  1. May 3, 2012 #1
    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 cant figure it out

    i have tried this far
    f:=x^7+k
    y:=Take[NestList[f, 0, 50], -10]
     
  2. jcsd
  3. May 3, 2012 #2
    In[1]:= f[x_]:=x^7+k;y=Take[NestList[f,x,50],-10]

    And then

    In[3]:= y/.k->0.5
     
  4. May 3, 2012 #3
    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?
     
  5. May 4, 2012 #4
    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)}
     
  6. May 4, 2012 #5
    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.
     
  7. May 4, 2012 #6
    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.
     
  8. May 4, 2012 #7
    Must have been a double mouse click, sorry.
     
  9. May 4, 2012 #8
    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.
     
  10. May 4, 2012 #9
    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.
     
  11. May 4, 2012 #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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Mathematica function help
  1. Mathematica functions (Replies: 1)

  2. Help in Mathematica (Replies: 15)

  3. Help with Mathematica? (Replies: 1)

Loading...