ElectricalEngineering.ElectricalEngineeringModule

ElectricalEngineering

This is a Julia package on electrical engineering based on Unitful and PyPlot. The package ElectricalEngineering.jl is tested with Julia 1.

Plotting

  • arrowaxes Creates a plot with a horizontal and a vertical axis instead of a frame

  • removeaxes Removes the axis of the actual plot

  • lengthdimension Draws length dimension with label based on rectangular x- and y-coordinates. The length dimension arrow can be shifted parallel to the specified coordinates by means the single parameter par. Additionally, auxiliary lines from the specified coordinates to the length dimension are drawn.

Complex Phasors

  • pol Creates a complex quantity with length r and angle phi

  • Creates a complex quantity with length 1 and angle phi

  • phasor Draws a phasor from a starting point origin and end point origin+c. The phasor consists of a shaft and an arrow head. Each phasor c is plotted as a relative quantity, i.e., c/ref is actually shown the plot figure. This concept of plotting a per unit phasor is used to be able to plot phasor with different quantities, e.g., voltage and current phasors. It is important that the variables c, origin and ref have the same units (defined through Unitful).

  • phasorsine Draws a phasor with magnitude between 0 and 1 on the left subplot of a figure and a sine diagram on the right subplot of the figure. Such graph is used in electrical engineering to explain the relationship between phasors and time domain wave forms.

  • angulardimension Draws an arrowed arc, intended to label the angle between phasors. The arc is drawn from angle phi1 (begin) to phi2 (end). The begin and end arrow shapes can be set. The arc can be labeled and optionally a dot maker can be used to indicate right angles (90°).

  • phasordimension Draws length dimension with label based on rectangular x- and y-coordinates. The length dimension arrow can be shifted parallel to the specified coordinates by means the single parameter par. Additionally, auxiliary lines from the specified coordinates to the length dimension are drawn.

Complex Circuit Calculations

  • Calculates the parallel connection of impedances. Optionally, the calculation can be performed using units from the module Unitful.

Input and Output

  • printuln Prints a real or complex variable in an optionally specified unit

  • usprint Returns a string containing the number with six digits plus unit without space in between, such that the string output can be copied and pasted.

  • save2fig Save the actual figure in the file formats png and pdf including subdirectories. These two graphics format are relevant when processing figures in LaTeX, LyX, LibreOffice or other word processors

  • save3fig Save the actual figure in the file formats png, eps and pdf including subdirectories. These three graphics format are relevant when processing figures in LaTeX and LyX

See also ? on

  • ElectricalEngineering.Gray

  • ElectricalEngineering.Tab20bc

Other Packages related with Electrical Engineering

  • CircuitComponentRounding.jl provides functions to round given values to the nearest standardized value for circuit components

  • Modia.jl is a package for modeling and simulation of multidomain engineering systems described by differential equations, algebraic equations, and (space-discretized) partial differential equations

ElectricalEngineering.:∥Method

Function call

∥(z...)

Type \parallel and hit the tab key to autocomplete the parallel symbol ∥

Description

This calculates the parallel connection of impedances. Optionally, the calculation can be performed using units from the module Unitful.

Important note: Use the operator in parentheses, since its precedence is equal to the (low) precedence of relation operators or use the function call with arguments to avoid miscalculations

The functions par and are redundant impementations.

Variables

z Vector of impedances

Examples

julia> using Unitful,Unitful.DefaultSymbols,ElectricalEngineering
julia> ∥(4,6)
2.4
julia> ∥(4Ω,6Ω)
2.4 Ω
julia> 2Ω+(4Ω∥6Ω) # Parentheses are ALWAYS required since
4.4 Ω
julia> 2Ω+4Ω∥6Ω # Is equal to (2Ω+4Ω)∥6Ω which is usually NOT intended
3.0 Ω
julia> (2.4Ω∥(4Ω∥6Ω))
1.2 Ω
julia> ∥(4Ω,6Ω,2.4Ω)
1.2 Ω

Type \Omega and hit the tab key to autocomplete the parallel symbol Ω

ElectricalEngineering.angulardimensionFunction

Function call

angulardimension(r = 1, phi1 = 0, phi2 = pi/2; origin = 0.0im,
    label= "", labelphisep = 0.5, labelrsep = 0.1,
    labelrelrot = false, labelrelangle = 0, ha = "center", va = "center",
    color="black", backgroundcolor="none",
    arrowstyle1 = ".", arrowstyle2 = "-|>", dot90 = false,
    linewidth = 0.6, linestyle = "-", width = 0.2,
    headlength = 5, headwidth = 2.5)

Description

This function draws an arrowed arc, intended to label the angle between phasors. The arc is drawn from angle phi1 (begin) to phi2 (end). The begin and end arrow shapes can be set. The arc can be labeled and optionally a dot maker can be used to indicate right angles (90°).

Variables

r Radius if the arc with not unit; shall be between 0 and 1; default value = 1

phi1 Phase angle of the begin of the arc; default value = 0

phi2 Phase angle of the end of the arc; default value = pi/2

origin Complex quantity, indicating the origin of the arc with no unit; default value = 0.0 + 0.0im

label Label of the angle; default value =""

labelphisep Angular separation of the label with respect to the arc; if labelphisep == 0, the label is located at angle phi1 and if labelphisep == 1, the label is located at angle phi2; default value = 0.5, right in the middle between phi1 and phi2

labelrsepRadial per unit location of label (in direction of the phasor):labelrsep = 0` locates the label right on the arc. A positive value locates the label outside the arc, a negative value locates the label inside the arc; default value = 0.1

labelrelrot Relative rotation of label; if labelrelrot == false (default value) then the label is not rotated relative to the center of the arc; otherwise the label is rotated relative to the angle labelrelangle

labelrelangle Relative angle of label with respect to center of the arc; this angle is only applied, it labelrelrot == true; this angle indicates the relative orientation of the label with respect to the center of the arc; default value = 0

ha Horizontal alignment of label; actually represents the radial alignment of the label; default value = "center"

va Vertical alignment of label; actually represents the tangential alignment of the label; default value = "center"

color Color of the arc; default value = "black"

backgroundcolor Background color of the label; if labelrsep is equal to 0, the background color "white" can be used; default value = "none"

arrowstyle1 Arrow style of the begin of the arc; default value = "."; valid strings are:

  • . dot marker
  • <|- arrow

arrowstyle2 Arrow style of the end of the arc; default value = "-|>"; valid strings are:

  • . dot marker
  • -|> arrow

headlength Length of arrow head; default value = 5

headwidth Width of arrow head; default value = 2.5

Example

Copy and paste code:

using Unitful, Unitful.DefaultSymbols, PyPlot, ElectricalEngineering
figure(figsize=(3.3, 2.5))
rc("text", usetex=true); rc("font", family="serif")
V1 = 100V + j*0V # Voltage
Z1 = 30Ω + j*40Ω # Impedance
I1 = V1/Z1 # Current
Vr = real(Z1)*I1
Vx = V1 - Vr
refV = abs(V1); refI=abs(I1)*0.8
phasor(V1, label=L"$\underline{V}_1$", labeltsep=0.1, ref=refV,
    labelrelrot=true)
phasor(Vr, label=L"$\underline{V}_r$", labeltsep=-0.25, ref=refV,
    labelrelrot=true)
phasor(Vx, origin=Vr, label=L"$\underline{V}_x$", labeltsep=-0.2, ref=refV,
    labelrelrot=true)
phasor(I1, label=L"$\underline{I}_1$", labeltsep=-0.2, labelrsep=0.7, ref=refI,
    labelrelrot=true, linestyle="--", par=-0.05)
phi1=angle(I1)
phi2=angle(V1)
angulardimension(0.3,phi1,phi2,arrowstyle1=".",arrowstyle2="-|>",ha="left",
    label=L"$\varphi_1$", labelrsep=0.05)
axis("square"); xlim(-1,1); ylim(-1,1)
removeaxes(); # Remove axis
# save3fig("phasordiagram",crop=true);
ElectricalEngineering.arrowaxesFunction

Function call

arrowaxes(fig=gcf(), ax=gca(); xmin, xmax, ymin, ymax,
    xa=0, ya=0, xlabel="", ylabel="",
    xneg = false, yneg = false,
    color="black", backgroundcolor="none", axisoverhang = 0.18,
    linewidth = 0.75, headwidth = 0.06, headlength = 0.09, overhang = 0.1,
    labelsep = 0.06, left=0.2, right=0.85, bottom=0.20, top=0.85)

Description

Creates a plot with a horizontal and a vertical axis instead of a frame.

Variables

fig Figure handle; by default the figure handle of a actual figure is used

xmin Minimum of horizontal axis; default value = actual scaling

xmax Maximum of horizontal axis; default value = actual scaling

ymin Minimum of vertical axis; default value = actual scaling

ymax Maximum of vertical axis; default value = actual scaling

ax Axes handle; by default the axes handle of a actual figure is used

xa Horizontal location of the vertical axis; default value = 0

ya Vertical location of the horizontal axis; default value = 0

xlabel Label of x-axis; default value = ""

ylabel Label of y-axis; default value = ""

xneg If true, the horizontal arrow is drawn from right to left; default value = false

yneg If true, the vertical arrow is drawn from top to bottom; default value = false

color Color of the axes; default value = "black"

backgroundcolor Background color of the label; if labelrsep is equal to 0, the background color "white" can be used; default value = "none"

axisoverhang Overhang of the axis, relative to plot area; default value = 0.18 (18% of plot width)

linewidth Line width of the axes; default value = 0.75

headwidth Width of head, relative to plot area; default value = 0.045 (4.5% of horizontal plot width)

headlength Length of head, relative to plot area; default value = 0.07 (7% of horizontal plot width)

overhang Overhang of arrow head; default value = 0.0

labelsep Location of labels from axis, relative to plot area; default value = 0.05 (5% of plot width)

left Left side of the figure; default value = 0.2

right Right side of the figure; default value = 0.85

bottom Bottom side of the figure; default value = 0.2

top Top side of the figure; default value = 0.85

Examples

Copy and paste the following code:

using Unitful,Unitful.DefaultSymbols,ElectricalEngineering,PyPlot
figure(figsize=(3.3, 2.5))
rc("text", usetex=true); rc("font", family="serif")
x=collect(0.0:0.1:5.0); y=exp.(sin.(x));
plot(x,y,color=colorBlack1, linewidth=lineWidth1, linestyle=lineStyle1)
xlim(0,5); ylim(0,3); arrowaxes(xlabel=L"$x$",ylabel=L"$y$")
# save3fig("arrowaxes", crop=true)
ElectricalEngineering.lengthdimensionFunction

Function call

lengthdimension(x1=0, y1=0, x2=1, y2=1;
    label = "", labeltsep = 0.1, labelrsep=0.5, labelrelrot=false,
    labelrelangle=0, ha = "center", va = "center",
    color="black", backgroundcolor = "none",
    arrowstyle1 = "<|-", arrowstyle2 = "-|>", linewidth=0.6, linestyle = "-",
    width=0.2, headlength=5, headwidth=2.5,
    par=0, paroverhang = 0.02, parcolor = "black",
    parlinewidth=0.6, parlinestyle = "-")

Description

This function draws length dimension with label based on rectangular x- and y-coordinates. The length dimension arrow can be shifted parallel to the specified coordinates by means the single parameter par. Additionally, auxiliary lines from the specified coordinates to the length dimension are drawn.

Variables

x1 x-component of the begin of the length dimension; default value = 0

y1 y-component of the begin of the length dimension; default value = 0

x2 x-component of the end of the length dimension; default value = 1

y2 y-component of the end of the length dimension; default value = 1

label Label of the angle; default value =""

labelphisep Angular separation of the label with respect to the arc; if labelphisep == 0, the label is located at angle phi1 and if labelphisep == 1, the label is located at angle phi2; default value = 0.5, right in the middle between phi1 and phi2

labelrsepRadial per unit location of label (in direction of the phasor):labelrsep = 0` locates the label right on the arc. A positive value locates the label outside the arc, a negative value locates the label inside the arc; default value = 0.1

labelrelrot Relative rotation of label; if labelrelrot == false (default value) then the label is not rotated relative to the center of the arc; otherwise the label is rotated relative to the angle labelrelangle

labelrelangle Relative angle of label with respect to center of the arc; this angle is only applied, it labelrelrot == true; this angle indicates the relative orientation of the label with respect to the center of the arc; default value = 0

ha Horizontal alignment of label; actually represents the radial alignment of the label; default value = "center"

va Vertical alignment of label; actually represents the tangential alignment of the label; default value = "center"

color Color of the arc; default value = "black"

backgroundcolor Background color of the label; if labelrsep is equal to 0, the background color "white" can be used; default value = "none"

arrowstyle1 Arrow style of the begin of the arc; default value = "."; valid strings are:

  • . dot marker
  • <|- arrow

arrowstyle2 Arrow style of the end of the arc; default value = "-|>"; valid strings are:

  • . dot marker
  • -|> arrow

headlength Length of arrow head; default value = 5

headwidth Width of arrow head; default value = 2.5

par In order to be able to draw the length dimension parallel to the specified coordiantes x1, y1, x2, y2, par is used to specify the per unit tangential shift (offset) of the length dimension; default value = 0 (no shift)

paroverhang The auxiliary lines, drawn in case of par != 0, show the absolute overhang paroverhang; default value = 0.02

parcolor Color of the auxiliary lines; default value = "black"

parlinewidth Line width of the auxiliary line; default value = 0.6

parlinestyle Line style of the auxiliary line; default value = "-"

Example

Copy and paste code:

using Unitful, Unitful.DefaultSymbols, PyPlot, ElectricalEngineering
figure(figsize=(3.3, 2.5))
rc("text", usetex=true); rc("font", family="serif")
t1=0.2;t2=0.3;ymax=1
t=[0,t1,t1+t2,2*t1+t2,2*(t1+t2),3*t1+2*t2]
y=[0,ymax,0,ymax,0,ymax]
step(t,y,linewidth=1,color="black")
grid(true); xlim(0,1), ylim(-0.1,1.3);
xlabel(L"$t$\,(s)"); ylabel(L"$y$")
lengthdimension(0,0.2,t1,0.2,label=L"$t_1$",labeltsep=0,backgroundcolor="white")
lengthdimension(t1,0.2,t1+t2,0.2,label=L"$t_2$",labeltsep=0,backgroundcolor="white")
lengthdimension(t1,ymax,2*t1+t2,ymax,label=L"$T$",par=0.1,labeltsep=0.05,labelrsep=0.7)
# save3fig("lengthdimension",crop=true)
ElectricalEngineering.parMethod

Function call

par(z...)

Description

This calculates the parallel connection of impedances. Optionally, the calculation can be performed using units from the module Unitful.

The functions par and are redundant impementations.

Variables

z Vector of impedances

Examples

julia> using Unitful,Unitful.DefaultSymbols,ElectricalEngineering
julia> par(4,6)
2.4
julia> par(4Ω,6Ω)
2.4 Ω

Type \Omega and hit the tab key to autocomplete the parallel symbol Ω

ElectricalEngineering.phasorMethod

Function call

phasor(c;origin=0.0+0.0im, ref=1, par=0,
    labelrsep=0.5, labeltsep=0.1, label="", ha="center", va="center",
    labelrelrot=false, labelrelangle=0,
    color="black", backgroundcolor="none", linesstyle="-", linewidth=1,
    width=0.2, headlength=10, headwidth=5)

Description

This function draws a phasor from a starting point origin and end point origin+c. The phasor consists of a shaft and an arrow head.

Each phasor c is plotted as a relative quantity, i.e., c/ref is actually shown the plot figure. This concept of plotting a per unit phasor is used to be able to plot phasor with different quantities, e.g., voltage and current phasors. It is important that the variables c, origin and ref have the same units (defined through Unitful).

Variables

c Complex phasor, drawn relative relative to origin

origin Complex number representing the origin of the phasor; this variable needs to have the same unit as c

ref Reference length of scaling; this is required as in a phasor diagram voltages and currents may be included; in order to account for the different voltage and current scales, one (constant) ref is used for voltage phasors and another (constant) ref is used for current phasors; this variable needs to have the same unit as c

par In order to be able to plot parallel phasors, par is used to specify the per unit tangential shift (offset) of a phasor, with respect to ref; so typically ref will be selected to be around 0.05 to 0.1; default value = 0 (no shift of phasor)

labelrsep Radial per unit location of label (in direction of the phasor): labelrsep = 0 represents the shaft of the phasor and labelrsep = 1 represents the arrow hear of the phasor; default value = 0.5, i.e., the radial center of the phasor

labeltsep Tangential per unit location of label: labeltsep = 0 means that the label is plotted onto the phasor; labeltsep = 0.1 plots the label on top of the phasor applying a displacement of 10% with respect to ref; labeltsep = -0.2 Plots the label below the phasor applying a displacement of 20% with respect to ref; default value = 0.1

ha Horizontal alignment of label; actually represents the tangential alignment of the label; default value = "center"

va Vertical alignment of label; actually represents the radial alignment of the label; default value = "center"

labelrelrot Relative rotation of label; if labelrelrot == false (default value) then the label is not rotated relative to the orientation of the phasor; otherwise the label is rotated relative to the phasor by the angle labelrelangle

labelrelangle Relative angle of label with respect to phasor orientation; this angle is only applied, it labelrelrot == true; this angle the indicates the relative orientation of the label with respect to the orientation of the phasor; default value = 0

color Color of the phasor; i.e., shaft and arrow head color; default value = "black"

backgroundcolor Background color of the label; if labelrsep is equal to 0, the background color "white" can be used; default value = "none"

linestyle Line style of the phasor; default value = "-"

linewidth Line width of the phasor; default value = 1

width Line width of the shaft line; default value = 0.2

headlength Length of arrow head; default value = 10

headwidth Width of arrow head; default value = 5

Example

Copy and paste code:

using Unitful, Unitful.DefaultSymbols, PyPlot, ElectricalEngineering
figure(figsize=(3.3, 2.5))
rc("text", usetex=true); rc("font", family="serif")
V1 = 100V + j*0V # Voltage
Z1 = 30Ω + j*40Ω # Impedance
I1 = V1/Z1 # Current
Vr = real(Z1)*I1
Vx = V1 - Vr
refV = abs(V1); refI=abs(I1)*0.8
phasor(V1, label=L"$\underline{V}_1$", labeltsep=0.1, ref=refV,
    labelrelrot=true)
phasor(Vr, label=L"$\underline{V}_r$", labeltsep=-0.25, ref=refV,
    labelrelrot=true)
phasor(Vx, origin=Vr, label=L"$\underline{V}_x$", labeltsep=-0.2, ref=refV,
    labelrelrot=true)
phasor(I1, label=L"$\underline{I}_1$", labeltsep=-0.2, labelrsep=0.7, ref=refI,
    labelrelrot=true, linestyle="--", par=-0.05)
phi1=angle(I1)
phi2=angle(V1)
angulardimension(0.3,phi1,phi2,arrowstyle1=".",arrowstyle2="-|>",ha="left",
    label=L"$\varphi_1$", labelrsep=0.05)
axis("square"); xlim(-1,1); ylim(-1,1)
removeaxes(); # Remove axis
# save3fig("phasordiagram",crop=true);
ElectricalEngineering.phasordimensionMethod

Function call

phasordimension(c; origin = 0im, ref = 1;
    label = "", labeltsep = 0.1, labelrsep=0.5, labelrelrot=false,
    labelrelangle=0, ha = "center", va = "center",
    color="black", backgroundcolor = "none",
    arrowstyle1 = "<|-", arrowstyle2 = "-|>", linewidth=0.6, linestyle = "-",
    width=0.2, headlength=5, headwidth=2.5,
    par=0, paroverhang = 0.02, parcolor = "black",
    parlinewidth=0.6, parlinestyle = "-")

Description

This function draws length dimension with label based on rectangular x- and y-coordinates. The length dimension arrow can be shifted parallel to the specified coordinates by means the single parameter par. Additionally, auxiliary lines from the specified coordinates to the length dimension are drawn.

Variables

c Complex phasor to be dimensioned

origin Complex number representing the origin of the phasor dimension; this variable needs to have the same unit as c

ref Reference length of scaling; this is required as in a phasor diagram voltages and currents may be included; in order to account for the different voltage and current scales, one (constant) ref is used for voltage phasors and another (constant) ref is used for current phasors; this variable needs to have the same unit as c

label Label of the angle; default value =""

labelphisep Angular separation of the label with respect to the arc; if labelphisep == 0, the label is located at angle phi1 and if labelphisep == 1, the label is located at angle phi2; default value = 0.5, right in the middle between phi1 and phi2

labelrsepRadial per unit location of label (in direction of the phasor):labelrsep = 0` locates the label right on the arc. A positive value locates the label outside the arc, a negative value locates the label inside the arc; default value = 0.1

labelrelrot Relative rotation of label; if labelrelrot == false (default value) then the label is not rotated relative to the center of the arc; otherwise the label is rotated relative to the angle labelrelangle

labelrelangle Relative angle of label with respect to center of the arc; this angle is only applied, it labelrelrot == true; this angle indicates the relative orientation of the label with respect to the center of the arc; default value = 0

ha Horizontal alignment of label; actually represents the radial alignment of the label; default value = "center"

va Vertical alignment of label; actually represents the tangential alignment of the label; default value = "center"

color Color of the arc; default value = "black"

backgroundcolor Background color of the label; if labelrsep is equal to 0, the background color "white" can be used; default value = "none"

arrowstyle1 Arrow style of the begin of the arc; default value = "."; valid strings are:

  • . dot marker
  • <|- arrow

arrowstyle2 Arrow style of the end of the arc; default value = "-|>"; valid strings are:

  • . dot marker
  • -|> arrow

headlength Length of arrow head; default value = 5

headwidth Width of arrow head; default value = 2.5

par In order to be able to draw the length dimension parallel to the specified coordiantes x1, y1, x2, y2, par is used to specify the per unit tangential shift (offset) of the length dimension; default value = 0 (no shift)

paroverhang The auxiliary lines, drawn in case of par != 0, show the absolute overhang paroverhang; default value = 0.02

parcolor Color of the auxiliary lines; default value = "black"

parlinewidth Line width of the auxiliary line; default value = 0.6

parlinestyle Line style of the auxiliary line; default value = "-"

Examples

Copy and paste the following code:

using Unitful, Unitful.DefaultSymbols, PyPlot, ElectricalEngineering
figure(figsize=(3.3, 2.5))
rc("text", usetex=true); rc("font", family="serif")
Z1 = pol(1,30°)
phasor(Z1, label=L"$\underline{Z}$", labeltsep = 0.05, labelrelrot=true)
phasordimension(real(Z1), label=L"$R$", arrowstyle1="",
    linestyle="-", linewidth=1, headwidth=5, headlength=10,
    labeltsep=0, color="gray", backgroundcolor="white")
    phasordimension(j*imag(Z1), origin=real(Z1), label=L"j$\cdot X$",
    arrowstyle1="", linestyle="-", linewidth=1, headwidth=5, headlength=10,
    labeltsep=0, color="gray", backgroundcolor="white")
arrowaxes(xmin = real(Z1)+0.1, xlabel="Re", ylabel=L"j$\cdot$Im")
xlim([-0.5,1]);ylim([-0.5,1]); axis("square"); removeaxes();
# save3fig("phasordimension", crop=true)
ElectricalEngineering.phasorsineFunction

Function call

phasorsine(mag = 1, phi = 0; add = false, figsize = (6.6,2.5),
    xlabel = L"$\omega t$\,($^\circ $)", ylabel = "", maglabel = "",
    phasorlabel = maglabel, labeltsep = 0.1, labelrsep = 0.5,
    labelrelrot = true, labelrelangle = 0,
    color = "black", linewidth = 1, linestyle = "-",
    colorDash="gray", left=0.20, right=0.80, bottom=0.20, top=0.80,
    showsine=true, showdashline=true)

Description

This function draws a phasor with magnitude between 0 and 1 on the left subplot of a figure and a sine diagram on the right subplot of the figure. Such graph is used in electrical engineering to explain the relationship between phasors and time domain wave forms.

Variables

mag Magnitude of displayed phasor; shall be between 0 and 1; default value = 1

phi Phase angle of the phasor; default value = 0

add When calling this function the first time, add shall be equal to false, which is the default value. In this case a new figure with the dimensions specified in figsize is created. In order to add a second phasor and sine diagram to an existing figure, add has to be set true

figsize Size of the new figure, if add is equal to false; default value = (6.6,2.5)

xlabel Label of x-axis of right subplot; default value ="ωt(°)" in LaTeX notation

ylabel label of y-axis of right subplot; default value = ""; if more than one phasors and sine diagram shall be drawn (add = true), this label is displayed only once; therefore, one has to create the label of all phasors when function phasorsine is called the first time for creating a figure

maglabel Label of positive and negative magnitude mag on the right subplot; dafault value = "";

phasorlabel Label of phasor of left subplot; default value = maglabel

labelrsep Radial per unit location of label (in direction of the phasor): labelrsep = 0 represents the shaft of the phasor and labelrsep = 1 represents the arrow hear of the phasor; default value = 0.5, i.e., the radial center of the phasor

labeltsep Tangential per unit location of label: labeltsep = 0 means that the label is plotted onto the phasor; labeltsep = 0.1 plots the label on top of the phasor applying a displacement of 10% with respect to ref; labeltsep = -0.2 Plots the label below the phasor applying a displacement of 20% with respect to ref; default value = 0.1

labelrelrot Relative rotation of label; if labelrelrot == false (default value) then the label is not rotated relative to the orientation of the phasor; otherwise the label is rotated relative to the phasor by the angle labelrelangle

labelrelangle Relative angle of label with respect to phasor orientation; this angle is only applied, it labelrelrot == true; this angle the indicates the relative orientation of the label with respect to the orientation of the phasor; default value = 0

color Color of the phasor; i.e., shaft and arrow head color; default value = "black"

backgroundcolor Background color of all labels; if labelrsep is equal to 0, the background color "white" can be used; default value = "none"

linewidth Line width of the phasor; default value = 1

linestyle Line style of the phasor; default value = "-"

colorDash Color of the dashed circle (left subplot) and the horizontal dashed lines between the left and right subplot; default value = colorBlack4

left Left side of the figure; default value = 0.2

right Right side of the figure; default value = 0.85

bottom Bottom side of the figure; default value = 0.2

top Top side of the figure; default value = 0.85

showsine If true, the sinewave is shown; default value = true

showdashline If true, the dashed lines are shown; default value = true

Example

Copy and paste code:

using Unitful, Unitful.DefaultSymbols, PyPlot, ElectricalEngineering
rc("text", usetex=true); rc("font", family="serif")
phasorsine(1, 45°, ylabel=L"$u,i$", maglabel=L"$\hat{U}$", labelrsep=0.3,
    color="gray", linestyle="--")
phasorsine(0.55, 0, add=true, maglabel=L"$\hat{I}$")
# save3fig("phasorsine",crop=true);
ElectricalEngineering.polMethod

Function call

pol(r, phi)

Description

Creates a complex quantity with length r and angle phi

Variables

r Length of complex quantity; r may be utilized including a unit generated by Unitful

phi Angle of complex quantity; if module Unitful is utilized, the angle may be specified in degrees, by using unit °

Examples

julia> using Unitful, Unitful.DefaultSymbols, ElectricalEngineering
julia> U1 = pol(2V,pi)
-2 + 0im V
julia> U2 = pol(sqrt(2)*1V,45°)
1 + 1im V
ElectricalEngineering.printulnMethod

Function call

printuln(r...; label="")

Description

This function prints a real or complex variable in an optionally specified unit

Variables

r[1] Text string to printed, indicating the variable name or description; a maximum of 16 characters is allowed, in case the optional variable label is NOT specified; in case of specifying the variable label, the maximum length of r[1] may not exceed 12 characters

r[2] Variable to be printed; the variable may be real or complex, units assigned from the module Unitful are allowed; vectors of variables are also allowed

r[3] Optional target unit of r[2] to be displayed

label Optional four character label structuring the output of variables, e.g., label = "(a)"

Examples

julia> using Unitful, Unitful.DefaultSymbols, ElectricalEngineering
julia> U1 = 300V+j*400V
julia> printuln("U1", U1, kV)
              U1 = 0.3 kV + j 0.4 kV
                 = 0.5 kV ∠ 53.1301°
julia> printuln("real(U1)", real(U1), kV)
        real(U1) = 0.3 kV
julia> printuln("U1", U1, V, label="(a)")
(a)           U1 = 300 V + j 400 V
                 = 500 V ∠ 53.1301°
ElectricalEngineering.removeaxesFunction

Function call

removeaxes(ax=gca())

Description

Removes the axis of the actual plot

Variables

ax Axes handle; by default the axes handle of a actual figure is used

ElectricalEngineering.save2figFunction

Function call

save2fig(fileName, subDir="."; dpi=300, tight=true, crop=false)

Description

Save the actual figure in the following three file formats

  • png Portable network graphics in subdirectory png/
  • pdf Encapsulated postscript in subdirectory pdf/

These two graphics format are relevant when processing figures in LaTeX, LyX, LibreOffice or other word processors

Variables

fileName String of the filename, extended by .png, and .pdf; the file names are stored in sub directories png/, and pdf/

subDir String of sub directory in which the adjacent sub directories png/, and pdf/ are located; default = . (local work directory)

dpi Resolution of the stored PNG file; default = 300 (dpi)

tight Additional margin around the figure is removed, except for a 2% margin; default = true

crop Crop all 'white' space around the figure; this feature requires the installation of the following software

  • imagemagick to be applied to png files, see https://www.imagemagick.org/script/index.php on Windows or apply sudo apt install imagemagick on Linux (Mint or Ubuntu)
  • pdfcrop to be applied to pdf files, see https://www.ctan.org/pkg/pdfcrop on Windows or apply sudo apt install texlive-extra-utils on Linux (Mint or Ubuntu)

Examples

julia> save2fig("phasordiagram")
julia> save2fig("phasordiagram_crop", crop=true)
ElectricalEngineering.save3figFunction

Function call

save3fig(fileName, subDir="."; dpi=300, tight=true, crop=false)

Description

Save the actual figure in the following three file formats

  • png Portable network graphics in subdirectory png/
  • eps Encapsulated postscript in subdirectory eps/
  • pdf Encapsulated postscript in subdirectory pdf/

These three graphics format are relevant when processing figures in LaTeX, LyX, LibreOffice or other word processors

Variables

fileName String of the filename, extended by .png, .eps and .pdf; the file names are stored in sub directories png/, eps/ and pdf/

subDir String of sub directory in which the adjacent sub directories png/, eps/ and pdf/ are located; default = . (local work directory)

dpi Resolution of the stored PNG file; default = 300 (dpi)

tight Additional margin around the figure is removed, except for a 2% margin; default = true

crop Crop all 'white' space around the figure; this feature requires the installation of the following software

  • imagemagick to be applied to png files, see https://www.imagemagick.org/script/index.php on Windows or apply sudo apt install imagemagick on Linux (Mint or Ubuntu)
  • epstool to be applied to eps files, see http://pages.cs.wisc.edu/~ghost/gsview/epstool.htm on Windows or apply sudo apt install epstool on Linux (Mint or Ubuntu)
  • pdfcrop to be applied to pdf files, see https://www.ctan.org/pkg/pdfcrop on Windows or apply sudo apt install texlive-extra-utils on Linux (Mint or Ubuntu)

Examples

julia> save3fig("phasordiagram")
julia> save3fig("phasordiagram_crop", crop=true)
ElectricalEngineering.upstripFunction

Function call

upstrip(u, U)

Description

Returns the number of any physical quantity u. If the optional unit U is not specified the quantity is converted to its coherent (preferred) unit before determining the number.

Variables

u Variable to be processed

U Optional target unit; if not provided, the quantity is converted to its coherent (preferred) unit before determining the number.

Examples

```julia julia> I1 = 1.0mA julia> upstrip(I1) 0.001 julia> usprint(I1, mA) 1.0

ElectricalEngineering.usprintFunction

Function call

usprint(u,U)

Description

Returns a string containing the number with six digits plus unit without space in between, such that the string output can be copied and pasted.

Variables

u Variable to be processed

U Optional target unit; if not provided, the actual unit is used

Examples

```julia julia> I1 = 1mA julia> usprint(I1) 1mA julia> usprint(I1, A) 0.001A

ElectricalEngineering.winding_mmfMethod

Function call

mmfwinding(w, i)

Description

Calculates the magnetomotive force distribution based on the winding layout and the actual currents of polyphase winding

Input variable

w[:,:] Winding array with equal number of windings per slot, where

  • size(w,1) = number of layers, e.g. 1 or 2
  • size(w,2) = number of slots

i[:] Actual phase currents for, e.g., the three phases, scaled to 1

Output variables

mmf[:,:] Magnetomotive force, where

  • size(mmf,1) = number phases
  • size(mmm,1) = number of slots
ElectricalEngineering.∠Method

Function call

∠(phi)

Description

Creates a complex quantity with length 1 and angle phi

Variables

phi Angle of complex quantity; if module Unitful is utilized, the angle may be specified in degrees, by using unit °

Examples

julia> using Unitful, Unitful.DefaultSymbols, ElectricalEngineering
julia> U1 = 2V*∠(90°)
-0.0 + 2.0im V