产生逻辑图的分叉图,包括不稳定点

问题描述 投票:0回答:0
典型分叉图仅包含稳定的固定点,这些点很有吸引力(附近的点在迭代时被拉到固定点)。这些非常容易计算:只需迭代一遍次,它会收敛到固定点。 但是,我试图包括不稳定的(排斥)固定点。从本质上讲,不会使用上述算法找到它们。 我的想法是松开要固定点的条件。也就是说,如果您的x值在f(x)的“ epsilon”之内,则只需返回x即可。这不会产生所需的输出。 我在下面包含了我的代码。任何想法或反馈都将不胜感激! 谢谢

import numpy as np from matplotlib import pyplot as plt # Define the logistic map epsilon = 1e-4 def lmap(x, r): # "Beefing up" the fixed point: # if x is in the epsilon neighbourhood of f(x), let it be a fixed point (return x) if abs(r * x * (1 - x) - x) < epsilon: return x else: return r * x * (1 - x) # Iterate over the logistic map to find fixed points def get_fixed_pts(f, x0, r, iterations = 100, keep = 10, decimals = 5): x = x0 for i in range(iterations): x = f(x, r) if i >= (iterations - keep): yield np.round(x, decimals) # Setting up some params x0 = 0.5 n_pts = 1000 r_lims = [2, 4] fixed_points = [] corresponding_r_values = [] # Looping over r values to find the fixed point for every r value for r in np.linspace(*r_lims, n_pts): # Get the fixed points and remove duplicates. # Then, find the cycle size (number of fixed points) pts = set(get_fixed_pts(lmap, x0, r)) cycle_size = len(pts) # Store values fixed_points.extend(pts) corresponding_r_values.extend([r] * cycle_size) # Plot all found points plt.figure(figsize=(16, 9)) plt.scatter(corresponding_r_values, fixed_points, s = 0.01, c = 'black', label = 'Stable fixed point') plt.title('Bifurcation diagram of logistic map') plt.xlabel('Parameter Value') plt.ylabel('Fixed Points') plt.xlim(r_lims) plt.legend() plt.show()

要用不稳定的固定点生成逻辑图的分叉图,您可以通过分析计算固定点,因为不稳定点驱动轨迹。

使用f(x)= r * x *(1 -x)查找固定点x = 0和x =(r -1)/r,

并将它们分类为稳定| f'(x)|

1使用衍生f'(x)= r *(1-2x)

import numpy as np import matplotlib.pyplot as plt def logistic_map(x, r): return r * x * (1 - x) def logistic_map_derivative(x, r): return r * (1 - 2 * x) def compute_fixed_points(r): if r < 1: return [0], [] stable = [] unstable = [] if abs(logistic_map_derivative(0, r)) < 1: stable.append(0) else: unstable.append(0) if r > 1: x_fixed = (r - 1) / r if abs(logistic_map_derivative(x_fixed, r)) < 1: stable.append(x_fixed) else: unstable.append(x_fixed) return stable, unstable # Iterate through the logistic map to compute periodic points def iterate_logistic_map(x0, r, iterations=500, discard=100): x = x0 trajectory = [] for i in range(iterations): x = logistic_map(x, r) if i >= discard: trajectory.append(x) return trajectory r_values = np.linspace(2, 4, 1000) x0 = 0.5 num_iterations = 500 discard = 100 stable_points = [] unstable_points = [] r_stable = [] r_unstable = [] for r in r_values: # Compute analytically derived fixed points stable, unstable = compute_fixed_points(r) stable_points.extend(stable) unstable_points.extend(unstable) r_stable.extend([r] * len(stable)) r_unstable.extend([r] * len(unstable)) # Iterate to find attracting fixed points trajectory = iterate_logistic_map(x0, r, iterations=num_iterations, discard=discard) r_stable.extend([r] * len(trajectory)) stable_points.extend(trajectory) plt.figure(figsize=(16, 9)) plt.scatter(r_stable, stable_points, s=0.5, c='black', label='Stable Points') plt.scatter(r_unstable, unstable_points, s=1, c='red', label='Unstable Points') plt.title('Bifurcation Diagram of Logistic Map (Stable and Unstable Points)') plt.xlabel('Parameter r') plt.ylabel('x') plt.legend(loc='upper left') plt.show()

	
python numerical-methods diagram
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.