function [M,K,D]=springmass(n,m,k,b) % SPRINGMASS constructs a model for a mass-spring-damper chain % % SPRINGMASS constructs a continuous time model % for a mass-spring-damper chain. % The chain is arranged with the first spring-damper attached % to a fixed point. % % written by S. Lall, 2001. % % [M,K,D]=springmass(n,m,k,b) % % returns M, K, D such that equations of motion are % % M \ddot{x} + D \dot{x} + K x = force % % n = number of masses % m = n length vector specifying mass of each element % k = n length vector specifying spring constant of each spring % b = n length vector specifying damping constant of each damper % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % version control lcplus='edited'; lcversion=[2003,01,21,01]; lcdate='21 Jan 2003'; % handy vector of ones om=ones(n,1); % k on the diagonal, -k on the subdiagonal K1=full(spdiags( [k, [-k(2:end);0]],[0,-1],n,n)); % b on the diagonal, -b on the subdiagonal B1=full(spdiags( [b, [-b(2:end);0]],[0,-1],n,n)); % -1 on the diagonal, 1 on the superdiagonal F1=full(spdiags( [-om, om],[0,1],n,n)); % mass matrix M=diag(m); % spring matrix K=-F1*K1; % damping D=-F1*B1;