function engr80_august_14_2006_2() % shows how to use Matlab to animation response of one degree of % freedom system. % show the effect of changing the damping of the system on the response. % by Nasser Abbasi, UCI. clear all; close all; t_start = 0; t_end = 6; %final time in seconds. time_span =t_start:0.001:t_end; k = 40; % spring stiffness. N/m m = 5; % mass, kg cr = 2*sqrt(k*m); %critical damping fprintf('critical damping coef. of system is %f\n',cr); initial_position = 0; initial_speed = 0; x0 = [initial_position initial_speed]; % Now start the simulation, change damping. for c = 0: .5 : cr+.1*cr [t,x]=ode45(@rhs,time_span,x0); plot(t,x(:,1)); title(sprintf('Critical damping=%4.1f, current damping coeff. =%4.1f',cr,c)); ylim([-.1 .5]); drawnow; pause(.1); end grid %************************************** % solves m x''+ c x' + k x = f(t) %************************************** function xdot=rhs(t,x) xdot_1 = x(2); xdot_2 = -(c/m)*x(2) - (k/m)*x(1) + force(t)/m; xdot = [xdot_1 ; xdot_2 ]; end %******************** % The forcing function, edit to change as needed. %******************** function f=force(t) P = 100; % force amplitude %f=P*sin(omega*t); f=10; %unit step %if t