-
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathexample_algebraicloop.py
More file actions
61 lines (43 loc) · 1.39 KB
/
example_algebraicloop.py
File metadata and controls
61 lines (43 loc) · 1.39 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
61
#########################################################################################
##
## PathSim example of an algebraic loop
##
#########################################################################################
# IMPORTS ===============================================================================
import numpy as np
import matplotlib.pyplot as plt
from pathsim import Simulation, Connection
from pathsim.blocks import (
Source,
Amplifier,
Adder,
Scope,
)
# ALGEBRAIC LOOP ========================================================================
#simulation timestep
dt = 0.1
#algebraic feedback
a = -0.2
#blocks that define the system
Src = Source(lambda t: 2*np.cos(t))
Amp = Amplifier(a)
Add = Adder()
Sco = Scope(labels=["src", "amp", "add"])
blocks = [Src, Amp, Add, Sco]
#the connections between the blocks
connections = [
Connection(Src, Add),
Connection(Add, Amp),
Connection(Amp, Add[1]),
Connection(Src, Sco),
Connection(Amp, Sco[1]),
Connection(Add, Sco[2])
]
#initialize simulation with the blocks, connections, timestep and logging enabled
Sim = Simulation(blocks, connections, dt=dt, log=True)
# Run Example ===========================================================================
if __name__ == "__main__":
#run the simulation for some time
Sim.run(5)
Sco.plot(".-")
plt.show()