How do I iterate a function which has 3 variables?

I have this function which is defined by 3 variables xvalue, P, C

we have f(xvalue, P, C) = a formula

This formula gives me an approximation for my data. So, I want this function(which gives a list) to be very close to the data values.

All the 3 variables take 29 values so I use a linespace command for all 3.

This is the code I have written.

G = 6.687*(10**(-11))
pie = 3.14159265358979
xvalue = np.linspace(8, 37, 29)*(3.086*(10**(19)))
def f(xvalue, P, C):
    return ((G*(((2*pie*(C)**3*P*((2*(xvalue+C)**2) * (np.log(xvalue+C)) +4*C*xvalue + 3*(C)**2 ))/(xvalue+C)**2) - (2*pie*(C)**3*P*(2*np.log(C) + 3))))**(1/2))/(xvalue)**(1/2)
f( (np.linspace(8, 37, 30)*(3.086*(10**(19)))), (np.linspace(5, 10, 30)*(10**(-20)))  , (np.linspace(2, 9, 30)*(10**(19)))) 

And the result I get is

array([ 41057.48335783,  46766.86571009,  52630.23811206,  58644.17375691,
        64805.45233656,  71111.04022756,  77558.07341632,  84143.842609  ,
        90865.78013739,  97721.44837086, 104708.52940819, 111824.81586818,
       119068.2026304 , 126436.67940272, 133928.32401215, 141541.29633103,
       149273.83276362, 157124.24122895, 165090.89658431, 173172.23644133,
       181366.75733289, 189673.01119427, 198089.60212662, 206615.18341451,
       215248.45477286, 223988.15980131, 232833.08362655, 241782.05071537,
       250833.92284304, 259987.59720332])

An array with 29 values. But, I want to get more than 29 values. To elucidate, the values I am getting are

 f(x[0], P[0], C[0])
 f(x[1], P[1], C[1])
 f(x[2], P[2], C[2])
 f(x[3], P[3], C[3])....
 f(x[29], P[29], C[29])

However, for greater approximation for my data, I want the the iteration of individual elements like this;

f(x[0], P[0], C[0]) 
 f(x[0], P[1], C[0])
 f(x[0], P[2], C[0])
 f(x[0], P[3], C[0]).....
 f(x[0], P[29], C[0])

and then the computer takes the next set of values

 f(x[1], P[0], C[0]) 
 f(x[1], P[1], C[0])
 f(x[1], P[2], C[0])
 f(x[1], P[3], C[0])....
 f(x[1], P[29], C[0])

So this goes on until x reaches 29. But, C is still zero. So I need to repeat the process again but this time I need to have the value of C as 1.

I don't know how to implement this process in code. Is there a simpler way to do this instead of having to manually re-enter values?

Read more here:

Content Attribution

This content was originally published by Papernapkin23 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: