Borrar filtros
Borrar filtros

what is wrong on my codes ? I can not get my result any one help?

1 visualización (últimos 30 días)
Doha Ali
Doha Ali el 17 de Mzo. de 2024
Comentada: Doha Ali el 17 de Abr. de 2024
% 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]);
Error using globaloptim.internal.preProcessLinearConstr
The number of rows in A must be the same as the length of b.

Error in gacommon (line 150)
globaloptim.internal.preProcessLinearConstr(Iterate.x,Aineq,bineq, ...

Error in ga (line 377)
NonconFcn,options,Iterate,type] = gacommon(nvars,fun,Aineq,bineq,Aeq,beq,lb,ub, ...
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

Respuestas (1)

Walter Roberson
Walter Roberson el 17 de Mzo. de 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 comentarios
Doha Ali
Doha Ali el 19 de Mzo. de 2024
Editada: Walter Roberson el 19 de Mzo. de 2024
ok,can you use this ? I define kz
% 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(6); % 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;
% 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(6); % 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;Lz=x(5)/100
m = 30;
Kx = 1320; Ky = 1320 * 90.0;Kz=1320*180;
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;
Cz = 2*0.025*4*(Kz/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% 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(6); % 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)
The nested function name 'TMD_nonlineardamploop' must not be reused in the same scope.
% 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;Kz=1320*180;
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;
Cz=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
% 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
Doha Ali
Doha Ali el 17 de Abr. de 2024
can you give the graph of the optimization?

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by