How to solve an equation of motion with the ode solver with time dependent components
Show older comments
Hello,
I have the following equation of motion of a mass M, a damping force D, a stiffness K and a (time dependent) external Force F(t):
M*x‘‘(t)+D*x‘(t)+K*x(t)= F(t)
Is there any possibility to solve this equation of motion with ODE or another Matlab command?
Now I am new to Matlab and still a student, so i don't have a lot of experience with Matlab. I hope this is a simple problem that a more experienced Matlab user can help me to solve this problem.
Thanks,
Jenny
Answers (1)
Torsten
on 23 Nov 2015
function main
x0=[0 1]; % first component is x(0), second x'(0)
tspan=[0 20]; % timespan of integration
[T,Y] = ode45(@myfun,tspan,x0);
plot(T,Y(:,1),T,Y(:,2));
function dy = myfun(t,y)
F=...;
K=...;
D=...;
M=...;
dy=zeros(2,1);
dy(1)=y(2);
dy(2)=(F-K*y(1)-D*y(2))/M;
Best wishes
Torsten.
Categories
Find more on Programming 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!