ShaneCan
ShaneCan

Reputation: 1

Array only filling last value

I'm having a problem with my array only filling the last space with the calculated value. My code is below:

c_volume = 4.45e-5                                                              
c_flow_rate = 1.67e-6                                                           

acr = c_flow_rate/c_volume

t1 = [3600.0,18000.0, 36000.0]
air_conc_t1 = [6.42404968e+02, 2.74977722e+02, 1.45282562e+02]


t2 = [7200.0, 21600.0, 39600.0]
air_conc_t2 = [4.53346985e+02, 2.41359268e+02, 1.28038071e+02]

===============================================================

n_calc = np.zeros((len(t1),1), dtype='f') 

def n(t1, air_conc_t1, t2, air_conc_t2):
    return (1/(t2-t1))*(np.log(air_conc_t1/air_conc_t2))                        

for i in range(len(t1)):
    n_calc[i] = n(t1[i], air_conc_t1[i], t2[i], air_conc_t2[i])

===============================================================

calc_f1 = np.zeros((len(t1),1), dtype='f')
calc_f2 = np.zeros((len(t1),1), dtype='f')
calc_N = np.zeros((len(t1),1), dtype='f')

def f1(acr, n_calc):
    return (acr+n_calc)/n_calc                                                    

calc_f1[i] = f1(acr, n_calc[i])

def f2(acr, n_calc):
    return (acr-n_calc)/n_calc                                                  

calc_f2[i] = f2(acr, n_calc[i])

def N(R, calc_root, m_thickness, calc_f1, calc_f2):
    return (2*R*np.tan(calc_root*m_thickness))/(calc_root*m_thickness*
        (calc_f1+calc_f2*calc_root*m_thickness*((1/np.tan(calc_root\
        *m_thickness))+np.tan(calc_root*m_thickness))))

for i in xrange(len(t1)):
    calc_N[i] = N(R, calc_root[i], m_thickness, calc_f1[i], calc_f2[i])         

print calc_f1
print calc_f2
print calc_N

I'm getting the following printed:

[[    0.        ]
 [    0.        ]
 [ 1070.23657227]]
[[    0.       ]
 [    0.       ]
 [ 1068.2364502]]
[[             inf]
 [             inf]
 [  3.55326119e-06]]

I'm not sure why the first two values of the array are not being filled, but the last one is. I've calculated them by hand and get values.

I'm very new to programming so any help would be appreciated.

Thanks,

Shane

Upvotes: 0

Views: 103

Answers (2)

furas
furas

Reputation: 142651

Lines

calc_f1[i] = f1(acr, n_calc[i])

calc_f2[i] = f2(acr, n_calc[i])

are outside any for loop (maybe it is only problem with indentions).

Upvotes: 1

Chad Dienhart
Chad Dienhart

Reputation: 5194

your calls to f1 and f2 are not in a loop. Note that everything at the same level of indentation is included in the loop.

try this instead:

for i in xrange(len(t1)):
    calc_f1[i] = f1(acr, n_calc[i])
    calc_f2[i] = f2(acr, n_calc[i])
    calc_N[i] = N(R, calc_root[i], m_thickness, calc_f1[i], calc_f2[i])         

print calc_f1
print calc_f2
print calc_N

Upvotes: 1

Related Questions