-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_drift_function.py
More file actions
60 lines (47 loc) · 1.9 KB
/
Copy pathplot_drift_function.py
File metadata and controls
60 lines (47 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import numpy as np
import matplotlib.pyplot as plt
def plot_drift_function():
"""
Plot the non-linear drift function: v = mu + t/(1.0 + t)
where mu = 0.5 and t ranges from 0 to 5
"""
# Parameters
mu = 0.5
t_start = 0.0
t_end = 5.0
n_steps = 1000
# Generate time points
t = np.linspace(t_start, t_end, n_steps)
# Calculate drift values
v = mu + t / (1.0 + t)
# Create the plot
plt.figure(figsize=(10, 6))
plt.plot(t, v, 'b-', linewidth=2, label=f'v = {mu} + t/(1.0 + t)')
# Add horizontal line for mu (asymptote)
plt.axhline(y=mu, color='r', linestyle='--', alpha=0.7, label=f'μ = {mu} (asymptote)')
# Add horizontal line for initial value
initial_v = mu + 0 / (1.0 + 0) # v at t=0
plt.axhline(y=initial_v, color='g', linestyle=':', alpha=0.7, label=f'Initial v = {initial_v}')
# Customize the plot
plt.xlabel('Time (t)', fontsize=12)
plt.ylabel('Drift Rate (v)', fontsize=12)
plt.title('Non-linear Drift Function: v = μ + t/(1.0 + t)', fontsize=14)
plt.grid(True, alpha=0.3)
plt.legend(fontsize=11)
# Set axis limits
plt.xlim(t_start, t_end)
plt.ylim(0, max(v) * 1.1)
# Add some annotations
plt.annotate(f'v(0) = {initial_v:.2f}', xy=(0, initial_v), xytext=(0.5, initial_v + 0.1),
arrowprops=dict(arrowstyle='->', color='green'), fontsize=10)
plt.annotate(f'v(5) = {v[-1]:.2f}', xy=(5, v[-1]), xytext=(3.5, v[-1] + 0.1),
arrowprops=dict(arrowstyle='->', color='blue'), fontsize=10)
plt.tight_layout()
plt.show()
# Print some key values
print(f"Initial drift rate (t=0): v = {v[0]:.4f}")
print(f"Final drift rate (t=5): v = {v[-1]:.4f}")
print(f"Change in drift rate: Δv = {v[-1] - v[0]:.4f}")
print(f"Asymptotic value (t→∞): v = {mu:.4f}")
if __name__ == "__main__":
plot_drift_function()