Пример #1
0
#! /usr/bin/env python

import openturns as ot

ref_values = [[1.0, 0.0], [0.0, 0.5]]

mats = [ot.Matrix(ref_values),
        ot.SquareMatrix(ref_values),
        ot.TriangularMatrix(ref_values),
        ot.SymmetricMatrix(ref_values),
        ot.CovarianceMatrix(ref_values),
        ot.CorrelationMatrix(ref_values)]
mats.extend([
    ot.ComplexMatrix(ref_values),
    ot.HermitianMatrix(ref_values),
    ot.TriangularComplexMatrix(ref_values),
    ot.SquareComplexMatrix(ref_values)])

for a in mats:

    # try conversion
    ref = ot.Matrix([[1.0, 0.0], [0.0, 0.5]])
    iname = a.__class__.__name__
    print('a=', a)

    # try scalar mul
    try:
        s = 5.
        ats = a * s
        print('a*s=', ats)
        sta = s * a
Пример #2
0
# %%
# Define the spectral function:
def s(f):
    if(f <= 5.0):
        return 1.0
    else:
        x = f - 5.0
        return m.exp(-2.0 * x * x)


# %%
# Create the collection of HermitianMatrix:
coll = ot.HermitianMatrixCollection()
for k in range(N):
    frequency = fgrid.getValue(k)
    matrix = ot.HermitianMatrix(1)
    matrix[0, 0] = s(frequency)
    coll.add(matrix)

# %%
# Create the spectral model:
spectralModel = ot.UserDefinedSpectralModel(fgrid, coll)

# Get the spectral density function computed at first frequency values
firstFrequency = fgrid.getStart()
frequencyStep = fgrid.getStep()
firstHermitian = spectralModel(firstFrequency)

# Get the spectral function at frequency + 0.3 * frequencyStep
spectralModel(frequency + 0.3 * frequencyStep)
Пример #3
0
print("with transpose, array", a0.transpose(), "=> ComplexMatrix", m0)

a0 = np.array(((1. + 3j, 2. - 5j), (3. + 7j, 4. - 9j)))
m0 = ot.SquareComplexMatrix(a0)
print("array", a0, "=> SquareComplexMatrix", m0)
a1 = np.array(m0)
print("SquareComplexMatrix", m0, "=> array", a1)

a0 = np.array(((1. + 3j, 0.), (3. + 7j, 4. - 9j)))
m0 = ot.TriangularComplexMatrix(a0)
print("array", a0, "=> TriangularComplexMatrix", m0)
a1 = np.array(m0)
print("TriangularComplexMatrix", m0, "=> array", a1)

a0 = np.array(((1. + 3j, 2. - 5j), (2. + 5j, 4. - 9j)))
m0 = ot.HermitianMatrix(a0)
print("array", a0, "=> HermitianMatrix", m0)
m0[1, 0] = 3.0 - 5j
a1 = np.array(m0)
print("HermitianMatrix", m0, "=> array", a1)

# check np.matrix / Matrix conversion
a0 = np.matrix(((1., 2.), (3., 4.), (5., 6.)))
m0 = ot.Matrix(a0)
print("matrix", a0, "=> Matrix", m0)
a1 = np.array(m0)
print("Matrix", m0, "=> matrix", a1)
m0 = ot.Matrix(a0.transpose())
print("with transpose, matrix", a0.transpose(), "=> Matrix", m0)

a0 = np.matrix(((1. + 3j, 2. - 5j, 3. + 7j), (4. - 9j, 5. + 11j, 6. - 13j)))