@@ -4,7 +4,7 @@ The circuit is a simple circuit that shows chaotic behaviour.
4
4
Except for a non-linear resistor every other component already is part of ` ModelingToolkitStandardLibrary.Electrical ` .
5
5
6
6
First we need to make some imports.
7
- ``` julia
7
+ ``` @example components
8
8
using ModelingToolkit
9
9
using ModelingToolkitStandardLibrary.Electrical
10
10
using ModelingToolkitStandardLibrary.Electrical: OnePort
@@ -27,7 +27,7 @@ equation
27
27
end NonlinearResistor;
28
28
```
29
29
this can almost be directly translate it to the syntax of ` ModelingToolkit ` .
30
- ``` julia
30
+ ``` @example components
31
31
@parameters t
32
32
33
33
function NonlinearResistor(;name, Ga, Gb, Ve)
@@ -45,6 +45,7 @@ function NonlinearResistor(;name, Ga, Gb, Ve)
45
45
]
46
46
extend(ODESystem(eqs, t, [], pars; name=name), oneport)
47
47
end
48
+ nothing # hide
48
49
```
49
50
50
51
### Explanation
@@ -74,7 +75,7 @@ extend(ODESystem(eqs, t, [], pars; name=name), oneport)
74
75
75
76
## Building the Model
76
77
The final model can now be created with the components from the library and the new custom component.
77
- ``` julia
78
+ ``` @example components
78
79
@named L = Inductor(L=18)
79
80
@named Ro = Resistor(R=12.5e-3)
80
81
@named G = Conductor(G=0.565)
@@ -99,24 +100,27 @@ connections = [
99
100
]
100
101
101
102
@named model = ODESystem(connections, t, systems=[L, Ro, G, C1, C2, Nr])
103
+ nothing # hide
102
104
```
103
105
104
106
## Simulating the Model
105
107
Now the model can be simulated.
106
108
First ` structural_simplify ` is called on the model and a ` ODEProblem ` is build from the result.
107
109
Since the initial voltage of the first capacitor was already specified via ` v_start ` , no initial condition is given and an empty pair is supplied.
108
- ``` julia
110
+ ``` @example components
109
111
sys = structural_simplify(model)
110
112
prob = ODEProblem(sys, Pair[], (0, 5e4), saveat=0.01)
111
113
sol = solve(prob, Rodas4())
112
114
113
115
Plots.plot(sol[C1.v], sol[C2.v], title="Chaotic Attractor", label="", ylabel="C1 Voltage in V", xlabel="C2 Voltage in V")
114
116
Plots.savefig("chua_phase_plane.png")
117
+ nothing # hide
115
118
116
119
Plots.plot(sol; vars=[C1.v, C2.v, L.i], labels=["C1 Voltage in V" "C1 Voltage in V" "Inductor Current in A"])
117
120
Plots.savefig("chua.png")
121
+ nothing # hide
118
122
```
119
123
120
- ![ Time series plot of C1.v, C2.v and L.i] ( https://user-images.githubusercontent.com/50108075/169712569-9ae5a074-ca1a-4801-b666-75a2f6e21bf5 .png)
124
+ ![ Time series plot of C1.v, C2.v and L.i] ( chua_phase_plane .png)
121
125
122
- ![ Phase plane plot of C1.v and C2.v] ( https://user-images.githubusercontent.com/50108075/169712578-b3f314f6-3310-4471-a31e-af7fac3c0fbc .png)
126
+ ![ Phase plane plot of C1.v and C2.v] ( chua .png)
0 commit comments