SLiCAPpythonMaxima.py

SLiCAP module with symbolic math functions executed by maxima CAS.

Imported by the module SLiCAPplots.py.

detFunc()
equateCoeffs(protoType, transfer, noSolve=[], numeric=True)

Returns the solutions of the equation transferFunction = protoTypeFunction.

Both transfer and prototype should be Laplace rational functions. Their numerators should be polynomials of the Laplace variable of equal order and their denominators should be polynomials of the Laplace variable of equal order. :note: if ini.maxSolve == True: Maxima CAS will be used as solver, else: sympy. :param protoType: Prototype rational expression of the Laplace variable :type protoType: sympy.Expr :param transfer:

Transfer fucntion of which the parameters need to be solved. The numerator and the denominator of this rational expression should be of the same order as those of the prototype.

Parameters:
  • noSolve (list) – List with variables (str, sympy.core.symbol.Symbol) that do not need to be solved. These parameters will remain symbolic in the solutions.
  • numeric (bool) – True will force Maxima to use (big) floats for numeric values.
Returns:

Dictionary with key-value pairs:

  • key: name of the parameter (sympy.core.symbol.Symbol)
  • value: solution of this parameter: (sympy.Expr, int, float)

Return type:

dict

maxCramerNumer(M, Iv, detP, detN, numeric=True)

Returns the numerator of the response at the detector as a result of excitations from one or more sources.

Calculation method:

  • numer = + determinant(subs(M, col(detP) = Iv)) - determinant(subs(M, col(detN) = Iv))

The subsititutions are made with Sympy. The determinants are calculated with Maxima CAS.

Parameters:
  • M (sympy.Matrix) – MNA matrix
  • Iv (sympy.Matrix) – Vector with independent variables
  • detP (int, bool) – Position of positive detector in vector with dependent variables. This can be a nodal voltage or a current through a voltage source or None if the positive node is the ground node or a positive current is not used.
  • detN (int, bool) – Position of positive detector in vector with dependent variables. This can be a nodal voltage or a current through a voltage source or None if the negative node is the ground node or a negative current is not used.
  • numeric (bool) – True will force Maxima to use (big) floats for numeric values.
Returns:

Numerator of a response

Return type:

sympy.Expr

maxDet(M, numeric=True)

Returns the determinant of matrix ‘M’ in Sympy format, calculated by Maxima CAS.

Calculation of the determinant according to the GENTLEMAN-JOHNSON TREE-MINOR method. This is a fast version of expansion by minors. It it implemented in Maxima CAS for matrices up to 50 x 50.

Parameters:
  • M (sympy.Matrix) – Matrix of which the determinant needs to be evaluated
  • numeric (bool) – True will force Maxima to use (big) floats for numeric values.
maxEval(maxExpr)

Evaluates the expression ‘maxExpr’ with Maxima CAS and returns the result.

Starts a subprocess that evaluates maxExpr with Maxima CAS and returns the resulting expression in text format. The variable that needs to be output must be named: ‘result’.

In some cases Maxima CAS will ask for extra input. This will be ignored and a time out will kill the subprocess.

Parameters:maxExpr (str) – Expression in Maxima format to be evaluated.
Returns:String that can be converted into a sympy expression.
Return type:str

Example:

>>> maxEval("result:ilt(1/(s^2 + a^2), s, t);")
'sin(a*t)/a'
maxILT(numer, denom, numeric=True)

Calculates the inverse Laplace transform of ‘Fs’ using Maxima CAS.

This function first tries to calculate the ILT symbolically, if this fails it tries to create a factorized rational expression of the Laplace variable ini.laplace and then calculates the ILT of this rational expression.

Parameters:numer (sympy.Expr) – Numarator of the Laplace Transform.

:param denom : Denominator of the Laplace Transform. :type denom: sympy.Expr

Parameters:numeric (bool) – True will force Maxima to use (big) floats for numeric values.
Returns:Sympy expression of the time function if the ILT succeeded, or sp.Symbol(‘ft’) if the ILT failed.
Example:
>>> maxILT(2, 3*ini.Laplace**2 + sp.Symbol('a')**2, numeric = False)
2*sqrt(3)*sin(sqrt(3)*a*t/3)/(3*a)
Example:
>>> maxILT(2, 3*ini.Laplace**2 + sp.Symbol('a')**2, numeric = True)
1.154700538379252*sin(0.5773502691896258*a*t)/a
maxIntegrate(expr, var, start=None, stop=None, numeric=True)

Calculated definite or indefinite integral of ‘expr’.

Parameters:
  • expr (sympy.Expr) – Integrand
  • var (sympy.Symbol, str) – Integration variable
  • start (Bool, int float, sympy.Expr) – Lower limit of the integral.
  • stop (Bool, int float, sympy.Expr) – Upper limit of the integral.
  • numeric (bool) – True will force Maxima to use (big) floats for numeric values.
Returns:

Integral

Return type:

sympy.Expr

maxLimit(expr, var, val, pm, numeric=True)

Calculates the limit of an expression for ‘var’ approaches ‘val’ from ‘pm’.

Parameters:
  • expr (sympy.Expr, str) – Expression of which the limit must be evaluated.
  • var (sympy.Symbol, str) – Variable that should approach the limit value.
  • val (sympy.Symbol, str, sp.Expr, int, float) – Limit value of the variable.
  • pm (str) – Direction: ‘plus’ or ‘minus’
  • numeric (bool) – True will force Maxima to use (big) floats for numeric values.
Returns:

Calculated limit

Return type:

sympy.Expr

maxNumer(M, detP, detN, srcP, srcN, numeric=True)

Returns the numerator of a transfer function.

Calculation method:

  • numer = + cofactor(srcP, detP) - cofactor(srcN, detP) - cofactor(srcP, detN) + cofactor(srcN, detN)
  • cofactor(i,j) = (-1)^(i+j)*det(minor(i,j))

The minor matrices and the multiplication factors are determined with Sympy, the determinants are calculated with Maxima.

Note:

In Sympy a minor is defined as the determinant of the minor matrix. Use sympy.Matrix.minor_submatrix to get the matrix only.

In Maxima a minor is the minor matrix itself.

Parameters:
  • M (sympy.Matrix) – MNA matrix
  • detP (int, bool) – Position of positive detector in vector with dependent variables. This can be a nodal voltage or a current through a voltage source or None if the positive node is the ground node or a positive current is not used.
  • detN (int, bool) – Position of positive detector in vector with dependent variables. This can be a nodal voltage or a current through a voltage source or None if the negative node is the ground node or a negative current is not used.
  • srcP (int, bool) –

    Current source: position of positive node in vector with dependent variables.

    Voltage source: position of current through this source in the vector with dependent variables.

  • srcN (int, bool) –

    Current source: position of positive node in vector with dependent variables.

    Voltage source: None

  • numeric (bool) – True will force Maxima to use (big) floats for numeric values.
Returns:

Numerator of a transfer function

Return type:

sympy.Expr

maxSolve(M, Iv, numeric=True)

Calculates M^(-1).Iv

Parameters:
  • M (sympy.Matrix) – MNA matrix
  • Iv (sympy.Matrix) – Vector with independent variables
  • numeric (bool) – True will force Maxima to use (big) floats for numeric values.
Returns:

Network solution.

Return type:

sympy.Matrix

rmsNoise(noiseResult, noise, fmin, fmax, source=None)

Calculates the RMS source-referred noise or detector-referred noise, or the contribution of a specific noise source to it.

Parameters:
  • noiseResult (SLiCAPprotos.allResults) – Results of the execution of an instruction with data type ‘noise’.
  • noise – ‘inoise’ or ‘onoise’ for source-referred noise or detector- referred noise, respectively.
  • fmin (str, int, float, sp.Symbol) – Lower limit of the frequency range in Hz.
  • fmax (str, int, float, sp.Symbol) – Upper limit of the frequency range in Hz.
  • source – ‘all’ or refDes (ID) of a noise source of which the contribution to the RMS noise needs to be evaluated. Only IDs of current of voltage sources with a nonzero value for ‘noise’ are accepted.
Returns:

RMS noise over the frequency interval.

  • An expression or value if parameter stepping of the instruction is disabled.
  • A list with expressions or values if parameter stepping of the instruction is enabled.

Return type:

int, float, sympy.Expr, list

sympy2maximaMatrix(M)

Converts a sympy matrix object into a Maxima matrix definition.

Parameters:M (symPy.Matrix) – sympy matrix
Returns:sympy matrix converted to a Maxima matrix
Return type:str