how to solve this second differential equation mx"+cx'+kx​+kx^3=f0co​s(wt)(I am stuck)

조회 수: 39 (최근 30일)
What is wrong in my code?
function Xdot=num_for(t,X)
m=100; k=1000; c=160;
ze=c/(2*sqrt(k*m));
wn=sqrt(k/m);
w=5; F=160; f=F/m;
y0=[0.01;0.1];
y1=y0.^2;
f=[0; f*cos(w*t)];
A=[0 1;-wn*wn-k/m*y1 -2*ze*wn];
Xdot=A*X+f;
end
Tspan=[0 10];
y0=[0.01;0.1];
[t,y]=ode45(@num_for,Tspan,y0);
figure
plot(t,y(:,1))

답변 (1개)

Sam Chak
Sam Chak 2022년 4월 24일
I have fixed the state matrix A and remove the unnecessary parameters. Now it should work properly.
Dynamics:
State-space model:
function Xdot = num_for(t, X)
Xdot = zeros(2,1);
m = 100;
k = 1000;
c = 160;
w = 5;
f = 160;
F = [0; (f/m)*cos(w*t)]; % input force vector
A = [0 1; -k/m -c/m]; % state matrix
Xdot = A*X + F; % state-space model
end
Run the solver:
Tspan = [0 10];
y0 = [0.01; 0.1];
[t, y] = ode45(@num_for, Tspan, y0);
figure
plot(t, y(:,1), 'linewidth', 1.5)
grid on
xlabel('Time, t [sec]')
ylabel({'$x_{1}$'}, 'Interpreter', 'latex')
title('Time response of the 1st system state')
Result:

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by