편집 기록

편집 기록
  • 프로필 nowp님의 편집
    날짜2021.02.01

    for 조건을 덧붙여서 행렬에 추가하는데, 0부터 시작하면 오류가 납니다. TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'


    import math
    import numpy as np
    import matplotlib.pyplot as plt
    
    def local_atmospheric_temperature(altitude):
    
        h = altitude
    
        if h > 0 and h <= 11000:
            h_b = 0.0
            T_b = 288.15
            L_b = -0.0065
            local_atmospheric_temperature = T_b + (L_b*(h-h_b))
    
            return local_atmospheric_temperature
    
        if h > 11000 and h <= 20000:
            h_b = 11000
            T_b = 216.65
            L_b = 0.0
            local_atmospheric_temperature = T_b + (L_b*(h-h_b))
    
            return local_atmospheric_temperature
    
        if h > 20000 and h <= 32000:
            h_b = 20000
            T_b = 216.65
            L_b = 0.001
            local_atmospheric_temperature = T_b + (L_b*(h-h_b))
            return local_atmospheric_temperature
    
        if h > 32000 and h <= 47000:
            h_b = 32000
            T_b = 228.65
            L_b = 0.0028
            local_atmospheric_temperature = T_b + (L_b*(h-h_b))
            return local_atmospheric_temperature
    
        if h > 47000 and h <= 51000:
            h_b = 47000
            T_b = 270.65
            L_b = 0.0
            local_atmospheric_temperature = T_b + (L_b*(h-h_b))
            return local_atmospheric_temperature
    
        if h > 51000 and h <= 71000:
            h_b = 51000
            T_b = 270.65
            L_b = -0.0028
            local_atmospheric_temperature = T_b + (L_b*(h-h_b))
            return local_atmospheric_temperature
    
        if h > 71000 and h <= 80000:
            h_b = 71000
            T_b = 214.65
            L_b = -0.002
            local_atmospheric_temperature = T_b + (L_b*(h-h_b))
            return local_atmospheric_temperature
    
    def local_atmospheric_density(altitude):
    
        h = altitude
    
        T_local = local_atmospheric_temperature(h)
    
        g_0 = 9.80665 #[m/s^2]
        m_M = 0.0289644 #[kg/mol]
        R_univ = 8.31432 #[J/mol*K]
    
        if h > 0 and h <= 11000:
            L_b = -0.0065
            T_b = 288.15
            rho_b = 1.2250
            local_atmospheric_density = rho_b * ((T_b/T_local)**(1+((g_0*m_M)/(R_univ*L_b))))
            return local_atmospheric_density
    
        if h > 11000 and h <= 20000:
            h_b = 11000
            L_b = 0.0
            T_b = 216.65
            rho_b = 0.36391
            local_atmospheric_density = rho_b * math.exp((-g_0*m_M*(h-h_b))/(R_univ*T_b))
            return local_atmospheric_density
    
        if h > 20000 and h <= 32000:
            L_b = 0.001
            T_b = 216.65
            rho_b = 0.08803
            local_atmospheric_density = rho_b * ((T_b/T_local)**(1+((g_0*m_M)/(R_univ*L_b))))
            return local_atmospheric_density
    
        if h > 32000 and h <= 47000:
            L_b = 0.0028
            T_b = 228.65
            rho_b = 0.01322
            local_atmospheric_density = rho_b * ((T_b/T_local)**(1+((g_0*m_M)/(R_univ*L_b))))
            return local_atmospheric_density
    
        if h > 47000 and h <= 51000:
            h_b = 47000
            L_b = 0.0
            T_b = 270.65
            rho_b = 0.00143
            local_atmospheric_density = rho_b * math.exp((-g_0*m_M*(h-h_b))/(R_univ*T_b))
            return local_atmospheric_density    
    
        if h > 51000 and h <= 71000:
            L_b = -0.0028
            T_b = 270.65
            rho_b = 0.00086
            local_atmospheric_density = rho_b * ((T_b/T_local)**(1+((g_0*m_M)/(R_univ*L_b))))
            return local_atmospheric_density
    
        if h > 71000 and h <= 80000:
            L_b = -0.002
            T_b = 214.65
            rho_b = 0.000064
            local_atmospheric_density = rho_b * ((T_b/T_local)**(1+((g_0*m_M)/(R_univ*L_b))))
            return local_atmospheric_density
    
    
    def local_atmospheric_pressure(altitude):
    
        h = altitude
        R_univ = 8.31432 #[J/mol*K]
        m_M = 0.0289644 #[kg/mol]
    
        local_atmospheric_pressure = ((local_atmospheric_density(h)* R_univ * local_atmospheric_temperature(h))/m_M)*10**(-5)
    
        return local_atmospheric_pressure
    
    N = 80000
    z = np.zeros((N,2))
    
    for h in range(0,80000,1):
    
        z[h,0] = h/1000
        z[h,1] = local_atmospheric_pressure(h)
        h+=1
    
    plt.title('Pressure at Different Altitudes',fontsize=12)
    plt.ylabel('Altitude in [km]',fontsize=10)
    plt.xlabel('Pressure in [bar]',fontsize=10)
    plt.axis([-0.1,1.1,-5,85])
    plt.plot(z[:,1],z[:,0],'b')
    plt.show()
    
    

    안녕하세요. 질문이 있습니다. for 문에서 0부터 시작하면 TypeError: unsupported operand type(s) for *: 'NoneType' and 'float' 이런 에러가 뜨고, 1부터 시작하면 문제없이 작동합니다.

    0부터 시작해야 그래프를 그릴때 문제가 없는데, 이걸 어떻게 해결해야할지 모르겠습니다. 도움 주실 수 있을까요?

    p.s. 제일 밑에 함수 pressure 부분을 빼고 altitude 함수까지만 해서 N부터 시작하는 for 구문을 넣으면 0부터 시작해도 잘 작동합니다.

  • 프로필 알 수 없는 사용자님의 편집
    날짜2021.02.01

    for 조건을 덧붙여서 행렬에 추가하는데, 0부터 시작하면 오류가 납니다.


    import math
    import numpy as np
    import matplotlib.pyplot as plt
    
    def local_atmospheric_temperature(altitude):
    
        h = altitude
    
        if h > 0 and h <= 11000:
            h_b = 0.0
            T_b = 288.15
            L_b = -0.0065
            local_atmospheric_temperature = T_b + (L_b*(h-h_b))
    
            return local_atmospheric_temperature
    
        if h > 11000 and h <= 20000:
            h_b = 11000
            T_b = 216.65
            L_b = 0.0
            local_atmospheric_temperature = T_b + (L_b*(h-h_b))
    
            return local_atmospheric_temperature
    
        if h > 20000 and h <= 32000:
            h_b = 20000
            T_b = 216.65
            L_b = 0.001
            local_atmospheric_temperature = T_b + (L_b*(h-h_b))
            return local_atmospheric_temperature
    
        if h > 32000 and h <= 47000:
            h_b = 32000
            T_b = 228.65
            L_b = 0.0028
            local_atmospheric_temperature = T_b + (L_b*(h-h_b))
            return local_atmospheric_temperature
    
        if h > 47000 and h <= 51000:
            h_b = 47000
            T_b = 270.65
            L_b = 0.0
            local_atmospheric_temperature = T_b + (L_b*(h-h_b))
            return local_atmospheric_temperature
    
        if h > 51000 and h <= 71000:
            h_b = 51000
            T_b = 270.65
            L_b = -0.0028
            local_atmospheric_temperature = T_b + (L_b*(h-h_b))
            return local_atmospheric_temperature
    
        if h > 71000 and h <= 80000:
            h_b = 71000
            T_b = 214.65
            L_b = -0.002
            local_atmospheric_temperature = T_b + (L_b*(h-h_b))
            return local_atmospheric_temperature
    
    def local_atmospheric_density(altitude):
    
        h = altitude
    
        T_local = local_atmospheric_temperature(h)
    
        g_0 = 9.80665 #[m/s^2]
        m_M = 0.0289644 #[kg/mol]
        R_univ = 8.31432 #[J/mol*K]
    
        if h > 0 and h <= 11000:
            L_b = -0.0065
            T_b = 288.15
            rho_b = 1.2250
            local_atmospheric_density = rho_b * ((T_b/T_local)**(1+((g_0*m_M)/(R_univ*L_b))))
            return local_atmospheric_density
    
        if h > 11000 and h <= 20000:
            h_b = 11000
            L_b = 0.0
            T_b = 216.65
            rho_b = 0.36391
            local_atmospheric_density = rho_b * math.exp((-g_0*m_M*(h-h_b))/(R_univ*T_b))
            return local_atmospheric_density
    
        if h > 20000 and h <= 32000:
            L_b = 0.001
            T_b = 216.65
            rho_b = 0.08803
            local_atmospheric_density = rho_b * ((T_b/T_local)**(1+((g_0*m_M)/(R_univ*L_b))))
            return local_atmospheric_density
    
        if h > 32000 and h <= 47000:
            L_b = 0.0028
            T_b = 228.65
            rho_b = 0.01322
            local_atmospheric_density = rho_b * ((T_b/T_local)**(1+((g_0*m_M)/(R_univ*L_b))))
            return local_atmospheric_density
    
        if h > 47000 and h <= 51000:
            h_b = 47000
            L_b = 0.0
            T_b = 270.65
            rho_b = 0.00143
            local_atmospheric_density = rho_b * math.exp((-g_0*m_M*(h-h_b))/(R_univ*T_b))
            return local_atmospheric_density    
    
        if h > 51000 and h <= 71000:
            L_b = -0.0028
            T_b = 270.65
            rho_b = 0.00086
            local_atmospheric_density = rho_b * ((T_b/T_local)**(1+((g_0*m_M)/(R_univ*L_b))))
            return local_atmospheric_density
    
        if h > 71000 and h <= 80000:
            L_b = -0.002
            T_b = 214.65
            rho_b = 0.000064
            local_atmospheric_density = rho_b * ((T_b/T_local)**(1+((g_0*m_M)/(R_univ*L_b))))
            return local_atmospheric_density
    
    
    def local_atmospheric_pressure(altitude):
    
        h = altitude
        R_univ = 8.31432 #[J/mol*K]
        m_M = 0.0289644 #[kg/mol]
    
        local_atmospheric_pressure = ((local_atmospheric_density(h)* R_univ * local_atmospheric_temperature(h))/m_M)*10**(-5)
    
        return local_atmospheric_pressure
    
    N = 80000
    z = np.zeros((N,2))
    
    for h in range(0,80000,1):
    
        z[h,0] = h/1000
        z[h,1] = local_atmospheric_pressure(h)
        h+=1
    
    plt.title('Pressure at Different Altitudes',fontsize=12)
    plt.ylabel('Altitude in [km]',fontsize=10)
    plt.xlabel('Pressure in [bar]',fontsize=10)
    plt.axis([-0.1,1.1,-5,85])
    plt.plot(z[:,1],z[:,0],'b')
    plt.show()
    
    

    안녕하세요. 질문이 있습니다. for 문에서 0부터 시작하면 TypeError: unsupported operand type(s) for *: 'NoneType' and 'float' 이런 에러가 뜨고, 1부터 시작하면 문제없이 작동합니다. 0부터 시작해야 그래프를 그릴때 문제가 없는데, 이걸 어떻게 해결해야할지 모르겠습니다.. 도움 주실 수 있을까요?

    p.s. 제일 밑에 함수 pressure 부분을 빼고 altitude 함수까지만 해서 N부터 시작하는 for 구문을 넣으면 0부터 시작해도 잘 작동합니다.