Home > Software engineering >  How to get a value of function corresponding to certain coordinates without actually replacing the v
How to get a value of function corresponding to certain coordinates without actually replacing the v

Time:11-28

I have an array of values x and y and have a function f(x,y). I want to get the value of f(x1,y1) corresponding to (x1,y1). How can we get it?

khmax = np.arange(0,0.5,0.001)
Ncmax = np.arange(0,0.5,0.001)
[X, Y] = np.meshgrid(Ncmax,khmax)

sum_real = 0
sum_imag = 0
for l in range (0,N):                                                # C_jl * P_lj
    sum_imag = sum_imag   (matrix_C[j_node-1][l])*(np.sin(Y*(x_j(l 1)-x_j(j_node)) / hmax))
    sum_real = sum_real   (matrix_C[j_node-1][l])*(np.cos(Y*(x_j(l 1)-x_j(j_node)) / hmax))
Aj_real = (X * sum_real)
Aj_imag = (X * sum_imag)
G_imag = -Aj_imag   (2 * (Aj_real) * (Aj_imag)) / 2 - ((3 * ((Aj_real)**2) * (Aj_imag)) -((Aj_imag)**3))   ((4*(Aj_real)*(Aj_imag))*((Aj_real)**2 - (Aj_imag)**2))/24
G_real = 1 - (Aj_real)   (((Aj_real)**2 - (Aj_imag)**2)/2) - ((((Aj_real)**3 - 3*(Aj_real)*((Aj_imag)**2)))/6)   ((((((Aj_real)**2 - (Aj_imag)**2 )**2- 4*((Aj_real)**2)*((Aj_imag)**2))))/ 24)

mod_G = (((G_real)**2)   ((G_imag)**2))**(0.5)

In this code mod_G is a function of (khmax, Ncmax). I want to get the value of mod_G corresponding to (khmax,Ncmax) suppose(0.1,0.1). I don't want to put the value of (khmax, Ncmax) into the function directly(i.e not replacing khmax with 0.1 and Ncmax with 0.1). How can I get mod_G without doing this?

CodePudding user response:

Could you try defining it as an actual python function, i.e. using the def keyword and then calling it with the two parameters? This way you could just easily call it as mod_G(0.1,0.1) without changing anything else.

  • Related