채택된 답변

Sam Chak
Sam Chak 2022년 12월 21일

1 개 추천

The nonlinear matrix ODE with time-varying stiffness matrix K can be transformed into a nonlinear state-space model. See example below.
tspan = [0 40];
x0 = [1 0.5 0 0];
[t, x] = ode45(@odefcn, tspan, x0);
plot(t, x), grid on, xlabel('t')
function xdot = odefcn(t, x)
xdot = zeros(4, 1);
M = diag([3 5]);
C = 2*eye(2);
K = [1+0.5*sin(2*pi/40*t) 0; 0 1+0.5*sin(2*pi/40*t)]; % time-varying K
A = [zeros(2) eye(2); -M\K -M\C];
B = [zeros(2); eye(2)];
F = [0; 0]; % Requires your input
u = M\F;
xdot = A*x + B*u;
end

댓글 수: 4

GUANGHE HUO
GUANGHE HUO 2022년 12월 21일
thanks for your answer@Sam Chak, I will try
GUANGHE HUO
GUANGHE HUO 2022년 12월 21일
Hi, @Sam Chak, for every time point, I have stored the Force vector and Stiffness Matrix by using cell, like F{i,1} and K{i,1}. I want to use ode45 in a LOOP, as following:
for kk=1:1:Length(T) % T is time point vector
end
but now I do not know how to use the template that you give me? Do you have some advice?
I use ordinary numeric array in my simulations. Perhaps you can try using the cell2mat() command to convert the selected cell array into the desired numeric array.
If your Force vector and the Stiffness matrix are time series data (cannot be expressed in any fundamental mathematical form), then you need to use the interp1() function to interpolate and to obtain the value of the time-dependent terms at the specified time.
Here is an example of using a data-driven Force to stabilize the Double Integrator system:
% Force data set recorded over some intervals of time
ft = linspace(0, 20, 2001);
f = 2*exp(-ft).*ft - exp(-ft).*(1 + ft); % made-up to generate the data
tspan = [0 20];
y0 = [1 0];
opts = odeset('RelTol', 1e-4, 'AbsTol', 1e-8);
[t, y] = ode45(@(t, y) doubleInt(t, y, ft, f), tspan, y0, opts);
plot(t, y), grid on, xlabel('t'), ylabel('Y(t)')
legend('y_{1}(t)', 'y_{2}(t)')
% Double Integrator system
function dydt = doubleInt(t, y, ft, f)
dydt = zeros(2, 1);
f = interp1(ft, f, t); % Interpolate the data set (ft, f) at time t
dydt(1) = y(2);
dydt(2) = f;
end
GUANGHE HUO
GUANGHE HUO 2022년 12월 23일
Thanks for your help.@Sam Chak, You give me a lot of help, because i am new for MATLAB

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

추가 답변 (1개)

Torsten
Torsten 2022년 12월 20일

0 개 추천

Write as
xdot = y
ydot = inv(M)*(F-c*y-K*x)
and use ode45 to solve.

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

질문:

2022년 12월 20일

댓글:

2022년 12월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by