Code covered by the BSD License

Using Analytical Tools to Gain Insight and Speed-up Num. Analysis in MATLAB & Symbolic Math Toolbox

Deepak Ramaswamy (view profile)

28 Jan 2013 (Updated )

files from the webinar

massspringdamper.m
```%% Find eigenvalues of first order ODE corresponding to mass-spring-damper
syms m B k x(t) f real;
eq = m*diff(diff(x,t),t) + B*diff(x,t) + k*x - f; % m*x''(t)+B*x'(t)+k*x - f
display '2nd order ODE'
pretty(eq);
[V,Y] = odeToVectorField(eq); % Convert 2nd order ODE into 1st order
V = subs(V,{'Y[1]','Y[2]'},{Y(1),Y(2)});
display 'System of 1st order ODEs'
pretty(V);
A = equationsToMatrix(V,[Y(1),Y(2)]); % Extract matrix
display 'Symbolic matrix form'
pretty(A);
E = eig(A); % Find symbolic eigenvalues
display 'eigenvalues'
pretty(E);
%% Find poles of frequency domain transfer function
syms s Input Output y(t);
eqs = laplace(subs(eq,f,y(t)),t,s); % Apply Laplace transform
eqs = subs(eqs,{'laplace(x(t),t,s)','laplace(y(t),t,s)',...
'D(x)(0)',x(0)},{Output,Input,0,0}); % Substitute with Input&Output
display 'ODE in Laplace domain'
pretty(eqs)
Input = solve(eqs==0,Output,'IgnoreAnalyticConstraints',true);% Solve to get transfer function
display 'Transfer function'; pretty(Input);
display 'Poles'
pls = poles(Input); pretty(pls); % Extract poles
display 'Poles are identical to the eigenvalues'
%
% Copyright 2012 The MathWorks, Inc.```