Pages

Tuesday, November 1, 2011

Simulation of a Mass-Spring-Damper system

In this code simulates a mass-spring-damper system
m x''(t)+c x'(t)+k x(t) = f(t)



The code:
clc;
clear;

syms m c k t s  XS
x=sym('x(t)');
dx1=diff(x,t);
dx2=diff(x,t,2);

F=sin(t);
eq=m*dx2+c*dx1+k*x-F;

L=laplace(eq,t,s);

L1=subs(L,{c,m,k,'x(0)','D(x)(0)'},{2000,1007,40000,0,0});

Lf=subs(L1,{'laplace(x(t),t,s)'},{'XS'});

Lc=collect(Lf);

xi=solve(Lc,XS);

xf = ilaplace(xi, s, t);

ezplot(xf,[0,15]);
title('The Displacement Vs. time');
ylabel('Displacemnt (m)');
xlabel('time (s)');
------------------------------------

Inshallah next class we will discuss more examples on this code

No comments:

Post a Comment