Vibration Systems (vibesystem)

class vibration_toolbox.vibesystem.VibeSystem(M, C, K, name='')[source]

A multiple degrees of freedom system.

This class will create a multiple degree of freedom system given M, C and K matrices.

Parameters
Marray

Mass matrix.

Carray

Damping matrix.

Karray

Stiffness matrix.

namestr, optional

Name of the system.

Examples

For a system consisting of two masses connected to each other and both connected to a wall we have the following matrices:

>>> m0, m1 = 1, 1
>>> c0, c1, c2 = 5, 5, 5
>>> k0, k1, k2 = 1e3, 1e3, 1e3
>>> M = np.array([[m0, 0],
...               [0, m1]])
>>> C = np.array([[c0+c1, -c2],
...               [-c1, c2+c2]])
>>> K = np.array([[k0+k1, -k2],
...               [-k1, k2+k2]])
>>> sys = VibeSystem(M, C, K)
>>> sys.wn  # doctest: +SKIP
array([31.62,  54.77])
>>> sys.wd  # doctest: +SKIP
array([31.52,  54.26])
Attributes
evaluesarray

System’s eigenvalues.

evectorsarray

System’s eigenvectors.

wnarray

System’s natural frequencies in rad/s.

wdarray

System’s damped natural frequencies in rad/s.

damping_ratioarray

System’s damping factor for each mode.

Hscipy.signal.lti

Continuous-time linear time invariant system

A(self)[source]

State space matrix

This method will return the state space matrix of the system.

Returns
Aarray

System’s state space matrix.

Examples

>>> m0, m1 = 1, 1
>>> c0, c1, c2 = 1, 1, 1
>>> k0, k1, k2 = 1e3, 1e3, 1e3
>>> M = np.array([[m0, 0],
...               [0, m1]])
>>> C = np.array([[c0+c1, -c2],
...               [-c1, c2+c2]])
>>> K = np.array([[k0+k1, -k2],
...               [-k1, k2+k2]])
>>> sys = VibeSystem(M, C, K) # create the system
>>> sys.A()
array([[    0.,     0.,     1.,     0.],
       [    0.,     0.,     0.,     1.],
       [-2000.,  1000.,    -2.,     1.],
       [ 1000., -2000.,     1.,    -2.]])
freq_response(self, F=None, omega=None, modes=None)[source]

Frequency response for a mdof system.

This method returns the frequency response for a mdof system given a range of frequencies, the force for each frequency and the modes that will be used.

Parameters
Farray, optional

Force array (needs to have the same length as time array). If not given the impulse response is calculated.

omegaarray, optional
Array with the desired range of frequencies (the default

is 0 to 1.5 x highest damped natural frequency.

modeslist, optional

Modes that will be used to calculate the frequency response (all modes will be used if a list is not given).

Returns
omegaarray

Array with the frequencies

magdbarray

Magnitude (dB) of the frequency response for each pair input/output. The order of the array is: [output, input, magnitude]

phasearray

Phase of the frequency response for each pair input/output. The order of the array is: [output, input, phase]

Examples

>>> m0, m1 = 1, 1
>>> c0, c1, c2 = 1, 1, 1
>>> k0, k1, k2 = 1e3, 1e3, 1e3
>>> M = np.array([[m0, 0],
...               [0, m1]])
>>> C = np.array([[c0+c1, -c2],
...               [-c1, c2+c2]])
>>> K = np.array([[k0+k1, -k2],
...               [-k1, k2+k2]])
>>> sys = VibeSystem(M, C, K) # create the system
>>> omega, magdb, phase = sys.freq_response()
>>> # magnitude for output on 0 and input on 1.
>>> magdb[0, 1, :4]
array([-69.54, -69.54, -69.54, -69.54])
>>> # phase for output on 1 and input on 1.
>>> phase[1, 1, :4]
array([...0.  , -0.  , -0.01, -0.01])
plot_freq_response(self, out, inp, modes=None, ax0=None, ax1=None, **kwargs)[source]

Plot frequency response.

This method plots the frequency response given an output and an input.

Parameters
outint

Output.

inputint

Input.

modeslist, optional

Modes that will be used to calculate the frequency response (all modes will be used if a list is not given).

ax0matplotlib.axes, optional

Matplotlib axes where the amplitude will be plotted. If None creates a new.

ax1matplotlib.axes, optional

Matplotlib axes where the phase will be plotted. If None creates a new.

kwargsoptional

Additional key word arguments can be passed to change the plot (e.g. linestyle=’–’)

Returns
ax0matplotlib.axes

Matplotlib axes with amplitude plot.

ax1matplotlib.axes

Matplotlib axes with phase plot.

Examples

>>> m0, m1 = 1, 1
>>> c0, c1, c2 = 1, 1, 1
>>> k0, k1, k2 = 1e3, 1e3, 1e3
>>> M = np.array([[m0, 0],
...               [0, m1]])
>>> C = np.array([[c0+c1, -c2],
...               [-c1, c2+c2]])
>>> K = np.array([[k0+k1, -k2],
...               [-k1, k2+k2]])
>>> sys = VibeSystem(M, C, K) # create the system
>>> # plot frequency response for input and output at m0
>>> sys.plot_freq_response(0, 0)
(<matplotlib.axes._...
plot_freq_response_grid(self, outs, inps, modes=None, ax=None)[source]

Plot frequency response.

This method plots the frequency response given an output and an input.

Parameters
outslist

List with the desired outputs.

inpslist

List with the desired outputs.

modeslist

List with the modes that will be used to construct the frequency response plot.

axarray with matplotlib.axes, optional

Matplotlib axes array created with plt.subplots. It needs to have a shape of (2*inputs, outputs).

Returns
axarray with matplotlib.axes, optional

Matplotlib axes array created with plt.subplots.

Examples

>>> m0, m1 = 1, 1
>>> c0, c1, c2 = 1, 1, 1
>>> k0, k1, k2 = 1e3, 1e3, 1e3
>>> M = np.array([[m0, 0],
...               [0, m1]])
>>> C = np.array([[c0+c1, -c2],
...               [-c1, c2+c2]])
>>> K = np.array([[k0+k1, -k2],
...               [-k1, k2+k2]])
>>> sys = VibeSystem(M, C, K) # create the system
>>> # plot frequency response for inputs at [0, 1]
>>> # and outputs at [0, 1]
>>> sys.plot_freq_response_grid(outs=[0, 1], inps=[0, 1])
array([[<matplotlib.axes._...
plot_time_response(self, F, t, ic=None, out=None, ax=None)[source]

Plot the time response for a mdof system.

This method returns the time response for a mdof system given a force, time and initial conditions.

Parameters
Farray

Force array (needs to have the same length as time array).

tarray

Time array.

icarray, optional

The initial conditions on the state vector (zero by default).

outlist

Desired output for which the time response will be plotted.

axarray with matplotlib.axes, optional

Matplotlib axes array created with plt.subplots. It needs to have a shape of (2*inputs, outputs).

Returns
axarray with matplotlib.axes, optional

Matplotlib axes array created with plt.subplots.

tarray

Time values for the output.

youtarray

System response.

xoutarray

Time evolution of the state vector.

Examples

>>> m0, m1 = 1, 1
>>> c0, c1, c2 = 1, 1, 1
>>> k0, k1, k2 = 1e3, 1e3, 1e3
>>> M = np.array([[m0, 0],
...               [0, m1]])
>>> C = np.array([[c0+c1, -c2],
...               [-c1, c2+c2]])
>>> K = np.array([[k0+k1, -k2],
...               [-k1, k2+k2]])
>>> sys = VibeSystem(M, C, K) # create the system
>>> t = np.linspace(0, 25, 1000) # time array
>>> F1 = np.zeros((len(t), 2))
>>> F1[:, 1] = 1000*np.sin(40*t) # force applied on m1
>>> sys.plot_time_response(F1, t)
array([<matplotlib.axes...
time_response(self, F, t, ic=None)[source]

Time response for a mdof system.

This method returns the time response for a mdof system given a force, time and initial conditions.

Parameters
Farray

Force array (needs to have the same length as time array).

tarray

Time array.

icarray, optional

The initial conditions on the state vector (zero by default).

Returns
tarray

Time values for the output.

youtarray

System response.

xoutarray

Time evolution of the state vector.

Examples

>>> m0, m1 = 1, 1
>>> c0, c1, c2 = 1, 1, 1
>>> k0, k1, k2 = 1e3, 1e3, 1e3
>>> M = np.array([[m0, 0],
...               [0, m1]])
>>> C = np.array([[c0+c1, -c2],
...               [-c1, c2+c2]])
>>> K = np.array([[k0+k1, -k2],
...               [-k1, k2+k2]])
>>> sys = VibeSystem(M, C, K) # create the system
>>> t = np.linspace(0, 25, 1000) # time array
>>> F1 = np.zeros((len(t), 2))
>>> F1[:, 1] = 1000*np.sin(40*t) # force applied on m1
>>> t, yout, xout = sys.time_response(F1, t)
>>> # response on m0
>>> yout[:5, 0] # doctest: +SKIP
array([0.  ,  0.  ,  0.07,  0.32,  0.61])
>>> # response on m1
>>> yout[:5, 1]  # doctest: +SKIP
array([0.  ,  0.08,  0.46,  0.79,  0.48])