def integral_x(n, res=1000): newgrid = copy.deepcopy(aero_data) x1, x2 = 0, 1.611 z1, z2 = 0, 0.505 def cubic_function(x): y = cubic_interpolator(matrix, nodes, row, x) return y nodes = nodes_x solution = [] for row in newgrid: matrix = cubic_coefficients(nodes, row) a = def_integral(cubic_function, x1, x2, res) solution.append(a) if n == 1: x = np.linspace(0, 1.611, len(solution)) plt.xlabel('z-axis') plt.plot(x, solution) plt.show() return solution nodes = nodes_z if n == 2: row = solution matrix = cubic_coefficients(nodes, solution) solution = def_integral(cubic_function, z1, z2, res) else: for i in range(n - 2): row = solution matrix = cubic_coefficients(nodes, solution) solution = indef_integral(cubic_function, z1, z2, res) nodes = np.linspace(z1, z2, len(solution)) row = solution matrix = cubic_coefficients(nodes, solution) solution = def_integral(cubic_function, z1, z2, res) # return solution return 0
def integral_z(n, x_final=1.611, z_sc=None, res=1000): # --------------------- input data -------------------------------- newgrid = copy.deepcopy(grid) """ boundaries of the integration """ x1, x2 = 0, 1.611 z1, z2 = 0, 0.505 if z_sc != None: aero_data_z = times_z(aero_data, nodes_z, z_sc) newgrid = transpose(aero_data_z) coord_sys=(1.611,0,-0.505,0) plt.imshow(transpose(newgrid), extent=coord_sys,interpolation='nearest', cmap=cm.gist_rainbow) plt.colorbar() plt.show() # ------------------ main program --------------------------- start_time = time.time() # to calculate runtime of the program """ The program can only calculate integrals of functions, not matrixes or wathever. This function can only have one variable as input: x-value. It also outputs only one value: y-value (=interpolated aero_data) The following defenitinion makes such a function that can later be used in the integral""" def cubic_function(x): y = cubic_interpolator(matrix, nodes,row, x) return y """ the function 'spline_coefficient(nodes,row)' converts an array of x-values (=nodes) and an array of y-values (=column of the aero_data) into a matrix. This matrix is necessary to use the function 'spline_interpolator'. (see interpolation file for explenation) """ nodes = nodes_z solution = [] for row in newgrid: matrix = cubic_coefficients(nodes, row) """ This calculates the definite integral from z1 to z2 of 'function' """ a = def_integral(cubic_function, z1, z2, res) solution.append(a) """ The result is a 1D array of data corresponding to the values of the definite integrals of interpolated columns of the aero_data """ """ This can be used to check the results for when n=1 """ if n == 1: x = np.linspace(0, 1.611, len(solution)) plt.xlabel('x-axis') plt.plot(x, solution) plt.show() return solution nodes = nodes_x if n == 2: row = solution matrix = cubic_coefficients(nodes, solution) solution = def_integral(cubic_function, x1, x_final, res) else: for i in range(n - 2): row = solution matrix = cubic_coefficients(nodes, solution) solution = indef_integral(cubic_function, x1, x2, res) nodes = np.linspace(x1, x2, len(solution)) row = solution matrix = cubic_coefficients(nodes, solution) solution = def_integral(cubic_function, x1, x_final, res) end_time = time.time() run_time = end_time - start_time # print run_time to see the time it took the program to compute return solution