Skip to content

Commit f1021de

Browse files
Merge pull request #361 from matthew-kapp/change-readme
Readme updated with new RC circuit example
2 parents 8a67616 + 91add5f commit f1021de

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

README.md

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,30 +50,34 @@ using ModelingToolkitStandardLibrary.Electrical
5050
using ModelingToolkitStandardLibrary.Blocks: Constant
5151
using ModelingToolkit: t_nounits as t
5252

53-
R = 1.0
54-
C = 1.0
55-
V = 1.0
56-
systems = @named begin
57-
resistor = Resistor(R = R)
58-
capacitor = Capacitor(C = C, v = 0.0)
59-
source = Voltage()
60-
constant = Constant(k = V)
61-
ground = Ground()
53+
@mtkmodel RC begin
54+
@parameters begin
55+
R = 1.0
56+
C = 1.0
57+
V = 1.0
58+
end
59+
@components begin
60+
resistor = Resistor(R = R)
61+
capacitor = Capacitor(C = C, v = 0.0)
62+
source = Voltage()
63+
constant = Constant(k = V)
64+
ground = Ground()
65+
end
66+
@equations begin
67+
connect(constant.output, source.V)
68+
connect(source.p, resistor.p)
69+
connect(resistor.n, capacitor.p)
70+
connect(capacitor.n, source.n, ground.g)
71+
end
6272
end
6373

64-
rc_eqs = [connect(constant.output, source.V)
65-
connect(source.p, resistor.p)
66-
connect(resistor.n, capacitor.p)
67-
connect(capacitor.n, source.n, ground.g)]
68-
69-
@named rc_model = ODESystem(rc_eqs, t; systems)
70-
sys = structural_simplify(rc_model)
74+
@mtkbuild sys = RC()
7175
prob = ODEProblem(sys, Pair[], (0, 10.0))
72-
sol = solve(prob, Tsit5())
73-
plot(sol, idxs = [capacitor.v, resistor.i],
76+
sol = solve(prob)
77+
78+
plot(sol, idxs = [sys.capacitor.v, sys.resistor.i],
7479
title = "RC Circuit Demonstration",
7580
labels = ["Capacitor Voltage" "Resistor Current"])
76-
savefig("plot.png")
7781
```
7882

7983
![](https://user-images.githubusercontent.com/1814174/164912983-c3f73628-0e19-4e42-b085-4f62ba6f23d1.png)

0 commit comments

Comments
 (0)