Using fminsearch() for MSD system
Show older comments
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 Comments
Alan Stevens
on 26 Sep 2022
What do you mean by optimize/minimize x1? x1 varies in time; at what time do you want it minimized?
Gurkaran Singh
on 26 Sep 2022
Edited: Gurkaran Singh
on 26 Sep 2022
Accepted Answer
More Answers (0)
Categories
Find more on Systems of Nonlinear Equations 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!