# Preface

Electrical circuits are built up of individual components, including three common passive elements---capacitor, resistor, and coil or inductor. Such a component can be characterized by the relationship between the current flowing through the device (I) and the electrical potential difference across the device (V). Current is the flow of electrical charge, so it is described by a derivative. Analysis of electrical circuits is based on accurate models for the relationship between voltage and current in the two-port models of the components of the system (some electrical circuit components have more than two ports, requiring more complex models). Modeling electric circuits is based on differential equations for currents and charges flowing between components. Therefore, it is important to plot basic electric components.

# Basic Components of Electric Circuit

The resistor element can be plotted with Mathematica as follows
sawline = Line[Table[{n/2, (-1)^n}, {n, 16}]]
sawgraph = Graphics[sawline]
The inductor:
coil = ParametricPlot[{t + 1.5*Sin[2*t], 1.5*Cos[2*t]}, {t, 0, 4*Pi}]

# Plotting Electric Circuits

We demonstrate one of the possible approaches for plotting electric circuits.
(*This line is to display the circuit that we will create:*)
display[Table[rcElement // at[{i, 0}], {i, 0, 17, 3}]]

(* The following line adds a connecting wire for a list of points within a framework defined by the Map. The Map is defined by the text and point list. The Text is defined by the Style. *)

connect[pointList_] := {Line[pointList], Map[Text[Style["", FontSize -> 18]] &, pointList[[{1, -1}]]]}

(*The following segment of code is to instantiate each of the elements that will be used in the circuit. If you wanted to include a
switch or any other new element, this would be the section to add it.*)

gap[l_: 1] := Line[l {{{0, 0}, {1/3, 0}}, {{2/3, 0}, {1, 0}}}]
resistor[l_: 1, n_: 3] := Line[Table[{i l/(4 n), 1/3 Sin[i Pi/2]}, {i, 0, 4 n}]]

coil[l_: 1, n_: 3] := Module[{
scale = l/(5/16 n + 1/2),
pts = {{0, 0}, {0, 1}, {1/2, 1}, {1/2, 0}, {1/2, -1}, {5/ 16, -1}, {5/16, 0}} },
Append[Table[BezierCurve[scale Map[{d 5/16, 0} + # &, pts]], {d, 0, n - 1}],
BezierCurve[scale Map[{5/16 n, 0} + # &, pts[[1 ;; 4]]]]]]

(*This portion of the code dictates the specifics of the display of the circuit. In particular, I have a grid with dotted lines.*)

capacitor[l_: 1] := {gap[l],
Line[l {{{1/3, -1}, {1/3, 1}}, {{2/3, -1}, {2/3, 1}}}]}

battery[l_: 1] := {gap[
l], {Rectangle[l {1/3, -(2/3)}, l {1/3 + 1/9, 2/3}],
Line[l {{2/3, -1}, {2/3, 1}}]}}

contact[l_: 1] := {gap[l],
Map[{EdgeForm[Directive[Thick, Black]], FaceForm[White],
Disk[#, l/30]} &, l {{1/3, 0}, {2/3, 0}}]}
Options[display] = {Frame -> True, FrameTicks -> None,
PlotRange -> All, GridLines -> Automatic,
GridLinesStyle -> Directive[Orange, Dashed],
AspectRatio -> Automatic};
display[d_, opts : OptionsPattern[]] :=
Graphics[Style[d, Thick],
Join[FilterRules[{opts}, Options[Graphics]], Options[display]]]

(*This line sets up the framework for adding components to the circuit at specific positions.*)

at[position_, angle_: 0][obj_] :=
GeometricTransformation[obj,
Composition[TranslationTransform[position],
RotationTransform[angle]]]

(*This generates the specific circuit, which all prior code was \
designed to allow us to do. This is the only part that needs to be \
changed to alter the circuit, providing no new unique elements need \

label[s_String, color_: RGBColor[.3, .5, .8]] :=
Text@Style[s, FontColor -> color, FontFamily -> "Geneva",
FontSize -> Large];
display[{
battery[] // at[{0, 0}, Pi/2],
connect[{{0, 1}, {0, 2}, {2, 2}}],
resistor[] // at[{2, 2}],
connect[{{3, 2}, {4, 2}, {4, 1}}],
coil[] // at[{4, 0}, Pi/2],
connect[{{4, 0}, {4, -1}, {3, -1}}],
capacitor[] // at[{2, -1}],
connect[{{2, -1}, {0, -1}, {0, 0}}]}]