Optimization 14DOF exact different than calculated periods

53 次查看(过去 30 天)

here is my code. When optimizing the T calculated are very different than my periods is there a problem with my interactions? clear all

% Number of Degrees of Freedom (DOFs) numDOF = 14;

% Mass data in kips (converted to slugs by dividing by 32.2) mass_values_kips = [ 481.3598137; 139.9818634; 139.9818634; 137.7838199; 135.5857453; 135.5857453; 135.5857453; 134.0534472; 133.7469876; 133.7469876; 133.7469876; 133.0730745; 132.9382919; 146.5049689 ]; % Masses in kips

% Convert to slugs mass_values = mass_values_kips / 32.2;

% Construct the mass matrix as a diagonal matrix M = diag(mass_values);

% Define target periods and frequencies as before periods = [5.016025, 4.130755, 1.048753, 0.9692, 0.843733, 0.498552, 0.425147, ... 0.314427, 0.258085, 0.254921, 0.219497, 0.175277, 0.165737, 0.161123]; frequencies = 2 * pi ./ periods; f_exact_Hz = frequencies;

% Initial stiffness values for a 14-DOF system min_val = 100; max_val = 5000; k_guess = min_val + (max_val - min_val) * rand(1, 14);

% Define bounds LB = ones(14, 1) * 1e-3; % Lower bounds UB = ones(14, 1) * 1e16; % Upper bounds

% Optimization options options = optimoptions('lsqnonlin', 'Display', 'iter', 'FunctionTolerance', 1e-20, ... 'StepTolerance', 1e-20, 'OptimalityTolerance', 1e-20, 'MaxFunEvals', inf, 'MaxIterations', 5000);

% Maximum number of iterations for updating k_initial max_iterations = 10; tolerance = 1e-3; % Tolerance for stopping criterion

for iter = 1:max_iterations % Perform optimization [K_opt_vec,~,res] = lsqnonlin(@(K) obj_function_reshaped_matrix(K, M, frequencies), k_guess, LB, UB, options);

    % Construct the optimized stiffness matrix
    K_opt = diag(K_opt_vec) + diag(-K_opt_vec(2:end), 1) + diag(-K_opt_vec(2:end), -1);
    % Solve eigenvalue problem
    [~, L] = eig(K_opt, M);
    f_calc_Hz = abs(diag(sqrt(L)) / (2 * pi));
    T_calc_s = 1 ./ f_calc_Hz; % Calculated periods
    % Display results for this iteration
    disp(['Iteration ', num2str(iter)]);
    disp('Calculated periods (T_calc_s):');
    disp(T_calc_s);
    % Check if the calculated periods are within tolerance
    if all(abs(T_calc_s - periods) < tolerance)
        disp('Calculated periods are within tolerance.');
        break;
    else
        % Adjust k_guess for the next iteration based on period error
        period_error = T_calc_s - periods;
        adjustment_factor = 1 + period_error ./ periods;
        % Update k_guess based on the adjustment factor
        k_guess = k_guess .* adjustment_factor';
    end
end

disp('Final optimized stiffness matrix (K):'); disp(K_opt); disp('Final calculated periods (T_calc_s):'); disp(T_calc_s);

%% Objective function definition for 14 DOF system with squared differences function diff = obj_function_reshaped_matrix(K_vec, M, f_exact_Hz) % Construct the 14x14 stiffness matrix K_mat = zeros(14, 14);

    % Fill in the diagonal and off-diagonal elements
    for i = 1:14
        if i == 1
            K_mat(i, i) = K_vec(i) + K_vec(i+1);
            K_mat(i, i+1) = -K_vec(i+1);
        elseif i == 14
            K_mat(i, i) = K_vec(i) + K_vec(i-1);
            K_mat(i, i-1) = -K_vec(i);
        else
            K_mat(i, i) = K_vec(i) + K_vec(i+1);
            K_mat(i, i+1) = -K_vec(i+1);
            K_mat(i, i-1) = -K_vec(i);
        end
    end
    % Solve the eigenvalue problem
    [~, L] = eig(K_mat, M);
    % Calculate natural frequencies from eigenvalues
    omega_calc = sqrt(diag(L));  % Rad/s
    f_calc_Hz = omega_calc / (2 * pi);  % Convert to Hz
    % Return the squared difference between calculated and exact frequencies
    diff = (f_calc_Hz - f_exact_Hz).^2;
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by