No BSD License  

Highlights from
MATLAB for Engineers

from MATLAB for Engineers by Adrian Biran
Companion Software

wd=spring(t,w);
function wd=spring(t,w);
% This function defines the differential equation relative to
% a damped mass-spring system, subject to an external sinusoidal force.
% It is written in the format required by ODE23 and ODE45.

% assign values to the constants that define the system

a = 2.0;                     % N
m = 2.0;                     % kg
c = 1.4;                     % Ns / m
h = 0.1;                     % N/m


% --- compute derivatives
[rows, cols] =  size(w);
wd = zeros(rows, cols);      % allocate space for wd
wd (1)   = - c/m*w(1) - h/m* w(2) + a/m*sin(t);
wd(2)    = w(1);

Contact us at files@mathworks.com