% TOGAC18_MSD_SymbolicAydinetalStab.m

% This file was an attempt to capture the stability of the transfer
% function G(s) seen in the towards collaborative drilling Aydin et al
% paper 2020. instead of using matlab TF functions or any internal transfer
% function analysis methods.
% This approach uses matlabs' symbolic toolbox to isolate where the
% transfer function is stable. The results were no different than seen with
% the stability analysis using TF methods in TOGAC19_MSD_StabilityofAydinetal.m

% Created by Brevin Banks 
% Modified 3/11/2023

%% Create symbolic variables for all variables used to build the controller in Aydin et al
syms m_ad b_ad m b k mp1 bp1 kp1 mp2 bp2 kp2 mp3 bp3 kp3 mh bh kh ke s real
syms a1 b1 a2 b2 a3 b3 bnum1 bnum2 bnum3 bden1 bden2 bden3 k2 k4 k6 real

% Grab the control parameters from the paper symbolically
A = 1/(m_ad*s + b_ad) % Admittance Controller Ys
P1 = k2*(a1*s + b1)/(mp1*s^2 + bp1*s + kp1) % T2
P2 = k4*(a2*s + b2)/(mp2*s^2 + bp2*s + kp2) % T4
P3 = k6*(a3*s + b3)/(mp3*s^2 + bp3*s + kp3) % T6
G = P1+P2+P3 % Total TF
Zeq = mh*s + bh + kh/s + ke/s % Impedance
H = (bnum1*s^2 + bnum2*s + bnum3)/(bden1*s^2 + bden2*s + bden3) % Filter

simplifyFraction(A*G/(1+A*G*H*Zeq))

Expression = (s*(bden1*s^2 + bden2*s + bden3)*(b1*k2*kp2*kp3 + b2*k4*kp1*kp3 + b3*k6*kp1*kp2 + b1*bp2*k2*kp3*s + b1*bp3*k2*kp2*s + b2*bp1*k4*kp3*s + b2*bp3*k4*kp1*s + b3*bp1*k6*kp2*s + b3*bp2*k6*kp1*s + a1*k2*kp2*kp3*s + a2*k4*kp1*kp3*s + a3*k6*kp1*kp2*s + a1*bp2*bp3*k2*s^3 + a2*bp1*bp3*k4*s^3 + a3*bp1*bp2*k6*s^3 + b1*bp2*bp3*k2*s^2 + b2*bp1*bp3*k4*s^2 + b3*bp1*bp2*k6*s^2 + a1*bp2*k2*kp3*s^2 + a1*bp3*k2*kp2*s^2 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*bp3*mp1*s^7 + b_ad*bden2*bp1*bp2*mp3*s^6 + b_ad*bden2*bp1*bp3*mp2*s^6 + b_ad*bden2*bp2*bp3*mp1*s^6 + b_ad*bden3*bp1*bp2*mp3*s^5 + b_ad*bden3*bp1*bp3*mp2*s^5 + b_ad*bden3*bp2*bp3*mp1*s^5 + bden1*bp1*bp2*bp3*m_ad*s^7 + bden2*bp1*bp2*bp3*m_ad*s^6 + bden3*bp1*bp2*bp3*m_ad*s^5 + b_ad*bden1*bp1*kp2*kp3*s^4 + b_ad*bden1*bp2*kp1*kp3*s^4 + b_ad*bden1*bp3*kp1*kp2*s^4 + b_ad*bden2*bp1*kp2*kp3*s^3 + b_ad*bden2*bp2*kp1*kp3*s^3 + b_ad*bden2*bp3*kp1*kp2*s^3 + b_ad*bden3*bp1*kp2*kp3*s^2 + b_ad*bden3*bp2*kp1*kp3*s^2 + b_ad*bden3*bp3*kp1*kp2*s^2 + b_ad*bden1*bp1*kp2*mp3*s^6 + b_ad*bden1*bp1*kp3*mp2*s^6 + b_ad*bden1*bp2*kp1*mp3*s^6 + b_ad*bden1*bp2*kp3*mp1*s^6 + b_ad*bden1*bp3*kp1*mp2*s^6 + b_ad*bden1*bp3*kp2*mp1*s^6 + b_ad*bden2*bp1*kp2*mp3*s^5 + b_ad*bden2*bp1*kp3*mp2*s^5 + b_ad*bden2*bp2*kp1*mp3*s^5 + b_ad*bden2*bp2*kp3*mp1*s^5 + b_ad*bden2*bp3*kp1*mp2*s^5 + b_ad*bden2*bp3*kp2*mp1*s^5 + b_ad*bden3*bp1*kp2*mp3*s^4 + b_ad*bden3*bp1*kp3*mp2*s^4 + b_ad*bden3*bp2*kp1*mp3*s^4 + b_ad*bden3*bp2*kp3*mp1*s^4 + b_ad*bden3*bp3*kp1*mp2*s^4 + b_ad*bden3*bp3*kp2*mp1*s^4 + bden1*bp1*bp2*kp3*m_ad*s^6 + bden1*bp1*bp3*kp2*m_ad*s^6 + bden1*bp2*bp3*kp1*m_ad*s^6 + bden2*bp1*bp2*kp3*m_ad*s^5 + bden2*bp1*bp3*kp2*m_ad*s^5 + bden2*bp2*bp3*kp1*m_ad*s^5 + bden3*bp1*bp2*kp3*m_ad*s^4 + bden3*bp1*bp3*kp2*m_ad*s^4 + bden3*bp2*bp3*kp1*m_ad*s^4 + b_ad*bden1*bp1*mp2*mp3*s^8 + b_ad*bden1*bp2*mp1*mp3*s^8 + b_ad*bden1*bp3*mp1*mp2*s^8 + b_ad*bden2*bp1*mp2*mp3*s^7 + b_ad*bden2*bp2*mp1*mp3*s^7 + b_ad*bden2*bp3*mp1*mp2*s^7 + b_ad*bden3*bp1*mp2*mp3*s^6 + b_ad*bden3*bp2*mp1*mp3*s^6 + b_ad*bden3*bp3*mp1*mp2*s^6 + bden1*bp1*bp2*m_ad*mp3*s^8 + bden1*bp1*bp3*m_ad*mp2*s^8 + bden1*bp2*bp3*m_ad*mp1*s^8 + bden2*bp1*bp2*m_ad*mp3*s^7 + bden2*bp1*bp3*m_ad*mp2*s^7 + bden2*bp2*bp3*m_ad*mp1*s^7 + bden3*bp1*bp2*m_ad*mp3*s^6 + bden3*bp1*bp3*m_ad*mp2*s^6 + bden3*bp2*bp3*m_ad*mp1*s^6 + b_ad*bden1*kp1*kp2*kp3*s^3 + b_ad*bden2*kp1*kp2*kp3*s^2 + b_ad*bden1*kp1*kp2*mp3*s^5 + b_ad*bden1*kp1*kp3*mp2*s^5 + b_ad*bden1*kp2*kp3*mp1*s^5 + b_ad*bden2*kp1*kp2*mp3*s^4 + b_ad*bden2*kp1*kp3*mp2*s^4 + b_ad*bden2*kp2*kp3*mp1*s^4 + b_ad*bden3*kp1*kp2*mp3*s^3 + b_ad*bden3*kp1*kp3*mp2*s^3 + b_ad*bden3*kp2*kp3*mp1*s^3 + bden1*bp1*kp2*kp3*m_ad*s^5 + bden1*bp2*kp1*kp3*m_ad*s^5 + bden1*bp3*kp1*kp2*m_ad*s^5 + bden2*bp1*kp2*kp3*m_ad*s^4 + bden2*bp2*kp1*kp3*m_ad*s^4 + bden2*bp3*kp1*kp2*m_ad*s^4 + bden3*bp1*kp2*kp3*m_ad*s^3 + bden3*bp2*kp1*kp3*m_ad*s^3 + bden3*bp3*kp1*kp2*m_ad*s^3 + b_ad*bden1*kp1*mp2*mp3*s^7 + b_ad*bden1*kp2*mp1*mp3*s^7 + b_ad*bden1*kp3*mp1*mp2*s^7 + b_ad*bden2*kp1*mp2*mp3*s^6 + b_ad*bden2*kp2*mp1*mp3*s^6 + b_ad*bden2*kp3*mp1*mp2*s^6 + b_ad*bden3*kp1*mp2*mp3*s^5 + b_ad*bden3*kp2*mp1*mp3*s^5 + b_ad*bden3*kp3*mp1*mp2*s^5 + bden1*bp1*kp2*m_ad*mp3*s^7 + bden1*bp1*kp3*m_ad*mp2*s^7 + bden1*bp2*kp1*m_ad*mp3*s^7 + bden1*bp2*kp3*m_ad*mp1*s^7 + bden1*bp3*kp1*m_ad*mp2*s^7 + bden1*bp3*kp2*m_ad*mp1*s^7 + bden2*bp1*kp2*m_ad*mp3*s^6 + bden2*bp1*kp3*m_ad*mp2*s^6 + bden2*bp2*kp1*m_ad*mp3*s^6 + bden2*bp2*kp3*m_ad*mp1*s^6 + bden2*bp3*kp1*m_ad*mp2*s^6 + bden2*bp3*kp2*m_ad*mp1*s^6 + bden3*bp1*kp2*m_ad*mp3*s^5 + bden3*bp1*kp3*m_ad*mp2*s^5 + bden3*bp2*kp1*m_ad*mp3*s^5 + bden3*bp2*kp3*m_ad*mp1*s^5 + bden3*bp3*kp1*m_ad*mp2*s^5 + bden3*bp3*kp2*m_ad*mp1*s^5 + b_ad*bden1*mp1*mp2*mp3*s^9 + b_ad*bden2*mp1*mp2*mp3*s^8 + b_ad*bden3*mp1*mp2*mp3*s^7 + bden1*bp1*m_ad*mp2*mp3*s^9 + bden1*bp2*m_ad*mp1*mp3*s^9 + bden1*bp3*m_ad*mp1*mp2*s^9 + bden2*bp1*m_ad*mp2*mp3*s^8 + bden2*bp2*m_ad*mp1*mp3*s^8 + bden2*bp3*m_ad*mp1*mp2*s^8 + bden3*bp1*m_ad*mp2*mp3*s^7 + bden3*bp2*m_ad*mp1*mp3*s^7 + bden3*bp3*m_ad*mp1*mp2*s^7 + bden1*kp1*kp2*kp3*m_ad*s^4 + bden2*kp1*kp2*kp3*m_ad*s^3 + bden3*kp1*kp2*kp3*m_ad*s^2 + bden1*kp1*kp2*m_ad*mp3*s^6 + bden1*kp1*kp3*m_ad*mp2*s^6 + bden1*kp2*kp3*m_ad*mp1*s^6 + bden2*kp1*kp2*m_ad*mp3*s^5 + bden2*kp1*kp3*m_ad*mp2*s^5 + bden2*kp2*kp3*m_ad*mp1*s^5 + bden3*kp1*kp2*m_ad*mp3*s^4 + bden3*kp1*kp3*m_ad*mp2*s^4 + bden3*kp2*kp3*m_ad*mp1*s^4 + bden1*kp1*m_ad*mp2*mp3*s^8 + bden1*kp2*m_ad*mp1*mp3*s^8 + bden1*kp3*m_ad*mp1*mp2*s^8 + bden2*kp1*m_ad*mp2*mp3*s^7 + bden2*kp2*m_ad*mp1*mp3*s^7 + bden2*kp3*m_ad*mp1*mp2*s^7 + bden3*kp1*m_ad*mp2*mp3*s^6 + bden3*kp2*m_ad*mp1*mp3*s^6 + bden3*kp3*m_ad*mp1*mp2*s^6 + bden1*m_ad*mp1*mp2*mp3*s^10 + bden2*m_ad*mp1*mp2*mp3*s^9 + bden3*m_ad*mp1*mp2*mp3*s^8 + b1*bnum3*k2*ke*kp2*kp3 + b2*bnum3*k4*ke*kp1*kp3 + b3*bnum3*k6*ke*kp1*kp2 + b1*bnum3*k2*kh*kp2*kp3 + b2*bnum3*k4*kh*kp1*kp3 + b3*bnum3*k6*kh*kp1*kp2 + b_ad*bden3*kp1*kp2*kp3*s + b1*bnum3*bp2*k2*ke*kp3*s + b1*bnum3*bp3*k2*ke*kp2*s + b2*bnum3*bp1*k4*ke*kp3*s + b2*bnum3*bp3*k4*ke*kp1*s + b3*bnum3*bp1*k6*ke*kp2*s + b3*bnum3*bp2*k6*ke*kp1*s + b1*bh*bnum3*k2*kp2*kp3*s + b1*bnum3*bp2*k2*kh*kp3*s + b1*bnum3*bp3*k2*kh*kp2*s + b2*bh*bnum3*k4*kp1*kp3*s + b2*bnum3*bp1*k4*kh*kp3*s + b2*bnum3*bp3*k4*kh*kp1*s + b3*bh*bnum3*k6*kp1*kp2*s + b3*bnum3*bp1*k6*kh*kp2*s + b3*bnum3*bp2*k6*kh*kp1*s + a1*bnum3*k2*ke*kp2*kp3*s + a2*bnum3*k4*ke*kp1*kp3*s + a3*bnum3*k6*ke*kp1*kp2*s + a1*bnum3*k2*kh*kp2*kp3*s + a2*bnum3*k4*kh*kp1*kp3*s + a3*bnum3*k6*kh*kp1*kp2*s + b1*bnum2*k2*ke*kp2*kp3*s + b2*bnum2*k4*ke*kp1*kp3*s + b3*bnum2*k6*ke*kp1*kp2*s + b1*bnum2*k2*kh*kp2*kp3*s + b2*bnum2*k4*kh*kp1*kp3*s + b3*bnum2*k6*kh*kp1*kp2*s + a1*bh*bnum1*bp2*bp3*k2*s^6 + a1*bh*bnum2*bp2*bp3*k2*s^5 + a1*bh*bnum3*bp2*bp3*k2*s^4 + a2*bh*bnum1*bp1*bp3*k4*s^6 + a2*bh*bnum2*bp1*bp3*k4*s^5 + a2*bh*bnum3*bp1*bp3*k4*s^4 + a3*bh*bnum1*bp1*bp2*k6*s^6 + a3*bh*bnum2*bp1*bp2*k6*s^5 + a3*bh*bnum3*bp1*bp2*k6*s^4 + b1*bh*bnum1*bp2*bp3*k2*s^5 + b1*bh*bnum2*bp2*bp3*k2*s^4 + b1*bh*bnum3*bp2*bp3*k2*s^3 + b2*bh*bnum1*bp1*bp3*k4*s^5 + b2*bh*bnum2*bp1*bp3*k4*s^4 + b2*bh*bnum3*bp1*bp3*k4*s^3 + b3*bh*bnum1*bp1*bp2*k6*s^5 + b3*bh*bnum2*bp1*bp2*k6*s^4 + b3*bh*bnum3*bp1*bp2*k6*s^3 + a1*bnum1*bp2*bp3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kp3*mp2 + b1*bnum3*k2*kp2*kp3*mh + b2*bnum3*k4*kh*kp1*mp3 + b2*bnum3*k4*kh*kp3*mp1 + b2*bnum3*k4*kp1*kp3*mh + b3*bnum3*k6*kh*kp1*mp2 + b3*bnum3*k6*kh*kp2*mp1 + b3*bnum3*k6*kp1*kp2*mh;
DS3 = b_ad*bden3*bp1*bp2*kp3 + b_ad*bden3*bp1*bp3*kp2 + b_ad*bden3*bp2*bp3*kp1 + b_ad*bden2*bp1*kp2*kp3 + b_ad*bden2*bp2*kp1*kp3 + b_ad*bden2*bp3*kp1*kp2 + b_ad*bden1*kp1*kp2*kp3 + b_ad*bden3*kp1*kp2*mp3 + b_ad*bden3*kp1*kp3*mp2 + b_ad*bden3*kp2*kp3*mp1 + bden3*bp1*kp2*kp3*m_ad + bden3*bp2*kp1*kp3*m_ad + bden3*bp3*kp1*kp2*m_ad + bden2*kp1*kp2*kp3*m_ad + b1*bh*bnum3*bp2*bp3*k2 + b2*bh*bnum3*bp1*bp3*k4 + b3*bh*bnum3*bp1*bp2*k6 + a1*bnum3*bp2*bp3*k2*ke + a2*bnum3*bp1*bp3*k4*ke + a3*bnum3*bp1*bp2*k6*ke + a1*bh*bnum3*bp2*k2*kp3 + a1*bh*bnum3*bp3*k2*kp2 + a1*bnum3*bp2*bp3*k2*kh + a2*bh*bnum3*bp1*k4*kp3 + a2*bh*bnum3*bp3*k4*kp1 + a2*bnum3*bp1*bp3*k4*kh + a3*bh*bnum3*bp1*k6*kp2 + a3*bh*bnum3*bp2*k6*kp1 + a3*bnum3*bp1*bp2*k6*kh + b1*bnum2*bp2*bp3*k2*ke + b2*bnum2*bp1*bp3*k4*ke + b3*bnum2*bp1*bp2*k6*ke + b1*bh*bnum2*bp2*k2*kp3 + b1*bh*bnum2*bp3*k2*kp2 + b1*bnum2*bp2*bp3*k2*kh + b2*bh*bnum2*bp1*k4*kp3 + b2*bh*bnum2*bp3*k4*kp1 + b2*bnum2*bp1*bp3*k4*kh + b3*bh*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*mh + b3*bnum2*k6*kh*kp1*mp2 + b3*bnum2*k6*kh*kp2*mp1 + b3*bnum2*k6*kp1*kp2*mh;
DS4 = b_ad*bden3*bp1*bp2*bp3 + b_ad*bden2*bp1*bp2*kp3 + b_ad*bden2*bp1*bp3*kp2 + b_ad*bden2*bp2*bp3*kp1 + b_ad*bden1*bp1*kp2*kp3 + b_ad*bden1*bp2*kp1*kp3 + b_ad*bden1*bp3*kp1*kp2 + b_ad*bden3*bp1*kp2*mp3 + b_ad*bden3*bp1*kp3*mp2 + b_ad*bden3*bp2*kp1*mp3 + b_ad*bden3*bp2*kp3*mp1 + b_ad*bden3*bp3*kp1*mp2 + b_ad*bden3*bp3*kp2*mp1 + bden3*bp1*bp2*kp3*m_ad + bden3*bp1*bp3*kp2*m_ad + bden3*bp2*bp3*kp1*m_ad + b_ad*bden2*kp1*kp2*mp3 + b_ad*bden2*kp1*kp3*mp2 + b_ad*bden2*kp2*kp3*mp1 + bden2*bp1*kp2*kp3*m_ad + bden2*bp2*kp1*kp3*m_ad + bden2*bp3*kp1*kp2*m_ad + bden1*kp1*kp2*kp3*m_ad + bden3*kp1*kp2*m_ad*mp3 + bden3*kp1*kp3*m_ad*mp2 + bden3*kp2*kp3*m_ad*mp1 + a1*bh*bnum3*bp2*bp3*k2 + a2*bh*bnum3*bp1*bp3*k4 + a3*bh*bnum3*bp1*bp2*k6 + b1*bh*bnum2*bp2*bp3*k2 + b2*bh*bnum2*bp1*bp3*k4 + b3*bh*bnum2*bp1*bp2*k6 + a1*bnum2*bp2*bp3*k2*ke + a2*bnum2*bp1*bp3*k4*ke + a3*bnum2*bp1*bp2*k6*ke + a1*bh*bnum2*bp2*k2*kp3 + a1*bh*bnum2*bp3*k2*kp2 + a1*bnum2*bp2*bp3*k2*kh + a2*bh*bnum2*bp1*k4*kp3 + a2*bh*bnum2*bp3*k4*kp1 + a2*bnum2*bp1*bp3*k4*kh + a3*bh*bnum2*bp1*k6*kp2 + a3*bh*bnum2*bp2*k6*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mp2 + a3*bnum2*k6*ke*kp2*mp1 + a1*bnum2*k2*kh*kp2*mp3 + a1*bnum2*k2*kh*kp3*mp2 + a1*bnum2*k2*kp2*kp3*mh + a2*bnum2*k4*kh*kp1*mp3 + a2*bnum2*k4*kh*kp3*mp1 + a2*bnum2*k4*kp1*kp3*mh + a3*bnum2*k6*kh*kp1*mp2 + a3*bnum2*k6*kh*kp2*mp1 + a3*bnum2*k6*kp1*kp2*mh + b1*bnum1*k2*ke*kp2*mp3 + b1*bnum1*k2*ke*kp3*mp2 + b2*bnum1*k4*ke*kp1*mp3 + b2*bnum1*k4*ke*kp3*mp1 + b3*bnum1*k6*ke*kp1*mp2 + b3*bnum1*k6*ke*kp2*mp1 + b1*bnum1*k2*kh*kp2*mp3 + b1*bnum1*k2*kh*kp3*mp2 + b1*bnum1*k2*kp2*kp3*mh + b2*bnum1*k4*kh*kp1*mp3 + b2*bnum1*k4*kh*kp3*mp1 + b2*bnum1*k4*kp1*kp3*mh + b3*bnum1*k6*kh*kp1*mp2 + b3*bnum1*k6*kh*kp2*mp1 + b3*bnum1*k6*kp1*kp2*mh + b1*bnum3*k2*ke*mp2*mp3 + b2*bnum3*k4*ke*mp1*mp3 + b3*bnum3*k6*ke*mp1*mp2 + b1*bnum3*k2*kh*mp2*mp3 + b1*bnum3*k2*kp2*mh*mp3 + b1*bnum3*k2*kp3*mh*mp2 + b2*bnum3*k4*kh*mp1*mp3 + b2*bnum3*k4*kp1*mh*mp3 + b2*bnum3*k4*kp3*mh*mp1 + b3*bnum3*k6*kh*mp1*mp2 + b3*bnum3*k6*kp1*mh*mp2 + b3*bnum3*k6*kp2*mh*mp1;
DS5 = b_ad*bden2*bp1*bp2*bp3 + b_ad*bden1*bp1*bp2*kp3 + b_ad*bden1*bp1*bp3*kp2 + b_ad*bden1*bp2*bp3*kp1 + b_ad*bden3*bp1*bp2*mp3 + b_ad*bden3*bp1*bp3*mp2 + b_ad*bden3*bp2*bp3*mp1 + bden3*bp1*bp2*bp3*m_ad + b_ad*bden2*bp1*kp2*mp3 + b_ad*bden2*bp1*kp3*mp2 + b_ad*bden2*bp2*kp1*mp3 + b_ad*bden2*bp2*kp3*mp1 + b_ad*bden2*bp3*kp1*mp2 + b_ad*bden2*bp3*kp2*mp1 + bden2*bp1*bp2*kp3*m_ad + bden2*bp1*bp3*kp2*m_ad + bden2*bp2*bp3*kp1*m_ad + b_ad*bden1*kp1*kp2*mp3 + b_ad*bden1*kp1*kp3*mp2 + b_ad*bden1*kp2*kp3*mp1 + bden1*bp1*kp2*kp3*m_ad + bden1*bp2*kp1*kp3*m_ad + bden1*bp3*kp1*kp2*m_ad + b_ad*bden3*kp1*mp2*mp3 + b_ad*bden3*kp2*mp1*mp3 + b_ad*bden3*kp3*mp1*mp2 + bden3*bp1*kp2*m_ad*mp3 + bden3*bp1*kp3*m_ad*mp2 + bden3*bp2*kp1*m_ad*mp3 + bden3*bp2*kp3*m_ad*mp1 + bden3*bp3*kp1*m_ad*mp2 + bden3*bp3*kp2*m_ad*mp1 + bden2*kp1*kp2*m_ad*mp3 + bden2*kp1*kp3*m_ad*mp2 + bden2*kp2*kp3*m_ad*mp1 + a1*bh*bnum2*bp2*bp3*k2 + a2*bh*bnum2*bp1*bp3*k4 + a3*bh*bnum2*bp1*bp2*k6 + b1*bh*bnum1*bp2*bp3*k2 + b2*bh*bnum1*bp1*bp3*k4 + b3*bh*bnum1*bp1*bp2*k6 + a1*bnum1*bp2*bp3*k2*ke + a2*bnum1*bp1*bp3*k4*ke + a3*bnum1*bp1*bp2*k6*ke + a1*bh*bnum1*bp2*k2*kp3 + a1*bh*bnum1*bp3*k2*kp2 + a1*bnum1*bp2*bp3*k2*kh + a2*bh*bnum1*bp1*k4*kp3 + a2*bh*bnum1*bp3*k4*kp1 + a2*bnum1*bp1*bp3*k4*kh + a3*bh*bnum1*bp1*k6*kp2 + a3*bh*bnum1*bp2*k6*kp1 + a3*bnum1*bp1*bp2*k6*kh + a1*bh*bnum3*bp2*k2*mp3 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 + a2*bnum3*k4*ke*mp1*mp3 + a3*bnum3*k6*ke*mp1*mp2 + a1*bnum3*k2*kh*mp2*mp3 + a1*bnum3*k2*kp2*mh*mp3 + a1*bnum3*k2*kp3*mh*mp2 + a2*bnum3*k4*kh*mp1*mp3 + a2*bnum3*k4*kp1*mh*mp3 + a2*bnum3*k4*kp3*mh*mp1 + a3*bnum3*k6*kh*mp1*mp2 + a3*bnum3*k6*kp1*mh*mp2 + a3*bnum3*k6*kp2*mh*mp1 + b1*bnum2*k2*ke*mp2*mp3 + b2*bnum2*k4*ke*mp1*mp3 + b3*bnum2*k6*ke*mp1*mp2 + b1*bnum2*k2*kh*mp2*mp3 + b1*bnum2*k2*kp2*mh*mp3 + b1*bnum2*k2*kp3*mh*mp2 + b2*bnum2*k4*kh*mp1*mp3 + b2*bnum2*k4*kp1*mh*mp3 + b2*bnum2*k4*kp3*mh*mp1 + b3*bnum2*k6*kh*mp1*mp2 + b3*bnum2*k6*kp1*mh*mp2 + b3*bnum2*k6*kp2*mh*mp1;
DS6 = b_ad*bden1*bp1*bp2*bp3 + b_ad*bden2*bp1*bp2*mp3 + b_ad*bden2*bp1*bp3*mp2 + b_ad*bden2*bp2*bp3*mp1 + bden2*bp1*bp2*bp3*m_ad + b_ad*bden1*bp1*kp2*mp3 + b_ad*bden1*bp1*kp3*mp2 + b_ad*bden1*bp2*kp1*mp3 + b_ad*bden1*bp2*kp3*mp1 + b_ad*bden1*bp3*kp1*mp2 + b_ad*bden1*bp3*kp2*mp1 + bden1*bp1*bp2*kp3*m_ad + bden1*bp1*bp3*kp2*m_ad + bden1*bp2*bp3*kp1*m_ad + b_ad*bden3*bp1*mp2*mp3 + b_ad*bden3*bp2*mp1*mp3 + b_ad*bden3*bp3*mp1*mp2 + bden3*bp1*bp2*m_ad*mp3 + bden3*bp1*bp3*m_ad*mp2 + bden3*bp2*bp3*m_ad*mp1 + b_ad*bden2*kp1*mp2*mp3 + b_ad*bden2*kp2*mp1*mp3 + b_ad*bden2*kp3*mp1*mp2 + bden2*bp1*kp2*m_ad*mp3 + bden2*bp1*kp3*m_ad*mp2 + bden2*bp2*kp1*m_ad*mp3 + bden2*bp2*kp3*m_ad*mp1 + bden2*bp3*kp1*m_ad*mp2 + bden2*bp3*kp2*m_ad*mp1 + bden1*kp1*kp2*m_ad*mp3 + bden1*kp1*kp3*m_ad*mp2 + bden1*kp2*kp3*m_ad*mp1 + bden3*kp1*m_ad*mp2*mp3 + bden3*kp2*m_ad*mp1*mp3 + bden3*kp3*m_ad*mp1*mp2 + a1*bh*bnum1*bp2*bp3*k2 + a2*bh*bnum1*bp1*bp3*k4 + a3*bh*bnum1*bp1*bp2*k6 + a1*bh*bnum2*bp2*k2*mp3 + a1*bh*bnum2*bp3*k2*mp2 + a1*bnum2*bp2*bp3*k2*mh + a2*bh*bnum2*bp1*k4*mp3 + a2*bh*bnum2*bp3*k4*mp1 + a2*bnum2*bp1*bp3*k4*mh + a3*bh*bnum2*bp1*k6*mp2 + a3*bh*bnum2*bp2*k6*mp1 + a3*bnum2*bp1*bp2*k6*mh + b1*bh*bnum1*bp2*k2*mp3 + b1*bh*bnum1*bp3*k2*mp2 + b1*bnum1*bp2*bp3*k2*mh + b2*bh*bnum1*bp1*k4*mp3 + b2*bh*bnum1*bp3*k4*mp1 + b2*bnum1*bp1*bp3*k4*mh + b3*bh*bnum1*bp1*k6*mp2 + b3*bh*bnum1*bp2*k6*mp1 + b3*bnum1*bp1*bp2*k6*mh + a1*bnum1*bp2*k2*ke*mp3 + a1*bnum1*bp3*k2*ke*mp2 + a2*bnum1*bp1*k4*ke*mp3 + a2*bnum1*bp3*k4*ke*mp1 + a3*bnum1*bp1*k6*ke*mp2 + a3*bnum1*bp2*k6*ke*mp1 + a1*bh*bnum1*k2*kp2*mp3 + a1*bh*bnum1*k2*kp3*mp2 + a1*bnum1*bp2*k2*kh*mp3 + a1*bnum1*bp2*k2*kp3*mh + a1*bnum1*bp3*k2*kh*mp2 + a1*bnum1*bp3*k2*kp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ke*mp1*mp2 + b1*bnum1*k2*kh*mp2*mp3 + b1*bnum1*k2*kp2*mh*mp3 + b1*bnum1*k2*kp3*mh*mp2 + b2*bnum1*k4*kh*mp1*mp3 + b2*bnum1*k4*kp1*mh*mp3 + b2*bnum1*k4*kp3*mh*mp1 + b3*bnum1*k6*kh*mp1*mp2 + b3*bnum1*k6*kp1*mh*mp2 + b3*bnum1*k6*kp2*mh*mp1 + b1*bnum3*k2*mh*mp2*mp3 + b2*bnum3*k4*mh*mp1*mp3 + b3*bnum3*k6*mh*mp1*mp2;
DS7 = b_ad*bden1*bp1*bp2*mp3 + b_ad*bden1*bp1*bp3*mp2 + b_ad*bden1*bp2*bp3*mp1 + bden1*bp1*bp2*bp3*m_ad + b_ad*bden2*bp1*mp2*mp3 + b_ad*bden2*bp2*mp1*mp3 + b_ad*bden2*bp3*mp1*mp2 + bden2*bp1*bp2*m_ad*mp3 + bden2*bp1*bp3*m_ad*mp2 + bden2*bp2*bp3*m_ad*mp1 + b_ad*bden1*kp1*mp2*mp3 + b_ad*bden1*kp2*mp1*mp3 + b_ad*bden1*kp3*mp1*mp2 + bden1*bp1*kp2*m_ad*mp3 + bden1*bp1*kp3*m_ad*mp2 + bden1*bp2*kp1*m_ad*mp3 + bden1*bp2*kp3*m_ad*mp1 + bden1*bp3*kp1*m_ad*mp2 + bden1*bp3*kp2*m_ad*mp1 + b_ad*bden3*mp1*mp2*mp3 + bden3*bp1*m_ad*mp2*mp3 + bden3*bp2*m_ad*mp1*mp3 + bden3*bp3*m_ad*mp1*mp2 + bden2*kp1*m_ad*mp2*mp3 + bden2*kp2*m_ad*mp1*mp3 + bden2*kp3*m_ad*mp1*mp2 + a1*bh*bnum1*bp2*k2*mp3 + a1*bh*bnum1*bp3*k2*mp2 + a1*bnum1*bp2*bp3*k2*mh + a2*bh*bnum1*bp1*k4*mp3 + a2*bh*bnum1*bp3*k4*mp1 + a2*bnum1*bp1*bp3*k4*mh + a3*bh*bnum1*bp1*k6*mp2 + a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2*mp3 + bden2*bp1*m_ad*mp2*mp3 + bden2*bp2*m_ad*mp1*mp3 + bden2*bp3*m_ad*mp1*mp2 + bden1*kp1*m_ad*mp2*mp3 + bden1*kp2*m_ad*mp1*mp3 + bden1*kp3*m_ad*mp1*mp2 + bden3*m_ad*mp1*mp2*mp3 + a1*bh*bnum1*k2*mp2*mp3 + a1*bnum1*bp2*k2*mh*mp3 + a1*bnum1*bp3*k2*mh*mp2 + a2*bh*bnum1*k4*mp1*mp3 + a2*bnum1*bp1*k4*mh*mp3 + a2*bnum1*bp3*k4*mh*mp1 + a3*bh*bnum1*k6*mp1*mp2 + a3*bnum1*bp1*k6*mh*mp2 + a3*bnum1*bp2*k6*mh*mp1 + a1*bnum2*k2*mh*mp2*mp3 + a2*bnum2*k4*mh*mp1*mp3 + a3*bnum2*k6*mh*mp1*mp2 + b1*bnum1*k2*mh*mp2*mp3 + b2*bnum1*k4*mh*mp1*mp3 + b3*bnum1*k6*mh*mp1*mp2;
DS9 = b_ad*bden1*mp1*mp2*mp3 + bden1*bp1*m_ad*mp2*mp3 + bden1*bp2*m_ad*mp1*mp3 + bden1*bp3*m_ad*mp1*mp2 + bden2*m_ad*mp1*mp2*mp3 + a1*bnum1*k2*mh*mp2*mp3 + a2*bnum1*k4*mh*mp1*mp3 + a3*bnum1*k6*mh*mp1*mp2;
DS10 = bden1*m_ad*mp1*mp2*mp3;


%Numerator is an 8th order
NS0 = 0;
NS1 = bden3*(b1*k2*kp2*kp3 + b2*k4*kp1*kp3 + b3*k6*kp1*kp2);
NS2 = bden3*(a1*k2*kp2*kp3 + a2*k4*kp1*kp3 + a3*k6*kp1*kp2 + b1*bp2*k2*kp3 + b1*bp3*k2*kp2 + b2*bp1*k4*kp3 + b2*bp3*k4*kp1 + b3*bp1*k6*kp2 + b3*bp2*k6*kp1) + bden2*(b1*k2*kp2*kp3 + b2*k4*kp1*kp3 + b3*k6*kp1*kp2);
NS3 = bden2*(a1*k2*kp2*kp3 + a2*k4*kp1*k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+ b2*k4*mp1*mp3 + b3*k6*mp1*mp2 + a1*bp2*k2*mp3 + a1*bp3*k2*mp2 + a2*bp1*k4*mp3 + a2*bp3*k4*mp1 + a3*bp1*k6*mp2 + a3*bp2*k6*mp1) + bden2*(a1*k2*mp2*mp3 + a2*k4*mp1*mp3 + a3*k6*mp1*mp2);
NS8 = bden1*(a1*k2*mp2*mp3 + a2*k4*mp1*mp3 + a3*k6*mp1*mp2);




%% Apply the values from the paper to the symbolic function
mp1=1;
bp1=129.04;
kp1 = 752.7;
mp2 = 1;
bp2= 72.97;
kp2= 1723;
mp3 = 1;
bp3 = 95.39;
kp3 = 6513;
mh = 5;
bh = 41;
kh = 401;
ke = 16599;
a1=25.69;
b1=749.3;
a2=65.99;
b2 =1679;
a3 =63.77;
b3=6564;
[bnum,bden] = butter(2,5/(30/2));
bnum1 = bnum(1);
bnum2 = bnum(2);
bnum3 = bnum(3);
bden1 = bden(1);
bden2 = bden(2);
bden3 = bden(3);

k2   =  -0.1896;
k4   =  1.6550;
k6   =  -0.4654;

m_ad = 50;
b_ad = 900;
%% Make the symbolic function appear more manageable
VDS0 = vpa(eval(DS0))
VDS1 = vpa(eval(DS1))
VDS2 = vpa(eval(DS2))
VDS3 = vpa(eval(DS3))
VDS4 = vpa(eval(DS4))
VDS5 = vpa(eval(DS5))
VDS6 = vpa(eval(DS6))
VDS7 = vpa(eval(DS7))
VDS8 = vpa(eval(DS8))
VDS9 = vpa(eval(DS9));
VDS10 = vpa(eval(DS10));

VDS0 =21261399472196.24609375;
VDS1 =2030661611.8014128143008105498168*b_ad + 47949294906007.275762557983398438;
VDS2 =2030661611.8014132976531982421875*m_ad - 4774822762.6207298610944516119581*b_ad + 32408242353192.444770203903317451;
VDS3 =7275324064.0530543483563131864256*b_ad - 4774822762.620730355381965637207*m_ad + 6020904970365.1409040717408061028;
VDS4 =1864921570.4989068050254456076256*b_ad + 7275324064.0530547559610567986965*m_ad + 307402224757.44137989897171792109;
VDS5 =103513306.51251661538944404178597*b_ad + 1864921570.4989066019788879202679*m_ad + 6982873848.042935041883708890964;
VDS6 =2704011.1156877219385823286339487*b_ad + 103513306.51251660590529013461492*m_ad + 140333460.89426495867903099679097;
VDS7 =37490.274408007260285118178444463*b_ad + 2704011.1156877217273759583804349*m_ad + 1647313.2932705096305219250041318;
VDS8 =296.77979589711327110812533192075*b_ad + 37490.274408007258229824643080974*m_ad + 13984.612338569021811274240008061;
VDS9 = b_ad + 296.77979589711327110812533192075*m_ad + 57.883701639767129787372823557234;
VDS10 =m_ad;
%Numerator is an 8th order
VNS0 = 0;
VNS1 = eval(NS1);
VNS2 = eval(NS2);
VNS3 = eval(NS3);
VNS4 = eval(NS4);
VNS5 = eval(NS5);
VNS6 = eval(NS6);
VNS7 = eval(NS7);
VNS8 = eval(NS8);

%% evaluate the stability for the case with no impedance applied
masses = 0:5:200;
dampers = 0:10:1000;
unstable = zeros(length(masses),length(dampers))
for massval = 1:length(masses)

    for dampval = 1:length(dampers)
        dampval
        mad = masses(massval);
        bad = dampers(dampval);

        EDS0 =21261399472196.24609375;
        EDS1 =2030661611.8014128143008105498168*bad + 47949294906007.275762557983398438;
        EDS2 =2030661611.8014132976531982421875*mad - 4774822762.6207298610944516119581*bad + 32408242353192.444770203903317451;
        EDS3 =7275324064.0530543483563131864256*bad - 4774822762.620730355381965637207*mad + 6020904970365.1409040717408061028;
        EDS4 =1864921570.4989068050254456076256*bad + 7275324064.0530547559610567986965*mad + 307402224757.44137989897171792109;
        EDS5 =103513306.51251661538944404178597*bad + 1864921570.4989066019788879202679*mad + 6982873848.042935041883708890964;
        EDS6 =2704011.1156877219385823286339487*bad + 103513306.51251660590529013461492*mad + 140333460.89426495867903099679097;
        EDS7 =37490.274408007260285118178444463*bad + 2704011.1156877217273759583804349*mad + 1647313.2932705096305219250041318;
        EDS8 =296.77979589711327110812533192075*bad + 37490.274408007258229824643080974*mad + 13984.612338569021811274240008061;
        EDS9 = bad + 296.77979589711327110812533192075*mad + 57.883701639767129787372823557234;
        EDS10 =mad;



        denominator = vpa((EDS10)*s^10 + (EDS9)*s^9 + (EDS8)*s^8 + (EDS7)*s^7 + (EDS6)*s^6 + (EDS5)*s^5 + (EDS4)*s^4 + (EDS3)*s^3 + (EDS2)*s^2 + (EDS1)*s +(EDS0));

        % Grab the poles and evaluate if any poles are unstable
        poles = solve(denominator,s);
        realpoles = real(poles);
        unstable(massval,dampval) = ~(any(realpoles(:)>0));
    end
end
%% Apply the values to the symbolic transfer function this time including Impedance

mp1=1;
bp1=129.04;
kp1 = 752.7;
mp2 = 1;
bp2= 72.97;
kp2= 1723;
mp3 = 1;
bp3 = 95.39;
kp3 = 6513;
mh = 5;
bh = 41;
kh = 401;
ke = 16599;
a1=25.69;
b1=749.3;
a2=65.99;
b2 =1679;
a3 =63.77;
b3=6564;
[bnum,bden] = butter(2,5/(30/2));
bnum1 = bnum(1);
bnum2 = bnum(2);
bnum3 = bnum(3);
bden1 = bden(1);
bden2 = bden(2);
bden3 = bden(3);
k2   =  -0.1896;
k4   =  1.6550;
k6   =  -0.4654;

masses = 0:5:200;
dampers = 0:10:1000;
unstable = zeros(length(masses),length(dampers),8);
% Grab the type of impedance then run through the stability analysis
for impedance_type =1:8
    switch impedance_type
        case 1 %Extreme Case set 1 full Ze and Zh
            mh = 5;
            bh = 41;
            kh = 401;
            me = 0;
            be = 0;
            ke = 16599;
            masses = 0:5:200;
            dampers = 0:10:1000;
        case 2 %Extreme Case set 2 full Ze and Zh with only mass
            mh = 5;
            bh = 0;
            kh = 401;
            me = 0;
            be = 0;
            ke = 16599;
        case 3 %Extreme Case set 3 full Ze no Zh mass
            mh = 0;
            bh = 41;
            kh = 401;
            me = 0;
            be = 0;
            ke = 16599;
        case 4 %Extreme Case set 4 full Ze no Zh mass or damping
            mh = 0;
            bh = 0;
            kh = 401;
            me = 0;
            be = 0;
            ke = 16599;
        case 5 %Extreme Case set 5 no Ze only Zh mass and damping
            mh = 5;
            bh = 41;
            kh = 401;
            me = 0;
            be = 0;
            ke = 0;
            masses = linspace(0,25,41);
            dampers = linspace(0,30,101);
        case 6 %Extreme Case set 6 no Ze only Zh mass
            mh = 5;
            bh = 0;
            kh = 401;
            me = 0;
            be = 0;
            ke = 0;
        case 7 %Extreme Case set 7 no Ze only Zh damping
            mh = 0;
            bh = 41;
            kh = 401;
            me = 0;
            be = 0;
            ke = 0;
        case 8 %Extreme Case set 8 no Ze or Zh
            mh = 0;
            bh = 0;
            kh = 401;
            me = 0;
            be = 0;
            ke = 0;
    end
    for massval = 1:length(masses)

        for dampval = 1:length(dampers)
            dampval
            m_ad = masses(massval);
            b_ad = dampers(dampval);

            %Denominator is a 10th order
            DS0 = b1*bnum3*k2*ke*kp2*kp3 + b2*bnum3*k4*ke*kp1*kp3 + b3*bnum3*k6*ke*kp1*kp2 + b1*bnum3*k2*kh*kp2*kp3 + b2*bnum3*k4*kh*kp1*kp3 + b3*bnum3*k6*kh*kp1*kp2;
            DS1 = b_ad*bden3*kp1*kp2*kp3 + b1*bnum3*bp2*k2*ke*kp3 + b1*bnum3*bp3*k2*ke*kp2 + b2*bnum3*bp1*k4*ke*kp3 + b2*bnum3*bp3*k4*ke*kp1 + b3*bnum3*bp1*k6*ke*kp2 + b3*bnum3*bp2*k6*ke*kp1 + b1*bh*bnum3*k2*kp2*kp3 + b1*bnum3*bp2*k2*kh*kp3 + b1*bnum3*bp3*k2*kh*kp2 + b2*bh*bnum3*k4*kp1*kp3 + b2*bnum3*bp1*k4*kh*kp3 + b2*bnum3*bp3*k4*kh*kp1 + b3*bh*bnum3*k6*kp1*kp2 + b3*bnum3*bp1*k6*kh*kp2 + b3*bnum3*bp2*k6*kh*kp1 + a1*bnum3*k2*ke*kp2*kp3 + a2*bnum3*k4*ke*kp1*kp3 + a3*bnum3*k6*ke*kp1*kp2 + a1*bnum3*k2*kh*kp2*kp3 + a2*bnum3*k4*kh*kp1*kp3 + a3*bnum3*k6*kh*kp1*kp2 + b1*bnum2*k2*ke*kp2*kp3 + b2*bnum2*k4*ke*kp1*kp3 + b3*bnum2*k6*ke*kp1*kp2 + b1*bnum2*k2*kh*kp2*kp3 + b2*bnum2*k4*kh*kp1*kp3 + b3*bnum2*k6*kh*kp1*kp2;
            DS2 = b_ad*bden3*bp1*kp2*kp3 + b_ad*bden3*bp2*kp1*kp3 + b_ad*bden3*bp3*kp1*kp2 + b_ad*bden2*kp1*kp2*kp3 + bden3*kp1*kp2*kp3*m_ad + b1*bnum3*bp2*bp3*k2*ke + b2*bnum3*bp1*bp3*k4*ke + b3*bnum3*bp1*bp2*k6*ke + b1*bh*bnum3*bp2*k2*kp3 + b1*bh*bnum3*bp3*k2*kp2 + b1*bnum3*bp2*bp3*k2*kh + b2*bh*bnum3*bp1*k4*kp3 + b2*bh*bnum3*bp3*k4*kp1 + b2*bnum3*bp1*bp3*k4*kh + b3*bh*bnum3*bp1*k6*kp2 + b3*bh*bnum3*bp2*k6*kp1 + b3*bnum3*bp1*bp2*k6*kh + a1*bnum3*bp2*k2*ke*kp3 + a1*bnum3*bp3*k2*ke*kp2 + a2*bnum3*bp1*k4*ke*kp3 + a2*bnum3*bp3*k4*ke*kp1 + a3*bnum3*bp1*k6*ke*kp2 + a3*bnum3*bp2*k6*ke*kp1 + a1*bh*bnum3*k2*kp2*kp3 + a1*bnum3*bp2*k2*kh*kp3 + a1*bnum3*bp3*k2*kh*kp2 + a2*bh*bnum3*k4*kp1*kp3 + a2*bnum3*bp1*k4*kh*kp3 + a2*bnum3*bp3*k4*kh*kp1 + a3*bh*bnum3*k6*kp1*kp2 + a3*bnum3*bp1*k6*kh*kp2 + a3*bnum3*bp2*k6*kh*kp1 + b1*bnum2*bp2*k2*ke*kp3 + b1*bnum2*bp3*k2*ke*kp2 + b2*bnum2*bp1*k4*ke*kp3 + b2*bnum2*bp3*k4*ke*kp1 + b3*bnum2*bp1*k6*ke*kp2 + b3*bnum2*bp2*k6*ke*kp1 + b1*bh*bnum2*k2*kp2*kp3 + b1*bnum2*bp2*k2*kh*kp3 + b1*bnum2*bp3*k2*kh*kp2 + b2*bh*bnum2*k4*kp1*kp3 + b2*bnum2*bp1*k4*kh*kp3 + b2*bnum2*bp3*k4*kh*kp1 + b3*bh*bnum2*k6*kp1*kp2 + b3*bnum2*bp1*k6*kh*kp2 + b3*bnum2*bp2*k6*kh*kp1 + a1*bnum2*k2*ke*kp2*kp3 + a2*bnum2*k4*ke*kp1*kp3 + a3*bnum2*k6*ke*kp1*kp2 + a1*bnum2*k2*kh*kp2*kp3 + a2*bnum2*k4*kh*kp1*kp3 + a3*bnum2*k6*kh*kp1*kp2 + b1*bnum1*k2*ke*kp2*kp3 + b2*bnum1*k4*ke*kp1*kp3 + b3*bnum1*k6*ke*kp1*kp2 + b1*bnum1*k2*kh*kp2*kp3 + b2*bnum1*k4*kh*kp1*kp3 + b3*bnum1*k6*kh*kp1*kp2 + b1*bnum3*k2*ke*kp2*mp3 + b1*bnum3*k2*ke*kp3*mp2 + b2*bnum3*k4*ke*kp1*mp3 + b2*bnum3*k4*ke*kp3*mp1 + b3*bnum3*k6*ke*kp1*mp2 + b3*bnum3*k6*ke*kp2*mp1 + b1*bnum3*k2*kh*kp2*mp3 + b1*bnum3*k2*kh*kp3*mp2 + b1*bnum3*k2*kp2*kp3*mh + b2*bnum3*k4*kh*kp1*mp3 + b2*bnum3*k4*kh*kp3*mp1 + b2*bnum3*k4*kp1*kp3*mh + b3*bnum3*k6*kh*kp1*mp2 + b3*bnum3*k6*kh*kp2*mp1 + b3*bnum3*k6*kp1*kp2*mh;
            DS3 = b_ad*bden3*bp1*bp2*kp3 + b_ad*bden3*bp1*bp3*kp2 + b_ad*bden3*bp2*bp3*kp1 + b_ad*bden2*bp1*kp2*kp3 + b_ad*bden2*bp2*kp1*kp3 + b_ad*bden2*bp3*kp1*kp2 + b_ad*bden1*kp1*kp2*kp3 + b_ad*bden3*kp1*kp2*mp3 + b_ad*bden3*kp1*kp3*mp2 + b_ad*bden3*kp2*kp3*mp1 + bden3*bp1*kp2*kp3*m_ad + bden3*bp2*kp1*kp3*m_ad + bden3*bp3*kp1*kp2*m_ad + bden2*kp1*kp2*kp3*m_ad + b1*bh*bnum3*bp2*bp3*k2 + b2*bh*bnum3*bp1*bp3*k4 + b3*bh*bnum3*bp1*bp2*k6 + a1*bnum3*bp2*bp3*k2*ke + a2*bnum3*bp1*bp3*k4*ke + a3*bnum3*bp1*bp2*k6*ke + a1*bh*bnum3*bp2*k2*kp3 + a1*bh*bnum3*bp3*k2*kp2 + a1*bnum3*bp2*bp3*k2*kh + a2*bh*bnum3*bp1*k4*kp3 + a2*bh*bnum3*bp3*k4*kp1 + a2*bnum3*bp1*bp3*k4*kh + a3*bh*bnum3*bp1*k6*kp2 + a3*bh*bnum3*bp2*k6*kp1 + a3*bnum3*bp1*bp2*k6*kh + b1*bnum2*bp2*bp3*k2*ke + b2*bnum2*bp1*bp3*k4*ke + b3*bnum2*bp1*bp2*k6*ke + b1*bh*bnum2*bp2*k2*kp3 + b1*bh*bnum2*bp3*k2*kp2 + b1*bnum2*bp2*bp3*k2*kh + b2*bh*bnum2*bp1*k4*kp3 + b2*bh*bnum2*bp3*k4*kp1 + b2*bnum2*bp1*bp3*k4*kh + b3*bh*bnum2*bp1*k6*kp2 + b3*bh*bnum2*bp2*k6*kp1 + b3*bnum2*bp1*bp2*k6*kh + a1*bnum2*bp2*k2*ke*kp3 + a1*bnum2*bp3*k2*ke*kp2 + a2*bnum2*bp1*k4*ke*kp3 + a2*bnum2*bp3*k4*ke*kp1 + a3*bnum2*bp1*k6*ke*kp2 + a3*bnum2*bp2*k6*ke*kp1 + a1*bh*bnum2*k2*kp2*kp3 + a1*bnum2*bp2*k2*kh*kp3 + a1*bnum2*bp3*k2*kh*kp2 + a2*bh*bnum2*k4*kp1*kp3 + a2*bnum2*bp1*k4*kh*kp3 + a2*bnum2*bp3*k4*kh*kp1 + a3*bh*bnum2*k6*kp1*kp2 + a3*bnum2*bp1*k6*kh*kp2 + a3*bnum2*bp2*k6*kh*kp1 + b1*bnum1*bp2*k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k2*ke*kp2*mp3 + a1*bnum3*k2*ke*kp3*mp2 + a2*bnum3*k4*ke*kp1*mp3 + a2*bnum3*k4*ke*kp3*mp1 + a3*bnum3*k6*ke*kp1*mp2 + a3*bnum3*k6*ke*kp2*mp1 + a1*bnum3*k2*kh*kp2*mp3 + a1*bnum3*k2*kh*kp3*mp2 + a1*bnum3*k2*kp2*kp3*mh + a2*bnum3*k4*kh*kp1*mp3 + a2*bnum3*k4*kh*kp3*mp1 + a2*bnum3*k4*kp1*kp3*mh + a3*bnum3*k6*kh*kp1*mp2 + a3*bnum3*k6*kh*kp2*mp1 + a3*bnum3*k6*kp1*kp2*mh + b1*bnum2*k2*ke*kp2*mp3 + b1*bnum2*k2*ke*kp3*mp2 + b2*bnum2*k4*ke*kp1*mp3 + b2*bnum2*k4*ke*kp3*mp1 + b3*bnum2*k6*ke*kp1*mp2 + b3*bnum2*k6*ke*kp2*mp1 + b1*bnum2*k2*kh*kp2*mp3 + b1*bnum2*k2*kh*kp3*mp2 + b1*bnum2*k2*kp2*kp3*mh + b2*bnum2*k4*kh*kp1*mp3 + b2*bnum2*k4*kh*kp3*mp1 + b2*bnum2*k4*kp1*kp3*mh + b3*bnum2*k6*kh*kp1*mp2 + b3*bnum2*k6*kh*kp2*mp1 + b3*bnum2*k6*kp1*kp2*mh;
            DS4 = b_ad*bden3*bp1*bp2*bp3 + b_ad*bden2*bp1*bp2*kp3 + b_ad*bden2*bp1*bp3*kp2 + b_ad*bden2*bp2*bp3*kp1 + b_ad*bden1*bp1*kp2*kp3 + b_ad*bden1*bp2*kp1*kp3 + b_ad*bden1*bp3*kp1*kp2 + b_ad*bden3*bp1*kp2*mp3 + b_ad*bden3*bp1*kp3*mp2 + b_ad*bden3*bp2*kp1*mp3 + b_ad*bden3*bp2*kp3*mp1 + b_ad*bden3*bp3*kp1*mp2 + b_ad*bden3*bp3*kp2*mp1 + bden3*bp1*bp2*kp3*m_ad + bden3*bp1*bp3*kp2*m_ad + bden3*bp2*bp3*kp1*m_ad + b_ad*bden2*kp1*kp2*mp3 + b_ad*bden2*kp1*kp3*mp2 + b_ad*bden2*kp2*kp3*mp1 + bden2*bp1*kp2*kp3*m_ad + bden2*bp2*kp1*kp3*m_ad + bden2*bp3*kp1*kp2*m_ad + bden1*kp1*kp2*kp3*m_ad + bden3*kp1*kp2*m_ad*mp3 + bden3*kp1*kp3*m_ad*mp2 + bden3*kp2*kp3*m_ad*mp1 + a1*bh*bnum3*bp2*bp3*k2 + a2*bh*bnum3*bp1*bp3*k4 + a3*bh*bnum3*bp1*bp2*k6 + b1*bh*bnum2*bp2*bp3*k2 + b2*bh*bnum2*bp1*bp3*k4 + b3*bh*bnum2*bp1*bp2*k6 + a1*bnum2*bp2*bp3*k2*ke + a2*bnum2*bp1*bp3*k4*ke + a3*bnum2*bp1*bp2*k6*ke + a1*bh*bnum2*bp2*k2*kp3 + a1*bh*bnum2*bp3*k2*kp2 + a1*bnum2*bp2*bp3*k2*kh + a2*bh*bnum2*bp1*k4*kp3 + a2*bh*bnum2*bp3*k4*kp1 + a2*bnum2*bp1*bp3*k4*kh + a3*bh*bnum2*bp1*k6*kp2 + a3*bh*bnum2*bp2*k6*kp1 + a3*bnum2*bp1*bp2*k6*kh + b1*bnum1*bp2*bp3*k2*ke + b2*bnum1*bp1*bp3*k4*ke + b3*bnum1*bp1*bp2*k6*ke + b1*bh*bnum1*bp2*k2*kp3 + b1*bh*bnum1*bp3*k2*kp2 + b1*bnum1*bp2*bp3*k2*kh + b2*bh*bnum1*bp1*k4*kp3 + b2*bh*bnum1*bp3*k4*kp1 + b2*bnum1*bp1*bp3*k4*kh + b3*bh*bnum1*bp1*k6*kp2 + b3*bh*bnum1*bp2*k6*kp1 + b3*bnum1*bp1*bp2*k6*kh + b1*bh*bnum3*bp2*k2*mp3 + b1*bh*bnum3*bp3*k2*mp2 + b1*bnum3*bp2*bp3*k2*mh + b2*bh*bnum3*bp1*k4*mp3 + b2*bh*bnum3*bp3*k4*mp1 + b2*bnum3*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bnum1*k2*kp2*kp3*mh + b2*bnum1*k4*kh*kp1*mp3 + b2*bnum1*k4*kh*kp3*mp1 + b2*bnum1*k4*kp1*kp3*mh + b3*bnum1*k6*kh*kp1*mp2 + b3*bnum1*k6*kh*kp2*mp1 + b3*bnum1*k6*kp1*kp2*mh + b1*bnum3*k2*ke*mp2*mp3 + b2*bnum3*k4*ke*mp1*mp3 + b3*bnum3*k6*ke*mp1*mp2 + b1*bnum3*k2*kh*mp2*mp3 + b1*bnum3*k2*kp2*mh*mp3 + b1*bnum3*k2*kp3*mh*mp2 + b2*bnum3*k4*kh*mp1*mp3 + b2*bnum3*k4*kp1*mh*mp3 + b2*bnum3*k4*kp3*mh*mp1 + b3*bnum3*k6*kh*mp1*mp2 + b3*bnum3*k6*kp1*mh*mp2 + b3*bnum3*k6*kp2*mh*mp1;
            DS5 = b_ad*bden2*bp1*bp2*bp3 + b_ad*bden1*bp1*bp2*kp3 + b_ad*bden1*bp1*bp3*kp2 + b_ad*bden1*bp2*bp3*kp1 + b_ad*bden3*bp1*bp2*mp3 + b_ad*bden3*bp1*bp3*mp2 + b_ad*bden3*bp2*bp3*mp1 + bden3*bp1*bp2*bp3*m_ad + b_ad*bden2*bp1*kp2*mp3 + b_ad*bden2*bp1*kp3*mp2 + b_ad*bden2*bp2*kp1*mp3 + b_ad*bden2*bp2*kp3*mp1 + b_ad*bden2*bp3*kp1*mp2 + b_ad*bden2*bp3*kp2*mp1 + bden2*bp1*bp2*kp3*m_ad + bden2*bp1*bp3*kp2*m_ad + bden2*bp2*bp3*kp1*m_ad + b_ad*bden1*kp1*kp2*mp3 + b_ad*bden1*kp1*kp3*mp2 + b_ad*bden1*kp2*kp3*mp1 + bden1*bp1*kp2*kp3*m_ad + bden1*bp2*kp1*kp3*m_ad + bden1*bp3*kp1*kp2*m_ad + b_ad*bden3*kp1*mp2*mp3 + b_ad*bden3*kp2*mp1*mp3 + b_ad*bden3*kp3*mp1*mp2 + bden3*bp1*kp2*m_ad*mp3 + bden3*bp1*kp3*m_ad*mp2 + bden3*bp2*kp1*m_ad*mp3 + bden3*bp2*kp3*m_ad*mp1 + bden3*bp3*kp1*m_ad*mp2 + bden3*bp3*kp2*m_ad*mp1 + bden2*kp1*kp2*m_ad*mp3 + bden2*kp1*kp3*m_ad*mp2 + bden2*kp2*kp3*m_ad*mp1 + a1*bh*bnum2*bp2*bp3*k2 + a2*bh*bnum2*bp1*bp3*k4 + a3*bh*bnum2*bp1*bp2*k6 + b1*bh*bnum1*bp2*bp3*k2 + b2*bh*bnum1*bp1*bp3*k4 + b3*bh*bnum1*bp1*bp2*k6 + a1*bnum1*bp2*bp3*k2*ke + a2*bnum1*bp1*bp3*k4*ke + a3*bnum1*bp1*bp2*k6*ke + a1*bh*bnum1*bp2*k2*kp3 + a1*bh*bnum1*bp3*k2*kp2 + a1*bnum1*bp2*bp3*k2*kh + a2*bh*bnum1*bp1*k4*kp3 + a2*bh*bnum1*bp3*k4*kp1 + a2*bnum1*bp1*bp3*k4*kh + a3*bh*bnum1*bp1*k6*kp2 + a3*bh*bnum1*bp2*k6*kp1 + a3*bnum1*bp1*bp2*k6*kh + a1*bh*bnum3*bp2*k2*mp3 + a1*bh*bnum3*bp3*k2*mp2 + a1*bnum3*bp2*bp3*k2*mh + a2*bh*bnum3*bp1*k4*mp3 + a2*bh*bnum3*bp3*k4*mp1 + a2*bnum3*bp1*bp3*k4*mh + a3*bh*bnum3*bp1*k6*mp2 + a3*bh*bnum3*bp2*k6*mp1 + a3*bnum3*bp1*bp2*k6*mh + b1*bh*bnum2*bp2*k2*mp3 + b1*bh*bnum2*bp3*k2*mp2 + b1*bnum2*bp2*bp3*k2*mh + b2*bh*bnum2*bp1*k4*mp3 + b2*bh*bnum2*bp3*k4*mp1 + b2*bnum2*bp1*bp3*k4*mh + b3*bh*bnum2*bp1*k6*mp2 + b3*bh*bnum2*bp2*k6*mp1 + b3*bnum2*bp1*bp2*k6*mh + a1*bnum2*bp2*k2*ke*mp3 + a1*bnum2*b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*bnum2*k4*kp1*mh*mp3 + b2*bnum2*k4*kp3*mh*mp1 + b3*bnum2*k6*kh*mp1*mp2 + b3*bnum2*k6*kp1*mh*mp2 + b3*bnum2*k6*kp2*mh*mp1;
            DS6 = b_ad*bden1*bp1*bp2*bp3 + b_ad*bden2*bp1*bp2*mp3 + b_ad*bden2*bp1*bp3*mp2 + b_ad*bden2*bp2*bp3*mp1 + bden2*bp1*bp2*bp3*m_ad + b_ad*bden1*bp1*kp2*mp3 + b_ad*bden1*bp1*kp3*mp2 + b_ad*bden1*bp2*kp1*mp3 + b_ad*bden1*bp2*kp3*mp1 + b_ad*bden1*bp3*kp1*mp2 + b_ad*bden1*bp3*kp2*mp1 + bden1*bp1*bp2*kp3*m_ad + bden1*bp1*bp3*kp2*m_ad + bden1*bp2*bp3*kp1*m_ad + b_ad*bden3*bp1*mp2*mp3 + b_ad*bden3*bp2*mp1*mp3 + b_ad*bden3*bp3*mp1*mp2 + bden3*bp1*bp2*m_ad*mp3 + bden3*bp1*bp3*m_ad*mp2 + bden3*bp2*bp3*m_ad*mp1 + b_ad*bden2*kp1*mp2*mp3 + b_ad*bden2*kp2*mp1*mp3 + b_ad*bden2*kp3*mp1*mp2 + bden2*bp1*kp2*m_ad*mp3 + bden2*bp1*kp3*m_ad*mp2 + bden2*bp2*kp1*m_ad*mp3 + bden2*bp2*kp3*m_ad*mp1 + bden2*bp3*kp1*m_ad*mp2 + bden2*bp3*kp2*m_ad*mp1 + bden1*kp1*kp2*m_ad*mp3 + bden1*kp1*kp3*m_ad*mp2 + bden1*kp2*kp3*m_ad*mp1 + bden3*kp1*m_ad*mp2*mp3 + bden3*kp2*m_ad*mp1*mp3 + bden3*kp3*m_ad*mp1*mp2 + a1*bh*bnum1*bp2*bp3*k2 + a2*bh*bnum1*bp1*bp3*k4 + a3*bh*bnum1*bp1*bp2*k6 + a1*bh*bnum2*bp2*k2*mp3 + a1*bh*bnum2*bp3*k2*mp2 + a1*bnum2*bp2*bp3*k2*mh + a2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*bh*bnum3*k6*mp1*mp2 + a3*bnum3*bp1*k6*mh*mp2 + a3*bnum3*bp2*k6*mh*mp1 + b1*bh*bnum2*k2*mp2*mp3 + b1*bnum2*bp2*k2*mh*mp3 + b1*bnum2*bp3*k2*mh*mp2 + b2*bh*bnum2*k4*mp1*mp3 + b2*bnum2*bp1*k4*mh*mp3 + b2*bnum2*bp3*k4*mh*mp1 + b3*bh*bnum2*k6*mp1*mp2 + b3*bnum2*bp1*k6*mh*mp2 + b3*bnum2*bp2*k6*mh*mp1 + a1*bnum2*k2*ke*mp2*mp3 + a2*bnum2*k4*ke*mp1*mp3 + a3*bnum2*k6*ke*mp1*mp2 + a1*bnum2*k2*kh*mp2*mp3 + a1*bnum2*k2*kp2*mh*mp3 + a1*bnum2*k2*kp3*mh*mp2 + a2*bnum2*k4*kh*mp1*mp3 + a2*bnum2*k4*kp1*mh*mp3 + a2*bnum2*k4*kp3*mh*mp1 + a3*bnum2*k6*kh*mp1*mp2 + a3*bnum2*k6*kp1*mh*mp2 + a3*bnum2*k6*kp2*mh*mp1 + b1*bnum1*k2*ke*mp2*mp3 + b2*bnum1*k4*ke*mp1*mp3 + b3*bnum1*k6*ke*mp1*mp2 + b1*bnum1*k2*kh*mp2*mp3 + b1*bnum1*k2*kp2*mh*mp3 + b1*bnum1*k2*kp3*mh*mp2 + b2*bnum1*k4*kh*mp1*mp3 + b2*bnum1*k4*kp1*mh*mp3 + b2*bnum1*k4*kp3*mh*mp1 + b3*bnum1*k6*kh*mp1*mp2 + b3*bnum1*k6*kp1*mh*mp2 + b3*bnum1*k6*kp2*mh*mp1 + b1*bnum3*k2*mh*mp2*mp3 + b2*bnum3*k4*mh*mp1*mp3 + b3*bnum3*k6*mh*mp1*mp2;
            DS7 = b_ad*bden1*bp1*bp2*mp3 + b_ad*bden1*bp1*bp3*mp2 + b_ad*bden1*bp2*bp3*mp1 + bden1*bp1*bp2*bp3*m_ad + b_ad*bden2*bp1*mp2*mp3 + b_ad*bden2*bp2*mp1*mp3 + b_ad*bden2*bp3*mp1*mp2 + bden2*bp1*bp2*m_ad*mp3 + bden2*bp1*bp3*m_ad*mp2 + bden2*bp2*bp3*m_ad*mp1 + b_ad*bden1*kp1*mp2*mp3 + b_ad*bden1*kp2*mp1*mp3 + b_ad*bden1*kp3*mp1*mp2 + bden1*bp1*kp2*m_ad*mp3 + bden1*bp1*kp3*m_ad*mp2 + bden1*bp2*kp1*m_ad*mp3 + bden1*bp2*kp3*m_ad*mp1 + bden1*bp3*kp1*m_ad*mp2 + bden1*bp3*kp2*m_ad*mp1 + b_ad*bden3*mp1*mp2*mp3 + bden3*bp1*m_ad*mp2*mp3 + bden3*bp2*m_ad*mp1*mp3 + bden3*bp3*m_ad*mp1*mp2 + bden2*kp1*m_ad*mp2*mp3 + bden2*kp2*m_ad*mp1*mp3 + bden2*kp3*m_ad*mp1*mp2 + a1*bh*bnum1*bp2*k2*mp3 + a1*bh*bnum1*bp3*k2*mp2 + a1*bnum1*bp2*bp3*k2*mh + a2*bh*bnum1*bp1*k4*mp3 + a2*bh*bnum1*bp3*k4*mp1 + a2*bnum1*bp1*bp3*k4*mh + a3*bh*bnum1*bp1*k6*mp2 + a3*bh*bnum1*bp2*k6*mp1 + a3*bnum1*bp1*bp2*k6*mh + a1*bh*bnum2*k2*mp2*mp3 + a1*bnum2*bp2*k2*mh*mp3 + a1*bnum2*bp3*k2*mh*mp2 + a2*bh*bnum2*k4*mp1*mp3 + a2*bnum2*bp1*k4*mh*mp3 + a2*bnum2*bp3*k4*mh*mp1 + a3*bh*bnum2*k6*mp1*mp2 + a3*bnum2*bp1*k6*mh*mp2 + a3*bnum2*bp2*k6*mh*mp1 + b1*bh*bnum1*k2*mp2*mp3 + b1*bnum1*bp2*k2*mh*mp3 + b1*bnum1*bp3*k2*mh*mp2 + b2*bh*bnum1*k4*mp1*mp3 + b2*bnum1*bp1*k4*mh*mp3 + b2*bnum1*bp3*k4*mh*mp1 + b3*bh*bnum1*k6*mp1*mp2 + b3*bnum1*bp1*k6*mh*mp2 + b3*bnum1*bp2*k6*mh*mp1 + a1*bnum1*k2*ke*mp2*mp3 + a2*bnum1*k4*ke*mp1*mp3 + a3*bnum1*k6*ke*mp1*mp2 + a1*bnum1*k2*kh*mp2*mp3 + a1*bnum1*k2*kp2*mh*mp3 + a1*bnum1*k2*kp3*mh*mp2 + a2*bnum1*k4*kh*mp1*mp3 + a2*bnum1*k4*kp1*mh*mp3 + a2*bnum1*k4*kp3*mh*mp1 + a3*bnum1*k6*kh*mp1*mp2 + a3*bnum1*k6*kp1*mh*mp2 + a3*bnum1*k6*kp2*mh*mp1 + a1*bnum3*k2*mh*mp2*mp3 + a2*bnum3*k4*mh*mp1*mp3 + a3*bnum3*k6*mh*mp1*mp2 + b1*bnum2*k2*mh*mp2*mp3 + b2*bnum2*k4*mh*mp1*mp3 + b3*bnum2*k6*mh*mp1*mp2;
            DS8 = b_ad*bden1*bp1*mp2*mp3 + b_ad*bden1*bp2*mp1*mp3 + b_ad*bden1*bp3*mp1*mp2 + bden1*bp1*bp2*m_ad*mp3 + bden1*bp1*bp3*m_ad*mp2 + bden1*bp2*bp3*m_ad*mp1 + b_ad*bden2*mp1*mp2*mp3 + bden2*bp1*m_ad*mp2*mp3 + bden2*bp2*m_ad*mp1*mp3 + bden2*bp3*m_ad*mp1*mp2 + bden1*kp1*m_ad*mp2*mp3 + bden1*kp2*m_ad*mp1*mp3 + bden1*kp3*m_ad*mp1*mp2 + bden3*m_ad*mp1*mp2*mp3 + a1*bh*bnum1*k2*mp2*mp3 + a1*bnum1*bp2*k2*mh*mp3 + a1*bnum1*bp3*k2*mh*mp2 + a2*bh*bnum1*k4*mp1*mp3 + a2*bnum1*bp1*k4*mh*mp3 + a2*bnum1*bp3*k4*mh*mp1 + a3*bh*bnum1*k6*mp1*mp2 + a3*bnum1*bp1*k6*mh*mp2 + a3*bnum1*bp2*k6*mh*mp1 + a1*bnum2*k2*mh*mp2*mp3 + a2*bnum2*k4*mh*mp1*mp3 + a3*bnum2*k6*mh*mp1*mp2 + b1*bnum1*k2*mh*mp2*mp3 + b2*bnum1*k4*mh*mp1*mp3 + b3*bnum1*k6*mh*mp1*mp2;
            DS9 = b_ad*bden1*mp1*mp2*mp3 + bden1*bp1*m_ad*mp2*mp3 + bden1*bp2*m_ad*mp1*mp3 + bden1*bp3*m_ad*mp1*mp2 + bden2*m_ad*mp1*mp2*mp3 + a1*bnum1*k2*mh*mp2*mp3 + a2*bnum1*k4*mh*mp1*mp3 + a3*bnum1*k6*mh*mp1*mp2;
            DS10 = bden1*m_ad*mp1*mp2*mp3;

            %Numerator is an 8th order
            NS0 = 0;
            NS1 = bden3*(b1*k2*kp2*kp3 + b2*k4*kp1*kp3 + b3*k6*kp1*kp2);
            NS2 = bden3*(a1*k2*kp2*kp3 + a2*k4*kp1*kp3 + a3*k6*kp1*kp2 + b1*bp2*k2*kp3 + b1*bp3*k2*kp2 + b2*bp1*k4*kp3 + b2*bp3*k4*kp1 + b3*bp1*k6*kp2 + b3*bp2*k6*kp1) + bden2*(b1*k2*kp2*kp3 + b2*k4*kp1*kp3 + b3*k6*kp1*kp2);
            NS3 = bden2*(a1*k2*kp2*kp3 + a2*k4*kp1*kp3 + a3*k6*kp1*kp2 + b1*bp2*k2*kp3 + b1*bp3*k2*kp2 + b2*bp1*k4*kp3 + b2*bp3*k4*kp1 + b3*bp1*k6*kp2 + b3*bp2*k6*kp1) + bden1*(b1*k2*kp2*kp3 + b2*k4*kp1*kp3 + b3*k6*kp1*kp2) + bden3*(b1*k2*kp2*mp3 + b1*k2*kp3*mp2 + b2*k4*kp1*mp3 + b2*k4*kp3*mp1 + b3*k6*kp1*mp2 + b3*k6*kp2*mp1 + b1*bp2*bp3*k2 + b2*bp1*bp3*k4 + b3*bp1*bp2*k6 + a1*bp2*k2*kp3 + a1*bp3*k2*kp2 + a2*bp1*k4*kp3 + a2*bp3*k4*kp1 + a3*bp1*k6*kp2 + a3*bp2*k6*kp1);
            NS4 = bden1*(a1*k2*kp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p1 + a3*k6*kp1*mp2 + a3*k6*kp2*mp1 + a1*bp2*bp3*k2 + a2*bp1*bp3*k4 + a3*bp1*bp2*k6 + b1*bp2*k2*mp3 + b1*bp3*k2*mp2 + b2*bp1*k4*mp3 + b2*bp3*k4*mp1 + b3*bp1*k6*mp2 + b3*bp2*k6*mp1);
            NS6 = bden2*(b1*k2*mp2*mp3 + b2*k4*mp1*mp3 + b3*k6*mp1*mp2 + a1*bp2*k2*mp3 + a1*bp3*k2*mp2 + a2*bp1*k4*mp3 + a2*bp3*k4*mp1 + a3*bp1*k6*mp2 + a3*bp2*k6*mp1) + bden3*(a1*k2*mp2*mp3 + a2*k4*mp1*mp3 + a3*k6*mp1*mp2) + bden1*(a1*k2*kp2*mp3 + a1*k2*kp3*mp2 + a2*k4*kp1*mp3 + a2*k4*kp3*mp1 + a3*k6*kp1*mp2 + a3*k6*kp2*mp1 + a1*bp2*bp3*k2 + a2*bp1*bp3*k4 + a3*bp1*bp2*k6 + b1*bp2*k2*mp3 + b1*bp3*k2*mp2 + b2*bp1*k4*mp3 + b2*bp3*k4*mp1 + b3*bp1*k6*mp2 + b3*bp2*k6*mp1);
            NS7 = bden1*(b1*k2*mp2*mp3 + b2*k4*mp1*mp3 + b3*k6*mp1*mp2 + a1*bp2*k2*mp3 + a1*bp3*k2*mp2 + a2*bp1*k4*mp3 + a2*bp3*k4*mp1 + a3*bp1*k6*mp2 + a3*bp2*k6*mp1) + bden2*(a1*k2*mp2*mp3 + a2*k4*mp1*mp3 + a3*k6*mp1*mp2);
            NS8 = bden1*(a1*k2*mp2*mp3 + a2*k4*mp1*mp3 + a3*k6*mp1*mp2);


            AydinTF = tf([(NS8) (NS7) (NS6) (NS5) (NS4) (NS3) (NS2) (NS1) 0],[(DS10) (DS9) (DS8) (DS7) (DS6) (DS5) (DS4) (DS3) (DS2) (DS1) (DS0)]);


            % Grab the poles and evaluate if any poles are unstable
            poles = pole(AydinTF);
            realpoles = real(poles);
            unstable(massval,dampval,impedance_type) = ~(any(realpoles(:)>0));

        end
    end
end


%% Create figures that output the results of the stability analysis
figcount = 0;
for impedance_type=1:8
    switch impedance_type
        case 1

            masses = 0:5:200;
            dampers = 0:10:1000;
        case 5
            masses = linspace(0,25,41);
            dampers = linspace(0,30,101);
    end

    edgecase = [];
    for jim = 1:length(masses)
        jeff = 1;

        while unstable(jim,jeff,impedance_type)~=1
            jeff = jeff+1;
            if jeff==length(unstable)
                jeff = jeff-1;
                break;
            end
            edgecase(jim) = jeff;

        end
    end
    stab_bs = []
    for bit = 1:length(edgecase)
        if edgecase(bit)==0
            stab_bs(bit) = 1;
        else
            stab_bs(bit) = dampers(edgecase(bit));
        end
    end
    if figcount <4
        figure(1)
        hold on
        plot(stab_bs,masses)
        legend
    else
        figure(2)
        hold on
        plot(stab_bs,masses)
        xlim([0 30])
        ylim([0 25])
        legend
    end

    figcount = figcount+1;
end
