Array problem - trying to remove a value from each array and getting an answer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ritesh247
    New Member
    • Mar 2010
    • 12

    Array problem - trying to remove a value from each array and getting an answer

    I was wondering if anyone could help me out with this:

    lets say u have three arrays:
    A=[1,2,3,4]
    B=[2,3,4,5]
    C=[4,6,7,8]

    I want to use each column from each array to get an output, such that when the code runs it uses the first column, then on the second run uses the second column..e.t.c

    here is the code I have been trying to work on, I have tired different methods but none have worked for me

    according to my code the first column of array from my code i.e xfrn, theta_freqrn, kappa_freqrn, arn and mthetadot, will give a single value of vf, and when the process is repeated it uses the second column of the array from each array to get another vf e.t.c.

    Code:
    xfrn=array([0.937143,0.885173,1.0329])
    theta_freqrn= array([10.1579,9.99248,10.9348])
    kappa_freqrn= array([4.95614, 4, 2])
    arn = array([6.32918, 5, 2])
    Mthetadotrn= array([-1.15940, 1, 4])
      
    s = 7.5
    c = 2.0
    m = 100.0
    rho = 1.225
    xcm = 0.5*c
    e = xfrn/c-0.25    
    
     vel   = zeros((3500,1),float)
    freq1 = zeros((3500,1),float)
    freq2 = zeros((3500,1),float)
    freq3 = zeros((3500,1),float)
    freq4 = zeros((3500,1),float)
    damp1 = zeros((3500,1),float)
    damp2 = zeros((3500,1),float)
    damp3 = zeros((3500,1),float)
    damp4 = zeros((3500,1),float)  
    vstart = 1.0
    vinc = 0.1 for icount in range(3500):            
         V=vstart + icount*vinc
    
         a11 = (m*s*s*s*c)/3.0
         a12 = m*s*s*(c*c/2.0-c*xfrn)/2.0
         a21 = a12
         a22 = m*s*(c*c*c/3.0-c*c*xfrn+xfrn*xfrn*c)
      
         A = matrix([[a11,a12],[a21,a22]])
         Ainv = linalg.inv(A)
      
         k1 = ((kappa_freqrn*arn)**2)*a11 
         k2 = ((theta_freqrn*arn)**2)*a22  
       
         c11 = (rho*V*c*s*s*s*arn)/6.0
         c12 = 0
         c21 = -(rho*V*c*c*s*s*e*arn)/4.0
         c22 = -(rho*V*c*c*c*s*Mthetadotrn)/8.0
       
          C = matrix([[c11,c12],[c21,c22]])
        
          AC = -Ainv*C 
       
          k11 = k1
          k12 = (rho*V*V*c*s*s*arn)/4.0
          k21 = 0
          k22 = k2 - (rho*V*V*c*c*s*e*arn)/2.0
          K = matrix([[k11,k12],[k21,k22]])
       
         AK = -Ainv*K
       
         matrix_bind_columns = concatenate((AK,AC),axis=1)
         M = concatenate((matrix([[0.0,0.0,1.0,0.0][0.0,0.0,0.0,1.0]]),matrix_bind_columns),axis=0)
      
          Meig = linalg.eig(M)[0]
       
         vel[icount] = V
         freq1[icount] = abs(Meig[0])
         damp1[icount] = -100.0*real(Meig[0])/freq1[icount]
         freq1[icount] = freq1[icount]/2*math.pi
         freq2[icount] = abs(Meig[1])
         damp2[icount] = -100.0*real(Meig[1])/freq2[icount]
         freq2[icount] = freq2[icount]/2*math.pi
         freq3[icount] = abs(Meig[2])
         damp3[icount] = -100.0*real(Meig[2])/freq3[icount]
         freq3[icount] = freq3[icount]/2*math.pi
         freq4[icount] = abs(Meig[3])
         damp4[icount] = -100.0*real(Meig[3])/freq4[icount]
         freq4[icount] = freq4[icount]/2*math.pi
      
         if damp3[icount] < 0:           goes below zero
             break
    ab = (damp3[icount-1])
    bc = (damp3[icount])
    Vf_min = V-0.1
    Vf_max = V
      
    def flutter_speed(ab,bc,Vf_min,Vf_max):               
    return (Vf_min+(Vf_max - Vf_min)*(-(ab)/(bc - ab)))
    Vf = flutter_speed(ab,bc,Vf_min,Vf_max)
    print Vf
  • Glenton
    Recognized Expert Contributor
    • Nov 2008
    • 391

    #2
    Hi

    I'm sorry, but it's pretty difficult to engage on this. Please give more description of what it is that's going wrong, and exactly what you want.

    I take it you're using numpy arrays?

    Here's an interactive session that may or may not help:

    Code:
    In [29]: a=arange(10)
    
    In [30]: b=a*5
    
    In [31]: c=1/(a+1)
    
    In [32]: print a,b,c
    [0 1 2 3 4 5 6 7 8 9] [ 0  5 10 15 20 25 30 35 40 45] [1 0 0 0 0 0 0 0 0 0]
    
    In [33]: c=1/(a+1.0)
    
    In [34]: print a,b,c
    [0 1 2 3 4 5 6 7 8 9] [ 0  5 10 15 20 25 30 35 40 45] [ 1.          0.5         0.33333333  0.25        0.2         0.16666667
      0.14285714  0.125       0.11111111  0.1       ]
    
    In [35]: for i,j,k in zip(a,b,c):
       ....:     print "do something with",i,j,k
       ....:     
       ....:     
    do something with 0 0 1.0
    do something with 1 5 0.5
    do something with 2 10 0.333333333333
    do something with 3 15 0.25
    do something with 4 20 0.2
    do something with 5 25 0.166666666667
    do something with 6 30 0.142857142857
    do something with 7 35 0.125
    do something with 8 40 0.111111111111
    do something with 9 45 0.1
    If it doesn't please give more details. Precise descriptions of the exact problem, pseudo-code, and commented real code that is preferrably a minimal working example of what's going wrong would all help.

    Comment

    Working...