0

I want to plot a diagram for parameter a. For each value of a, I wanna show the trajectory of the map after initial transient, and plot it on the y axis. In the example below I take 200 points in a (parameter that ranges from 1 to 4), run 1000 steps iterations for each a, and plot x after skipping 100 steps. In order to implement this I used two functions (iterate and logistic):

def logistic(x, a):
    return(a*x*(1 - x))
def iterate(f, x0, a, steps=1000):
    """x0: initial value
        a: parameter to f(x,a)"""
    x = np.zeros(steps+1)
    x[0] = x0
    for k in range(steps):
        x[k+1] = f(x[k], a)
    return(x)
n = 200 # points in a
a = np.arange(1,4,3/n)
s = 1000 # steps for each a
x = iterate(logistic, 100, a, 1000)
plt(x)

But I get the following error: ValueError: setting an array element with a sequence. Could anybody help?

EDIT

This is the diagram I want to obtain

enter image description here

StudentOIST
  • 189
  • 2
  • 7
  • 21

1 Answers1

0

Well, a is an array of 200 values. So it shouldn't surprise you that multiplying that by scalars gives a result with 200 values, which leads to trouble when trying to make the assignment.

J_H
  • 17,926
  • 4
  • 24
  • 44
  • So, what I am trying to do is plotting a diagram of trajectories. for each of the 200 values of the parameter 'a' I want to iterate x according to the logistic function for 1000 times. then extract the last 900 values of the iterated x and plot it against the parameter a. This should be repeated for each a from 1 to 4 (200 of them in total) – StudentOIST Oct 28 '17 at 08:18
  • I updated my question with an image of the diagram I am trying to obtain to make this clearer – StudentOIST Oct 28 '17 at 08:21