Hi guys, i am trying to optimize the mass damper system by choosing the optimal values of k2 and c2. I am getting so many errors while using fminsearch(). I am sharing the code below which is providing output for values of x1 and x2 (displacements of 2 masses). Our goal is to minimize x1 after 300s. It would be great if someone can help me modifying this code ofr fminsearch please.
In the code, values of k2 and c2 are selected manually but we need to optimize them using fminsearch()
clc
clear all
close all
tspan = [0:0.1:400]; %observing system's behaviour from 0-400 seconds
x0 = [0;0;0;0]; % as m1 and m2 are at rest at t=0.
%x1(0),x2(0),vel_m1(0) and vel_m2(0)
[t,x] = ode45(@odefun, tspan, x0); %odefun is the name of the function
plot(t,x(:,1)) %first degree
hold on
plot(t,x(:,2)) %second degree
legend('x1','x2')
xlabel('time')
ylabel('displacement')
function dxdt= odefun(t,x) %creating derivative functions
m1=50000; % given in the question
m2=1000; % 2 percent mass of m1
k1=500; % given in the question.
k2=50; % manually selected value to minimize x1
c2=400; % manually selected value to minimize x1
if t<=0.1 %Fd occurs at m1 only for first 100 ms
Fd=1000;
else
Fd=0;
end
%initializing column vector dxdt function
dxdt=zeros(4,1);
dxdt(1)=x(3); %equation 1
dxdt(2)=x(4); %equation 2
dxdt(3)=1/m1*(-(k1+k2)*x(1)+k2*x(2)-c2*(x(4)-x(3))+Fd); %equation 3
dxdt(4)=1/m2*(k2*x(1)-k2*(x(2))+c2*(x(3))-c2*(x(4))); %equation 4
end

댓글 수: 2

Alan Stevens
Alan Stevens 2022년 9월 26일
What do you mean by optimize/minimize x1? x1 varies in time; at what time do you want it minimized?
Gurkaran Singh
Gurkaran Singh 2022년 9월 26일
편집: Gurkaran Singh 2022년 9월 26일
Thanks Alan for commenting. Our object is to minimize x1 after 300 s. Is it possibile to use fminsearch to calculate the values of k2 and c2?

댓글을 달려면 로그인하십시오.

 채택된 답변

Torsten
Torsten 2022년 9월 26일
편집: Torsten 2022년 9월 26일

0 개 추천

p0 = [50 400];
p = fminsearch(@fun,p0)
Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: -Inf
p = 1×2
1.0e+06 * 0.2536 -2.4047
function objective = fun(p)
k2 = p(1);
c2 = p(2);
%tspan = [0,0.3]; %observing system's behaviour from 0-400 seconds
x0 = [0;0;0;0]; % as m1 and m2 are at rest at t=0.
%x1(0),x2(0),vel_m1(0) and vel_m2(0)
tspan = [0,0.1];
iflag = 1;
[t,x] = ode45(@(t,x)odefun(t,x,k2,c2,iflag), tspan, x0); %odefun is the name of the function
tspan = [0.1,0.3];
x0 = x(end,:);
iflag = 2;
[t,x] = ode45(@(t,x)odefun(t,x,k2,c2,iflag), tspan, x0); %odefun is the name of the function
objective = x(end,1);
end
function dxdt= odefun(t,x,k2,c2,iflag) %creating derivative functions
m1=50000; % given in the question
m2=1000; % 2 percent mass of m1
k1=500; % given in the question.
%k2=50; % manually selected value to minimize x1
%c2=400; % manually selected value to minimize x1
if iflag==1
Fd = 1000;
elseif iflag==2
Fd = 0.0;
end
%if t<=0.1 %Fd occurs at m1 only for first 100 ms
% Fd=1000;
%else
% Fd=0;
%end
%initializing column vector dxdt function
dxdt=zeros(4,1);
dxdt(1)=x(3); %equation 1
dxdt(2)=x(4); %equation 2
dxdt(3)=1/m1*(-(k1+k2)*x(1)+k2*x(2)-c2*(x(4)-x(3))+Fd); %equation 3
dxdt(4)=1/m2*(k2*x(1)-k2*(x(2))+c2*(x(3))-c2*(x(4))); %equation 4
end

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기

질문:

2022년 9월 26일

편집:

2022년 9월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by