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

Output power of a motor

The code:
clc;
clear;

t=0:0.01:10;
wm=188.5.*(1-exp(-0.2.*t));
Tind=10.*exp(-0.2.*t);

p=Tind.*wm;

plot(t,wm)
title('Rotational speed Vs. Time');
xlabel('Time (s)');
ylabel('\it{\omega}_m (rad/s)');

figure, plot(t,Tind)
title('Induced torque Vs. Time');
xlabel('Time (s)');
ylabel('\it{\tau}_{ind} (N.m)');

figure, plot(t,p)
title('Power Vs. Time');
xlabel('Time (s)');
ylabel('P (Watt)');

[maxp i]=max(p);

fprintf('The maximum is %f and its at %f seconds \n',maxp,i);

the output in the Command Window:
The maximum is 471.249658 and its at 348.000000 seconds 






Trajectories


The Code:


clc;
clear;

% inialization
y0=10;
v0=15;
a=-9.81;

% time
t1=0:5;
t2=0:0.01:5;

% the equation
y1=y0+v0.*t1+0.5.*a.*t1.^2;
y2=y0+v0.*t2+0.5.*a.*t2.^2;

plot(t1,y1);
figure
plot(t2,y2);
--------------------------------------
The resultant figure for a step increase of 1s

The resultant figure for a step increase of 0.01s



Welcoming

My colleagues,
Welcome to this blog.
I'll post the codes that we discuss in the class so that you can read it.
Please if you have any question. Don't hesitate to ask me.

LET'S MATLAB