Esempio n. 1
0
 def test_testUfuncs1(self):
     # Test various functions such as sin, cos.
     (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d
     assert_(eq(np.cos(x), cos(xm)))
     assert_(eq(np.cosh(x), cosh(xm)))
     assert_(eq(np.sin(x), sin(xm)))
     assert_(eq(np.sinh(x), sinh(xm)))
     assert_(eq(np.tan(x), tan(xm)))
     assert_(eq(np.tanh(x), tanh(xm)))
     with np.errstate(divide='ignore', invalid='ignore'):
         assert_(eq(np.sqrt(abs(x)), sqrt(xm)))
         assert_(eq(np.log(abs(x)), log(xm)))
         assert_(eq(np.log10(abs(x)), log10(xm)))
     assert_(eq(np.exp(x), exp(xm)))
     assert_(eq(np.arcsin(z), arcsin(zm)))
     assert_(eq(np.arccos(z), arccos(zm)))
     assert_(eq(np.arctan(z), arctan(zm)))
     assert_(eq(np.arctan2(x, y), arctan2(xm, ym)))
     assert_(eq(np.absolute(x), absolute(xm)))
     assert_(eq(np.equal(x, y), equal(xm, ym)))
     assert_(eq(np.not_equal(x, y), not_equal(xm, ym)))
     assert_(eq(np.less(x, y), less(xm, ym)))
     assert_(eq(np.greater(x, y), greater(xm, ym)))
     assert_(eq(np.less_equal(x, y), less_equal(xm, ym)))
     assert_(eq(np.greater_equal(x, y), greater_equal(xm, ym)))
     assert_(eq(np.conjugate(x), conjugate(xm)))
     assert_(eq(np.concatenate((x, y)), concatenate((xm, ym))))
     assert_(eq(np.concatenate((x, y)), concatenate((x, y))))
     assert_(eq(np.concatenate((x, y)), concatenate((xm, y))))
     assert_(eq(np.concatenate((x, y, x)), concatenate((x, ym, x))))
Esempio n. 2
0
 def test_testUfuncs1(self):
     # Test various functions such as sin, cos.
     (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d
     assert_(eq(np.cos(x), cos(xm)))
     assert_(eq(np.cosh(x), cosh(xm)))
     assert_(eq(np.sin(x), sin(xm)))
     assert_(eq(np.sinh(x), sinh(xm)))
     assert_(eq(np.tan(x), tan(xm)))
     assert_(eq(np.tanh(x), tanh(xm)))
     with np.errstate(divide='ignore', invalid='ignore'):
         assert_(eq(np.sqrt(abs(x)), sqrt(xm)))
         assert_(eq(np.log(abs(x)), log(xm)))
         assert_(eq(np.log10(abs(x)), log10(xm)))
     assert_(eq(np.exp(x), exp(xm)))
     assert_(eq(np.arcsin(z), arcsin(zm)))
     assert_(eq(np.arccos(z), arccos(zm)))
     assert_(eq(np.arctan(z), arctan(zm)))
     assert_(eq(np.arctan2(x, y), arctan2(xm, ym)))
     assert_(eq(np.absolute(x), absolute(xm)))
     assert_(eq(np.equal(x, y), equal(xm, ym)))
     assert_(eq(np.not_equal(x, y), not_equal(xm, ym)))
     assert_(eq(np.less(x, y), less(xm, ym)))
     assert_(eq(np.greater(x, y), greater(xm, ym)))
     assert_(eq(np.less_equal(x, y), less_equal(xm, ym)))
     assert_(eq(np.greater_equal(x, y), greater_equal(xm, ym)))
     assert_(eq(np.conjugate(x), conjugate(xm)))
     assert_(eq(np.concatenate((x, y)), concatenate((xm, ym))))
     assert_(eq(np.concatenate((x, y)), concatenate((x, y))))
     assert_(eq(np.concatenate((x, y)), concatenate((xm, y))))
     assert_(eq(np.concatenate((x, y, x)), concatenate((x, ym, x))))
Esempio n. 3
0
def cache_angles(tile_size=500):
    half_size = float(tile_size - 1) / 2

    get_zp = lambda x, y: arccos(1 / sqrt(x**2 + y**2 + 1))
    get_zm = lambda x, y: arccos(-1 / sqrt(x**2 + y**2 + 1))
    get_xypm = lambda x, y: arccos(y / sqrt(x**2 + y**2 + 1))
    get_phi = lambda x, y: arctan(float(y) / x)

    cache = {
        'zp': np.zeros((tile_size, tile_size, ), dtype=np.float),
        'zm': np.zeros((tile_size, tile_size, ), dtype=np.float),
        'xypm': np.zeros((tile_size, tile_size, ), dtype=np.float),
        'phi': np.zeros((tile_size, tile_size, ), dtype=np.float)
    }
    print 'Perform cache angles...'
    for tile_y in xrange(tile_size):
        y = float(tile_y) / half_size - 1
        for tile_x in xrange(tile_size):
            x = float(tile_x) / half_size - 1
            cache['zp'][tile_y, tile_x] = get_zp(x, y)
            cache['zm'][tile_y, tile_x] = get_zm(x, y)
            cache['xypm'][tile_y, tile_x] = get_xypm(x, y)
            if x != 0:
                cache['phi'][tile_y, tile_x] = get_phi(x, y)
            # print 'cache for: [{}, {}] -> [{},{}]'.format(tile_y, tile_x, y, x)
    return cache
Esempio n. 4
0
def para():
    import numpy as np
    import scipy as sp
    N = 10000000
    f = lambda x: arctan(x) / (x**2 + x * sin(x))  # 要求积分的函数
    f = sp.vectorize(f)
    xs = np.array([random() for _ in range(N)])  # 生成N个积分区间(0,1)的数据
    fs = f(xs)
    mean = fs.mean()
    print(mean)
    var = fs.var()
    print(var)
Esempio n. 5
0
def compute_pitch_and_inputs_flatness_simple(e_and_derivatives,
                                             lambda_and_derivatives):
    e = e_and_derivatives[0]
    de1 = e_and_derivatives[1]
    de2 = e_and_derivatives[2]
    de3 = e_and_derivatives[3]
    de4 = e_and_derivatives[4]

    l = lambda_and_derivatives[0]
    dl1 = lambda_and_derivatives[1]
    dl2 = lambda_and_derivatives[2]
    dl3 = lambda_and_derivatives[3]
    dl4 = lambda_and_derivatives[4]

    b = L3 * Jl * dl2
    c = L4 * cos(e)
    d = Je * de2 - L2 * cos(e)
    a = b * c / d

    db1 = L3 * Jl * dl3
    db2 = L3 * Jl * dl4
    dc1 = -L4 * sin(e) * de1
    dc2 = -L4 * (cos(e) * de1**2 + sin(e) * de2)
    dd1 = Je * de3 + L2 * sin(e) * de1
    dd2 = Je * de4 + L2 * (cos(e) * de1**2 + sin(e) * de2)
    f = db1 * c * d
    g = dc1 * d + c * dd1
    h = c * c * d * d
    da1 = (f - b * g) / h

    df1 = db2 * c * d + db1 * g
    dg1 = dc2 * d + 2 * dc1 * dd1 + c * dd2
    dh1 = 2 * c * dc1 * d**2 + 2 * c**2 * d * dd1
    da2 = ((df1 - (db1 * g + b * dg1)) * h - (f - b * g) * dh1) / h**2

    p = arctan(a)
    dp1 = da1 / (1 + a**2)
    dp2 = (da2 * (1 + a**2) - 2 * a * da1**2) / (1 + a**2)**2

    Vs = ((Jl * dl2 / (L4 * cos(e)))**2 +
          ((Je * de2 - L2 * cos(e)) / L3)**2)**(1 / 2)
    Vd = Jp * dp2 / L1

    Vf = (Vs + Vd) / 2
    Vb = (Vs - Vd) / 2

    return np.array([p, dp1, dp2]), np.array([Vf, Vb])
Esempio n. 6
0
 def calc_PA(self) :
     """Calculates the telescope PA. requires LST to be either a field or 
     previously calculated array
     Outputs an  array of PA values for each time in radians.
     This requires the fields Ra = 'CRVAL2', Dec = 'CRVAL3' and 'DATE-OBS'
     to be set.
     """
     
     self.PA = sp.zeros(self.dims[0])
     for ii in range(self.dims[0]) :
         RA = self.field['CRVAL2'][ii]
         DEC = self.field['CRVAL3'][ii]
         LST = utils.LSTatGBT(self.field['DATE-OBS'][ii])
         H = LST-RA
         Latit = 38.0+26.0/60
         tanPA = ma.sin(H*sp.pi/180)/(ma.cos(DEC*sp.pi/180)*ma.tan(Latit*sp.pi/180)-ma.sin(DEC*sp.pi/180)*ma.cos(H*sp.pi/180))
         self.PA[ii] = ma.arctan(tanPA)
Esempio n. 7
0
    def calc_PA(self):
        """Calculates the telescope PA. requires LST to be either a field or 
        previously calculated array
        Outputs an  array of PA values for each time in radians.
        This requires the fields Ra = 'CRVAL2', Dec = 'CRVAL3' and 'DATE-OBS'
        to be set.
        """

        self.PA = sp.zeros(self.dims[0])
        for ii in range(self.dims[0]):
            RA = self.field['CRVAL2'][ii]
            DEC = self.field['CRVAL3'][ii]
            LST = utils.LSTatGBT(self.field['DATE-OBS'][ii])
            H = LST - RA
            Latit = 38.0 + 26.0 / 60
            tanPA = ma.sin(H * sp.pi / 180) / (
                ma.cos(DEC * sp.pi / 180) * ma.tan(Latit * sp.pi / 180) -
                ma.sin(DEC * sp.pi / 180) * ma.cos(H * sp.pi / 180))
            self.PA[ii] = ma.arctan(tanPA)
import math

from numpy.ma import arctan

x = math.pi/3


def f(n):
    return (-1)**n * (math.pi/3)**(2*n+1) /(2*n+1)


def arctan_n_series(n):
    result = 0.0
    for i in range(n):
        result += f(i)
    return result


actual = arctan(x)

n_list = [3, 5, 10, 20]

print("n  arctan(pi/3)      actual        absolute error")

for i in n_list:
    temp_arctan = arctan_n_series(i)
    abs_error = abs(temp_arctan - actual)
    print(str(i) + " " + str(temp_arctan) + " " + str(actual) + " " + str(abs_error))
Esempio n. 9
0
            ┃      ☃      ┃
            ┃  ┳┛  ┗┳  ┃
            ┃      ┻      ┃
            ┗━┓      ┏━┛
                ┃      ┗━━━┓
                ┃  神兽保佑    ┣┓
                ┃ 永无BUG!   ┏┛
                ┗┓┓┏━┳┓┏┛
                  ┃┫┫  ┃┫┫
                  ┗┻┛  ┗┻┛
"""
from random import uniform
from numpy.ma import mean, arctan, sin, var

N = 10000
f = lambda x: arctan(x) / (x**2 + x * sin(x))  # 要求积分的函数
a, b = 0, 1  # 积分区间
xs = [uniform(a, b) for _ in range(N)]  # 从均匀分布uniform(a,answers)生成N个样本
mean = mean([f(x) for x in xs])  # 代入积分函数,用均值去近似期望,因为函数不收敛,所以这个值也不确定
print(mean)
print(var([f(x) for x in xs]))  # 由于函数不收敛,方差巨大


def para():
    import numpy as np
    import scipy as sp
    N = 10000000
    f = lambda x: arctan(x) / (x**2 + x * sin(x))  # 要求积分的函数
    f = sp.vectorize(f)
    xs = np.array([random() for _ in range(N)])  # 生成N个积分区间(0,1)的数据
    fs = f(xs)
Esempio n. 10
0
    def get_poles_analyze(self, poles):
        """
        definition for analyzing by graph poles:
        - regulation time
        - hesistation
        - overshoot
        - degree of attenuation
        :param poles: mean of poles transmission function
        :return:  keys for handle changing regulator quality
        """

        # ключи для оценки регулирования
        key_koleb = 0
        key_reg = 0
        key_per = 0

        degree_max = 0
        a = True
        counter = 1

        print("Полюса плоскости: ")
        for i in poles:
            if i.real >= 0:  # корень в левой полуплоскости
                a = False
            print("Полюс ", counter, " : ", i)
            counter += 1

        print("СИСТЕМА НЕ ПРОХОДИТ ПРОВЕРКУ ПО УСТОЙЧИВОСТИ!"
              if not a else "По критерию полюсов система устойчива")

        regulation_time = 1.0 / abs(max(poles.real))
        print("\nВремя регулирования: " + str(regulation_time))

        print("Полученная величина выше оптимальной области регулирования"
              if regulation_time > 17 else "Отлично")

        if regulation_time > 17:
            key_reg = -1

        for a in poles:
            degree = arctan(abs(a.imag) / abs(a.real))
            degree_max = (degree if (a.imag != 0) &
                          (degree_max < degree) else degree_max)

        print("*" * 20, "\n" "Колебательность составляет: " + str(degree_max))
        if degree_max >= 1.57:
            print("Колебательность выше оптимального диапазона")
            key_koleb = -1

        overshoot = exp(-pi / degree_max) * 100

        print("*" * 20, "\n" "Перерегулирование: " + str(overshoot) + " %")

        if overshoot > 27:
            print("Полученная величина выше оптимальной области регулирования")
            key_per = -1
        elif overshoot < 10:
            print("Полученная величина ниже оптимальной области регулирования")
            key_per = 1
        else:
            print("Отлично")

        degree_of_attenuation = 1 - exp(-2 * pi / degree_max)

        print("*" * 20, "\n"
              "Степень затухания: " + str(degree_of_attenuation))

        plt.title('Graph of poles')
        plt.plot()
        plt.show()

        return [key_koleb, key_reg, key_per]
Esempio n. 11
0
def compute_pitch_and_inputs_flatness_centripetal(eps_derivs, lamb_derivs):
    eps = eps_derivs[0]
    deps1 = eps_derivs[1]
    deps2 = eps_derivs[2]
    deps3 = eps_derivs[3]
    deps4 = eps_derivs[4]

    lamb = lamb_derivs[0]
    dlamb1 = lamb_derivs[1]
    dlamb2 = lamb_derivs[2]
    dlamb3 = lamb_derivs[3]
    dlamb4 = lamb_derivs[4]

    p_phi_1 = mc.m_h * mc.d_h**2 + mc.m_h * mc.l_p**2
    p_phi_2 = -mc.g * mc.d_h * mc.m_h
    p_eps_1 = mc.m_h * (mc.l_h**2 + mc.d_h**2) + mc.m_c * (mc.l_c**2 +
                                                           mc.d_c**2)
    p_eps_2 = mc.g * (mc.m_c * mc.d_c - mc.m_h * mc.d_h)
    p_eps_3 = mc.g * (mc.m_h * mc.l_h - mc.m_c * mc.l_c)
    p_lamb_1 = mc.m_h * (mc.l_h**2 + mc.l_p**2) + mc.m_c * mc.l_c**2

    A = p_eps_1 * deps2 + mc.mu_eps * deps1 + p_eps_2 * sin(
        eps) + p_eps_3 * cos(eps)
    B = p_lamb_1 * dlamb2 + mc.mu_lamb * dlamb1

    dA1 = p_eps_1 * deps3 + mc.mu_eps * deps2 + p_eps_2 * deps1 * cos(
        eps) - p_eps_3 * deps1 * sin(eps)
    dB1 = p_lamb_1 * dlamb3 + mc.mu_lamb * dlamb2

    dA2 = p_eps_1 * deps4 + mc.mu_eps * deps3 + p_eps_2 * (
        deps2 * cos(eps) - deps1**2 * sin(eps)) - p_eps_3 * (
            deps2 * sin(eps) + deps1**2 * cos(eps))
    dB2 = p_lamb_1 * dlamb4 + mc.mu_lamb * dlamb3

    D = dB1 * A * cos(eps) - B * (dA1 * cos(eps) - A * sin(eps) * deps1)
    E = (A * cos(eps))**2

    dD1 = dB2 * A * cos(eps) - B * (dA2 * cos(eps) -
                                    2 * dA1 * sin(eps) * deps1 - A *
                                    (deps2 * sin(eps) + deps1**2 * cos(eps)))
    dE1 = 2 * A * cos(eps) * (dA1 * cos(eps) - A * deps1 * sin(eps))

    C = B / (A * cos(eps))
    dC1 = D / E
    dC2 = (dD1 * E - D * dE1) / E**2

    phi = arctan(C)
    dphi1 = dC1 / (1 + C**2)
    dphi2 = (dC2 * (1 + C**2) - 2 * C * dC1**2) / (1 + C**2)**2

    Fs = 1 / mc.l_h * sqrt(A**2 + (B / cos(eps))**2)
    Fd = 1 / mc.l_p * (p_phi_1 * dphi2 + p_phi_2 * sin(phi) +
                       mc.mu_phi * dphi1)

    Ff = (Fs + Fd) / 2
    Fb = (Fs - Fd) / 2

    uf = Fr_inverse(Ff)
    ub = Fr_inverse(Fb)

    return np.array([phi, dphi1, dphi2]), np.array([uf, ub])