-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathDemo_Lienard.py
67 lines (49 loc) · 1.81 KB
/
Demo_Lienard.py
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
61
62
63
64
65
66
67
import time
import numpy as np
from VISolver.Domains.Lienard import Lienard
from VISolver.Solvers.Euler_LEGS import Euler_LEGS
from VISolver.Solvers.HeunEuler_LEGS import HeunEuler_LEGS
from VISolver.Solvers.CashKarp_LEGS import CashKarp_LEGS
from VISolver.Solver import Solve
from VISolver.Options import (
DescentOptions, Miscellaneous, Reporting, Termination, Initialization)
from VISolver.Log import PrintSimResults, PrintSimStats
from VISolver.Utilities import ListONP2NP
from matplotlib import pyplot as plt
def Demo():
#__LIENARD_SYSTEM__##################################################
# Define Network and Domain
Domain = Lienard()
# Set Method
Method = Euler_LEGS(Domain=Domain,FixStep=True,NTopLEs=2)
# Method = HeunEuler_LEGS(Domain=Domain,Delta0=1e-5,NTopLEs=2)
# Method = CashKarp_LEGS(Domain=Domain,Delta0=1e-5,NTopLEs=2)
# Initialize Starting Point
Start = np.array([1.5,0])
# Set Options
Init = Initialization(Step=1e-3)
Term = Termination(MaxIter=1e5,Tols=[(Domain.gap,1e-3)])
Repo = Reporting(Requests=['Step','Data','Lyapunov',Domain.gap])
Misc = Miscellaneous()
Options = DescentOptions(Init,Term,Repo,Misc)
# Print Stats
PrintSimStats(Domain,Method,Options)
# Start Solver
tic = time.time()
Lienard_Results = Solve(Start,Method,Domain,Options)
toc = time.time() - tic
# Print Results
PrintSimResults(Options,Lienard_Results,Method,toc)
# Plot Lyapunov Exponents
plt.plot(Lienard_Results.PermStorage['Lyapunov'])
plt.show()
# Plot System Trajectory
data = ListONP2NP(Lienard_Results.PermStorage['Data'])
plt.plot(data[:,0],data[:,1])
ax = plt.gca()
ax.set_xlim([-2.5,2.5])
ax.set_ylim([-2.5,2.5])
ax.set_aspect('equal')
plt.show()
if __name__ == '__main__':
Demo()