Hi @Nikoo,
I did execute your code and I end up getting this plot, so this attached plot below does not match with the plot as shown in your posted comments. Am I right?
Brief Analysis of troubleshooting your code
I had to do a lot of debugging in order to get your code executed properly. First, I had to deal with "Arrays have incompatible sizes for this operation" error, which was to make to sure that the arrays used in the calculations have compatible sizes. In the provided code, the issue arised from the calculation of the determinant of the K_matrix array. To resolve this issue, I had to modify the code to calculate the determinant of the K_matrix array using the det function. However, before calculating the determinant, I had to ensure that the K_matrix array is square, i.e., it has an equal number of rows and columns. So bear in mind , it is essential to ensure that the arrays used in calculations have compatible sizes. Before performing operations such as addition, subtraction, or multiplication, check that the arrays have the same dimensions or are compatible for the specific operation.Additionally, it is good practice to include error handling mechanisms, such as checking the size of arrays before performing operations, as shown in the solution above. This helps to catch any potential errors and handle them gracefully, providing informative messages to aid in debugging. Then, I faced with another error “index out of bounds error”, I added a check to verify that the arrays unstable, divergence_map, and Rdivergence_map have at least 3 columns before attempting to access elements at index 2 and 3. This precautionary measure helped me to prevent index out-of-bounds errors and ensures the arrays contain the necessary data for plotting. Afterwards, I faced the “Index in position 2 exceeds array bounds" error occurs when the code tries to access an element in an array that is beyond its bounds. In the given code, the error was caused by accessing elements in the unstable, divergence_map, and Rdivergence_map arrays without initializing them or updating their values. Lastly, removed the line scatter(Rdivergence_map(:, 2), Rdivergence_map(:, 3), 'filled', 'g'); since Rdivergence_map which was not used in the code. Here is your modified code,
N = 2; % Number of blades
I_thetaoverI_b = 2; % Moment of inertia pitch axis over I_b
I_psioverI_b = 2; % Moment of inertia yaw axis over I_b
C_thetaoverI_b = 0.00; % Damping coefficient over I_b
C_psioverI_b = 0.00; % Damping coefficient over I_b
h = 0.3; % rotor mast height, wing tip spar to rotor hub
hoverR = 0.34;
R = h / hoverR;
gamma = 4; % lock number
V_knots = 325; % the rotor forward velocity [knots]
% Convert velocity from [knots] to [meters per second]
% 1 knot = 0.51444 meters per second
V = V_knots * 0.51444;
% Calculate angular velocity in radians per second
omega_rad_s = V / R;
% Convert angular velocity from radians per second to RPM
% 1 radian per second = (60 / (2 * pi)) RPM
Omega = omega_rad_s * (60 / (2 * pi));
freq_1_over_Omega = 1 / Omega;
% the flap moment aerodynamic coefficients for large V
M_b = -(1 / 10) * V;
M_u = 1 / 6;
% the propeller aerodynamic coefficients
H_u = V / 2;
%%%%%%%%%%%the flap moment aerodynamic coefficients for small V
%M_b = -1*(1 + V^2)/8 ;
%M_u = V/4;
%the propeller aerodynamic coefficients
%H_u = (V^2/2)*log(2/V);
% Frequency ranges:
f_pitch = 5:5:140; % Frequency [Cycle/s or Hz]
f_yaw = 5:5:140; % Frequency [Cycle/s or Hz]
divergence_map = [];
unstable = [];
% Modify the loop to iterate over frequency points
for i = 1:length(f_pitch)
for j = 1:length(f_yaw)
% Angular frequencies for the current frequency points
w_omega_pitch = 2 * pi * f_pitch(i);
w_omega_yaw = 2 * pi * f_yaw(j);
K_psi = (w_omega_pitch^2) * I_psioverI_b;
K_theta = (w_omega_yaw^2) * I_thetaoverI_b;
phi = 0;
% Define inertia matrix [M]
M_matrix = [I_thetaoverI_b + 1 + cos(2 * phi), -sin(2 * phi);
-sin(2 * phi), I_psioverI_b + 1 - cos(2 * phi)];
% Define damping matrix [D]
D11 = h^2 * gamma * H_u * (1 - cos(2 * phi)) - gamma * M_b * (1 + cos(2 * phi)) - (2 + 2 * h * gamma * M_u) * sin(2 * phi);
D12 = h^2 * gamma * H_u * sin(2 * phi) + gamma * M_b * sin(2 * phi) - 2 * (1 + cos(2 * phi)) - 2 * h * gamma * M_u * cos(2 * phi);
D21 = h^2 * gamma * H_u * sin(2 * phi) + gamma * M_b * sin(2 * phi) + 2 * (1 - cos(2 * phi)) - 2 * h * gamma * M_u * cos(2 * phi);
D22 = h^2 * gamma * H_u * (1 + cos(2 * phi)) - gamma * M_b * (1 - cos(2 * phi)) + (2 + 2 * h * gamma * M_u) * sin(2 * phi);
D_matrix = [D11, D12; D21, D22];
% Define stiffness matrix [K]
K11 = K_theta - h * gamma * V * H_u * (1 - cos(2 * phi)) + gamma * V * M_u * sin(2 * phi);
K12 = -h * V * gamma * H_u * sin(2 * phi) + gamma * V * M_u * (1 + cos(2 * phi));
K21 = -h * gamma * V * H_u * sin(2 * phi) - gamma * V * M_u * (1 - cos(2 * phi));
K22 = K_psi - h * gamma * V * H_u * (1 + cos(2 * phi)) - gamma * V * M_u * sin(2 * phi);
K_matrix = [K11, K12; K21, K22];
% Check if K_matrix is square
if size(K_matrix, 1) == size(K_matrix, 2)
% Calculate determinant of K_matrix
det_K = det(K_matrix);
% Divergence condition
if det_K < 0
divergence_map = [divergence_map; phi, K_psi, K_theta];
else
unstable = [unstable; phi, K_psi, K_theta];
end
else
disp('K_matrix is not square');
end
end
end
% Plot the Flutter and divergence maps
figure;
hold on;
scatter(unstable(:, 2), unstable(:, 3), 'filled');
scatter(divergence_map(:, 2), divergence_map(:, 3), 'filled', 'r');
xlabel('K\_psi');
ylabel('K\_theta');
title('Whirl Flutter Diagram');
legend('Flutter area', 'Divergence area');
hold off;
Please execute the modified code to see your attached plot.
I spent enough time troubleshooting this code, so for the future reference, I will advise, try to implement small lines of code first, display results to make sure that you are satisfied with them, it’s like solving a puzzle by putting small pieces together to get the bigger picture. Also, I do admire your enthusiasm solving a complex problem. You are quite motivated and this is why I started helping you out in your previous posts to help achieve your goal and didn’t want you to give up on it that you worked so hard for.
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!