Julia electrical engineering package
View the Project on GitHub christiankral/ElectricalEngineering.jl
The Julia package Unitful provides units so that calculations can be performed with physical quantities instead of numbers only. The package can be installed with Pkg.add("Unitful"). The Unitiful homepage presents a documentation of the relevant functions in order to work with units.
In electrical engineering I recommend to load the Unitful package as well as the default units Unitful.DefaultSymbols, in addition to EE:
using Unitful,Unitful.DefaultSymbols,EE
Between number and quantity, no blank is allowed.
julia> V1=3.0V
3.0 V
julia> I1=1.0mA
1.0 mA
julia> R1=V1/I1
3.0 V mA^-1
In oder to get a formatted output with six significant digits and a selected unit, function printuln (provied by EE.jl) can be used:
julia> printuln("R1",R1,Ω)
R1 = 3000 Ω
Unitful functionuconvertConverts a quantity to a different unit within the same dimension.
julia> uconvert(mV,V1)
3000.0 mV
unitDetermine the used unit
julia> unit(V1)
V
julia> unit(I1)
mA
upreferredDetermine a quantify in coherent (preferred) units, i.e., the SI unit without prefix, except kg.
julia> upreferred(V1)
3.0 kg m^2 A^-1 s^-3
julia> upreferred(I1)
0.001 A
Additionally, this function can be used to determine coherent unit of a non-coherent unit.
julia> upreferred(mA)
A
ustripDetermine the number of physical quantity. It is important to note, that this does not automatically give the number in coherent SI units.
julia> ustrip(V1)
3.0
julia> ustrip(I1)
1.0
In order to get the number of the coherent SI quantity, use:
julia> ustrip(upreferred(I1))
0.001