Get the same value when using Integral2 function
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Yi-Kai Peng
el 5 de Ag. de 2023
Comentada: Yi-Kai Peng
el 8 de Ag. de 2023
I am using integral2 function to calculate the double integral. The source code is shown as follows:
%% Calculate the drag power for the bare fuselage
bl_bare = @(u,z) Oper.rho .* (u ./ Oper.Vinf) .* 0.5 .* (Oper.Vinf^2 - (u.^2));
ke_out_bare = @(u,z) Oper.rho .* (u ./ Oper.Vinf) .* 0.5 .* ((u - Oper.Vinf).^2);
% Perform double integral
q1_bare = integral2(bl_bare, 0, delta99, 0, 2*pi);
q2_bare = integral2(ke_out_bare, 0, delta99, 0, 2*pi);
D_bare = q1_bare + q2_bare;
%% Calculate the drag power for the bare fuselage with induced velocity field
v_induced = u .* (1 + a_fit);
v_slipstream = u .* (1 + (2 .* a_fit));
bl_induced = @(v_induced,z) Oper.rho .* (v_induced ./ Oper.Vinf) .* 0.5 .* (Oper.Vinf^2 - (v_induced .^2));
ke_out_induced = @(v_slipstream,z) Oper.rho .* (v_slipstream ./ Oper.Vinf) .* 0.5 .* ((v_slipstream - Oper.Vinf).^2);
% Perform double integral
q1_induced = integral2(bl_induced, 0, delta99, 0, 2*pi);
q2_induced = integral2(ke_out_induced, 0, delta99, 0, 2*pi);
D_induced = q1_induced + q2_induced;
However, q1_bare and q1_induced are the same, and q2_bare and q2_induced are the same as well.
I have checked that v_induced and v_slipstream are different from u. However, I cannot figure out why I got the same value.
u and a_fit are 1x30 double, and Oper.Vinf and Oper.rho are 1x1 double.
I appricate all the help. Thank you!
0 comentarios
Respuesta aceptada
Torsten
el 5 de Ag. de 2023
Editada: Torsten
el 6 de Ag. de 2023
As I already tried to explain, v_induced and v_slipstream are only formal parameters for the integral2 function. They cannot transport values that you gave to them in a preceding calculation.
The functions bl_induced and q2_induced are called from integral2 with certain values for v_induced and z resp. ke_out_induced and z in the intervals [0,delta99] and [0,2*pi] to approximate the integrals. Thus you get the same result as in the first part of the code ; only the names of the independent variables in your integral functions have changed, but this doesn't influence the values of the integrals.
Maybe you have a matrix of values for bl_induced and ke_out_induced over a 2d-grid for v_induced and z resp. v_slipstream and z. If this is the case, use trapz twice instead of integral2 and take a look at the example "Multiple Numerical Integrations" under
But before, you will have to explain the z-dependency of your functions to be integrated. If they don't depend on z, you have a 1d-integration and you can multiply the result by 2*pi.
Más respuestas (0)
Ver también
Categorías
Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!