Solving coupled second order differential equations
이전 댓글 표시
Hi,
I constantly get an error that I do not know how to resolve when I run this code. Any help would be greatly appreciated. The Force function applies a force of 50N @ t = 0 and equals 0 at all other time steps.
syms c k m1 m2 x1(t) x2(t) t F Y;
% 1st and 2nd derivative
dx1 = diff(x1);
d2x1 = diff(x1,2);
dx2 = diff(x2);
d2x2 = diff(x2,2);
% Defining equations
Eq1 = d2x1 == -(c/m1)*(dx1-dx2) - (k/m1)*(x1(t)-x2(t)) + F/m1;
Eq2 = d2x2 == -(c/m2)*(dx1-dx2) + (k/m2)*(x1(t)-x2(t));
[VF,subs] = odeToVectorField(Eq1, Eq2);
ftotal = matlabFunction(VF,'Vars',{t,Y,F,c,k,m1,m2});
m1 = 10;
m2 = 20;
c = 30;
k = 5;
F = @(t) Force(t);
tspan = [0 1];
ic = [8 0 0 0];
[t,Y] = ode45(@(t,Y) ftotal(t,Y,F,c,k,m1,m2), tspan, ic);
figure
plot(t, Y)
grid
legend(string(subs))
댓글 수: 1
Torsten
2022년 9월 6일
The value of the "Force" function at t=0 must somehow be part of the initial conditions ic.
As part of the differential equations, it won't influence the result.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
