pymor.models.transfer_function¶
Module Contents¶
- class pymor.models.transfer_function.FactorizedTransferFunction(dim_input, dim_output, K, B, C, D, dK=None, dB=None, dC=None, dD=None, parameters={}, sampling_time=0, name=None)[source]¶
Bases:
TransferFunctionTransfer functions in generalized coprime factor form.
This class describes input-output systems given by a transfer function of the form \(H(s, \mu) = \mathcal{C}(s, \mu) \mathcal{K}(s, \mu)^{-1} \mathcal{B}(s, \mu) + \mathcal{D}(s, \mu)\).
- Parameters:
dim_input – The number of inputs.
dim_output – The number of outputs.
K – Functions that take
sand return anOperator.B – Functions that take
sand return anOperator.C – Functions that take
sand return anOperator.D – Functions that take
sand return anOperator.dK – Functions that take
sand return anOperatorthat is the derivative of K, B, C, D (optional).dB – Functions that take
sand return anOperatorthat is the derivative of K, B, C, D (optional).dC – Functions that take
sand return anOperatorthat is the derivative of K, B, C, D (optional).dD – Functions that take
sand return anOperatorthat is the derivative of K, B, C, D (optional).parameters – The
Parametersof the transfer function.sampling_time –
0if the system is continuous-time, otherwise a positive number that denotes the sampling time (in seconds).name – Name of the system.
- class pymor.models.transfer_function.TransferFunction(dim_input, dim_output, tf, dtf=None, parameters={}, sampling_time=0, presets=None, name=None)[source]¶
Bases:
pymor.core.cache.CacheableObject,pymor.parameters.base.ParametricObjectClass for systems represented by a transfer function.
This class describes input-output systems given by a (parametrized) transfer function \(H(s, \mu)\).
- Parameters:
dim_input – The number of inputs.
dim_output – The number of outputs.
tf – The transfer function H, given by a callable that takes a complex value
sand, if parametric, aparameter valuemu. The result oftf(s, mu)is aNumPy arrayof shape(dim_output, dim_input).dtf – The complex derivative of
Hwith respect tos(optional).parameters – The
Parametersof the transfer function.sampling_time –
0if the system is continuous-time, otherwise a positive number that denotes the sampling time (in seconds).presets – A
dictof preset attributes orNone. The dict must only contain keys that correspond to attributes ofTransferFunctionsuch ash2_norm.name – Name of the system.
Methods
Compute magnitudes and phases.
Draw the Bode plot for all input-output pairs.
Evaluate the derivative of the transfer function.
Evaluate the transfer function.
Evaluate the transfer function on the imaginary axis.
Compute H2 inner product with an
LTIModel.Compute the H2-norm using quadrature.
Draw the magnitude plot.
- bode(w, mu=None, adaptive_opts=None)[source]¶
Compute magnitudes and phases.
- Parameters:
w – If
len(w) == 2, the left and right limits used for the adaptive sampling. Otherwise, a sequence of angular frequencies at which to compute the transfer function.mu –
Parameter valuesfor which to evaluate the transfer function.adaptive_opts – Optional arguments for
adaptive(ignored iflen(w) != 2).
- Returns:
w – A sequence of angular frequencies at which the transfer function was computed (returned if
len(w) == 2).mag – Transfer function magnitudes at frequencies in
w,NumPy arrayof shape(len(w), self.dim_output, self.dim_input).phase – Transfer function phases (in radians) at frequencies in
w,NumPy arrayof shape(len(w), self.dim_output, self.dim_input).
- bode_plot(w, mu=None, ax=None, Hz=False, dB=False, deg=True, adaptive_opts=None, input_indices=None, output_indices=None, **mpl_kwargs)[source]¶
Draw the Bode plot for all input-output pairs.
- Parameters:
w – If
len(w) == 2, the left and right limits used for the adaptive sampling. Otherwise, a sequence of angular frequencies at which to compute the transfer function.mu –
Parameter valuesfor which to evaluate the transfer function.ax – Axis of shape (2 *
self.dim_output,self.dim_input) to which to plot. If not given,matplotlib.pyplot.gcfis used to get the figure and create axis.Hz – Should the frequency be in Hz on the plot.
dB – Should the magnitude be in dB on the plot.
deg – Should the phase be in degrees (otherwise in radians).
adaptive_opts – Optional arguments for
adaptive(ignored iflen(w) != 2).input_indices – Optional argument to select specific inputs to be paired with all outputs or selected ones. If
None, all inputs are used for plotting, otherwise, aniterablecontaining the indices of the selected inputs has to be passed. The order of the plots depends on the order of the indices in theiterable. It is possible to pass negative indices to access the inputs counting backwards.output_indices – Optional argument to select specific outputs to be paired with all inputs or selected ones. If
None, all outputs are used for plotting, otherwise, aniterablecontaining the indices of the selected outputs has to be passed. The order of the plots depends on the order of the indices in theiterable. It is possible to pass negative indices to access the outputs counting backwards.mpl_kwargs – Keyword arguments used in the matplotlib plot function.
- Returns:
artists – List of matplotlib artists added.
- eval_dtf(s, mu=None)[source]¶
Evaluate the derivative of the transfer function.
- Parameters:
s – Laplace variable as a complex number.
mu –
Parameter values.
- Returns:
Transfer function value as a 2D |NumPy array|.
- eval_tf(s, mu=None)[source]¶
Evaluate the transfer function.
- Parameters:
s – Laplace variable as a complex number.
mu –
Parameter values.
- Returns:
Transfer function value as a 2D |NumPy array|.
- freq_resp(w, mu=None, adaptive_type='bode', adaptive_opts=None)[source]¶
Evaluate the transfer function on the imaginary axis.
- Parameters:
w – If
len(w) == 2, the left and right limits used for the adaptive sampling. Otherwise, a sequence of angular frequencies at which to compute the transfer function.mu –
Parameter valuesfor which to evaluate the transfer function.adaptive_type – The plot type that adaptive sampling should be used for (
'bode','mag'). Ignored iflen(w) != 2.adaptive_opts – Optional arguments for
adaptive(ignored iflen(w) != 2). Ifxscaleandyscaleare not set,'log'is used.
- Returns:
w – A sequence of angular frequencies at which the transfer function was computed (returned if
len(w) == 2).tfw – Transfer function values at frequencies in
w,NumPy arrayof shape(len(w), self.dim_output, self.dim_input).
- h2_inner(lti, mu=None)[source]¶
Compute H2 inner product with an
LTIModel.Uses the inner product formula based on the pole-residue form (see, e.g., Lemma 1 in [ABG10]). It assumes that
self.tfis defined on-lti.poles().- Parameters:
lti –
LTIModelconsisting ofOperatorsthat can be converted toNumPy arrays. The D operator is ignored.mu –
Parameter values.
- Returns:
inner – H2 inner product.
- h2_norm(return_norm_only=True, mu=None, **quad_kwargs)[source]¶
Compute the H2-norm using quadrature.
This method uses
scipy.integrate.quadand makes no assumptions on the form of the transfer function. It only assumes thatself.tfis defined over the imaginary axis.By default, the absolute error tolerance in
scipy.integrate.quadis set to zero (see its optional argumentepsabs). It can be changed by using theepsabskeyword argument.- Parameters:
return_norm_only – Whether to only return the approximate H2-norm.
mu –
Parameter values.quad_kwargs – Keyword arguments passed to
scipy.integrate.quad.
- Returns:
norm – Computed H2-norm.
norm_relerr – Relative error estimate (returned if
return_norm_onlyisFalseandpresetsdoes not contain'h2_norm').info – Quadrature info (returned if
return_norm_onlyisFalseandfull_outputisTrueandpresetsdoes not contain'h2_norm'). Seescipy.integrate.quaddocumentation for more details.
- mag_plot(w, mu=None, ax=None, ord=None, Hz=False, dB=False, adaptive_opts=None, **mpl_kwargs)[source]¶
Draw the magnitude plot.
- Parameters:
w – If
len(w) == 2, the left and right limits used for the adaptive sampling. Otherwise, a sequence of angular frequencies at which to compute the transfer function.mu –
Parameter valuesfor which to evaluate the transfer function.ax – Axis to which to plot. If not given,
matplotlib.pyplot.gcais used.ord – The order of the norm used to compute the magnitude (the default is the Frobenius norm).
Hz – Should the frequency be in Hz on the plot.
dB – Should the magnitude be in dB on the plot.
adaptive_opts – Optional arguments for
adaptive(ignored iflen(w) != 2).mpl_kwargs – Keyword arguments used in the matplotlib plot function.
- Returns:
out – List of matplotlib artists added.