[Python] Error: Index out of bounds - Python

Discussão em 'Python' iniciado por Stack, Fevereiro 26, 2025.

  1. Stack

    Stack Membro Participativo

    I am still fairly new to Python and I am attempting to run a for loop. However, I receive an error indicating that my index is out of bounds. I'm not sure what exactly the problem is, any help is appreciated!

    My code and error are both below:

    croot = 1
    ctip = 1
    span = 1
    thetaroot = 0
    thetatip = 0
    a0root = 0.11
    a0tip = 0.11
    alpha = 0
    alpha0root = -2.5
    alpha0tip = -2.5
    thetaroot = thetaroot * atan(1.) / 45.
    thetatip = thetatip * atan(1.) / 45.
    alpha = alpha * atan(1.) / 45.
    alpha0root = alpha0root * atan(1.) / 45.
    alpha0tip = alpha0tip * atan(1.) / 45.
    n = 10
    theta = zeros((1,n))
    y = zeros((1,n))
    c = zeros((1,n))
    cl = zeros((1,n))
    alp = zeros((1,n))
    a = zeros((1,n))
    rhs = zeros((n,1))
    b = zeros((n,1))
    a = zeros((n,1))
    #
    # Define properties at n span stations
    #
    pi = 4. * atan(1.)
    for i in range(1,n):
    theta = i * pi / (2. * n)
    y = span * 0.5 * cos(theta)
    c = croot + (ctip - croot) * y * 2. / span
    alp = alpha + thetaroot - (alpha0root + (alpha0tip - alpha0root + thetaroot - thetatip) * y * 2. / span)
    a = a0root + (a0tip - a0root) * y * 2. / span

    pi = 4. * atan(1)


    I then receive the error

    ---------------------------------------------------------------------------
    IndexError Traceback (most recent call last)
    <ipython-input-8-8710173d8f43> in <module>()
    29 pi = 4. * atan(1.)
    30 for i in range(1,n):
    ---> 31 theta = i * pi / (2. * n)
    32 y = span * 0.5 * cos(theta)
    33 c = croot + (ctip - croot) * y * 2. / span

    IndexError: index 1 is out of bounds for axis 0 with size 1

    Continue reading...

Compartilhe esta Página