what is wrong on my codes ? I can not get my result any one help?
3 views (last 30 days)
Show older comments
% This script is used to run a genetic algorithm to optimize the parameters of a nonlinear damping system model
clear % Clear the workspace
clc % Clear the command window
% Define the parameters for the system
A = eye(5); % Define a 5x5 identity matrix
% Set the bounds for the optimization variables
b = [65; 290; 200; 200; 200; 200];
UB = [65; 290; 200; 200; 200; 200];
lb = [48; 215; 30; 50; 20; 20];
LB = [48; 215; 30; 50; 20; 20];
% Run the genetic algorithm to optimize the parameters using the TMD_nonlineardamploop function
[x, fval, exitflag] = ga(@TMD_nonlineardamploop, 6, A, b, [], [], LB, UB, [], [1, 2, 3, 4, 5, 6]);
function y = TMD_nonlineardamploop(x)
% This function calculates the response of a nonlinear damping system model
% Inputs:
% - x: Vector of optimization variables containing parameters for the system
% Outputs:
% - y: Maximum displacement of the system
if ~isvector(x)
error('Input must be a vector');
end
% Extract the optimization variables
Kxt = x(1);
Kyt = x(2);
Kzt = x(3);
Kisayx = x(4) / 1000;
Kisayy = x(5) / 1000;
Kisayz = x(6) / 1000;
% Define system parameters
Ly = x(5) / 100;
m = 30;
Kx = 1320; Ky = 1320 * 90.0;
wx = (Kx / m)^0.5;
mt = 1.5 * 2 / 2 / 2;
Lx = 1;
Cx = 2 * 0.025 * 4 * (Kx / m)^0.5 * m;
Cy = 2 * 0.025 * 4 * (Ky / m)^0.5 * m;
% Define the mass, stiffness, and damping matrices
M = [m 0 0 0; 0 m 0 0; 0 0 mt 0; 0 0 0 mt; 0 0 0 mt];
K = [Kx + Kxt 0 -Kxt 0; 0 Ky + Kyt 0 -Kyt; 0 Kz + Kzt 0 -Kzt; -Kxt 0 Kxt 0; 0 -Kyt 0 Kyt; 0 -Kzt 0 Kzt];
C = [Cx + Cxt 0 -Cxt 0; 0 Cy + Cyt 0 -Cyt; Cz + Czt 0 0 -Czt; -Cyt; -Cxt 0 Cxt 0; 0 -Cyt 0 Cyt; 0 -Czt 0 Czt];
...
% Run the nonlinear simulation and store the results
non_linansw = [C_MMM1', MMM(:,1), MMM(:,2), MMM(:,3)];
% Return the maximum displacement of the system
y = max(max([non_linansw(:,2), non_linansw(:,3)]));
end
Answers (1)
Walter Roberson
on 17 Mar 2024
You need
A = eye(6);
However, A*x <= b with A = eye(6) is equivalent to x <= b which is the same thing expressed by UB, so there is no point in using that A b combination. You might as well use A = []; b = [];
4 Comments
See Also
Categories
Find more on Modulation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!