matlab - Python plotting data generated from for loop inside for loop -


I am trying to change this code from Matlab to Python:

  x (1) = 0.1; J = 0; Z = 2.8: 0.0011: 3. Calculation for 9J = J + 1% zz (j) = z; For N = 1: 200x (n + 1) = z * x (n) * (1 - x (n)); Xn (n, j) = x (n); End end H = plot (zz, xn (100: 200, :), 'r'); Set (h, 'markersize', 3);  

And so far I have found this:

  NMP import as import matplotlib.pyplot as PLT x = [] x.append ( 0.1) xn = [] j = 0 z_range = np.arange (2.8, 3.9, 0.0011) n_range = category (0,200,1) in zz: z_range: j = j + 1 print j # n The calculation progresses in N_range: w = zz * x [n] * (1.0-x [n]) x.append (zz * x [n] * (1.0-x [n])) xn.append ( W) x = np. Array (x) xn = np.array (xn) xn_matrix = xn.reshape ((z_range.size, len (n_range))) xn_mat = xn_matrix.T. For plt.figure () # I z_range: # plt.plot (Z_range, xn_mat [0: i], 'r.') Plt.show ()  

I'm not sure That it is the best way to convert from Math to Python to loop, and I think there are problems in plotting the result: I x (n + 1) = z * x (n) * (1 - X (n)); and xn (n, j) = x (n); Lines in Matlab are annoying me, so can someone please explain if there is any more effective method of writing in Python?

  NMP import as import matplotlib.pyplot as plt x = 0.1 # preallocate Xn xn = np.zeros ([1001, 200]) #linspace is better for a non-integer phase zz = np. Lynxpace (2.8, 3.9, 1001) # Used instead of calculating iterations for J, calculation (zz): for print (j) for n in the category (200): using the same old values ​​of # x The use of the footage is unnecessary xn [j, n], x = x, z * x * (1 - x) plt.plot (zz, xn [:,, 100:], 'r.') Plt.show ()  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -