Skip to content

Commit

Permalink
#47 Fixed sign error in Velocity
Browse files Browse the repository at this point in the history
  • Loading branch information
weka511 committed Dec 24, 2023
1 parent 785827f commit 5206a37
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions chaos_book/exercises/twomodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
def parse_args():
'''Define and parse command line arguments'''
parser = ArgumentParser(description=__doc__)
parser.add_argument('--T', type=float, default=10000)
parser.add_argument('--show', default=False, action='store_true', help='Show plots')
return parser.parse_args()

Expand All @@ -45,8 +46,8 @@ def Velocity(t,ssp):
r2 = x1**2 + y1**2
return np.array([
(mu1-r2)*x1 + c1*(x1*x2 + y1*y2),
(mu1-r2)*y1 + c1*(x1*y2 + x2*y1),
x2 + y2 + x1**2 - y1**2 +a2*x2* r2 ,
(mu1-r2)*y1 + c1*(x1*y2 - x2*y1),
x2 + y2 + x1**2 - y1**2 +a2*x2*r2 ,
-x2 + y2+ 2*x1*y1 + a2*y2*r2
])

Expand Down Expand Up @@ -75,27 +76,28 @@ def get_name_for_save(extra = None,

rng = np.random.default_rng()
ssp = rng.uniform(-1,1,4)
solution = solve_ivp(Velocity, (0,1000), ssp)
solution = solve_ivp(Velocity, (0,args.T), ssp)

fig = figure(figsize=(12,12))
ax1 = fig.add_subplot(1,1,1,projection='3d')
ax1.scatter(solution.y[0,:],solution.y[1,:],solution.y[2,:],
c = solution.y[3,:],
ax1.scatter(solution.y[0,:],solution.y[2,:],solution.y[3,:],
c = solution.y[1,:],
s = 1,
cmap = 'viridis',
label = 'Trajectory')
ax1.scatter(solution.y[0,0],solution.y[1,0],solution.y[2,0],
ax1.scatter(solution.y[0,0],solution.y[2,0],solution.y[3,0],
marker = 'X',
label = 'Start',
c = 'xkcd:red')
fig.colorbar(ScalarMappable(norm=Normalize(0, 1),
cmap = 'viridis'),
ax = ax1,
label = 'y2')
label = 'y1')
ax1.set_xlabel('x1')
ax1.set_ylabel('y1')
ax1.set_zlabel('x2')
ax1.set_ylabel('x2')
ax1.set_zlabel('y2')
ax1.legend()
ax1.set_title(f'Two Modes for T={args.T}')
fig.savefig(get_name_for_save())
elapsed = time() - start
minutes = int(elapsed/60)
Expand Down

0 comments on commit 5206a37

Please sign in to comment.