def integral_x(n, z_final=0.505, res=1000): #--------------------- input data -------------------------------- x1, x2 = 0, 1.611 z1, z2 = 0, 0.505 #------------------ main program --------------------------- def function(x): y = spline_interpolator(matrix, nodes, x) return y nodes = np.linspace(x1, x2, len(aero_data[0])) solution = [] for row in aero_data: matrix = spline_coefficient(nodes, row) a = def_integral(function, x1, x2, res) solution.append(a) if n > 2: for i in range(n - 2): nodes = np.linspace(z1, z2, len(solution)) matrix = spline_coefficient(nodes, solution) solution = indef_integral(function, z1, z2, res) if n > 1: nodes = np.linspace(z1, z2, len(solution)) matrix = spline_coefficient(nodes, solution) solution = def_integral(function, z1, z_final, res) return solution
def integral_z(n, x_final=1.611, z_sc=0, res=1000): #--------------------- input data -------------------------------- """ boundaries of the integration """ x1, x2 = 0, 1.611 z1, z2 = 0, 0.505 for row in range(len(grid)): for element in range(len(row)): z = element * 0.505 / 80 grid[row][element] = grid[row][element] * (z - z_sc) #------------------ 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 function(x): y = spline_interpolator(matrix, nodes, 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 = np.linspace(z1, z2, len(grid[0])) solution = [] for row in grid: matrix = spline_coefficient(nodes, row) """ This calculates the definite integral from z1 to z2 of 'function' """ a = def_integral(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 """ if n > 2: for i in range(n - 2): nodes = np.linspace(x1, x2, len(solution)) matrix = spline_coefficient(nodes, solution) solution = indef_integral(function, x1, x2, res) """ This can be used to check the results for when n=1 (only integrated once w.r.t. z-axis) or an intermediate step of another integration""" plot_to_show = 2 # Show the plot of the n'th integral. plot_to_show = 0 for no plots. if n == 1 or n - 1 == plot_to_show: x = np.linspace(0, 1.611, len(solution)) plt.xlabel('x-axis') plt.ylabel('z-axis') plt.plot(x, solution) plt.show() if n > 1: nodes = np.linspace(x1, x2, len(solution)) matrix = spline_coefficient(nodes, solution) solution = def_integral(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
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