de1=I*theta1ddot+B*theta1dot+K*(L^2*(theta1-theta0)-d0)+beta*(L^2*(theta1-theta0)-d0)^3-K*(L^2*(theta2-theta1)-d0)-beta*(L^2*(theta2-theta1)-d0)^3+GPE*sin(theta1);
de2=I*theta2ddot+B*theta2dot+K*(L^2*(theta2-theta1)-d0)+beta*(L^2*(theta2-theta1)-d0)^3-K*(L^2*(theta3-theta2)-d0)-beta*(L^2*(theta3-theta2)-d0)^3+GPE*sin(theta2);
de3=I*theta3ddot+B*theta3dot+K*(L^2*(theta3-theta2)-d0)+beta*(L^2*(theta3-theta2)-d0)^3-K*(L^2*(theta4-theta3)-d0)-beta*(L^2*(theta4-theta3)-d0)^3+GPE*sin(theta3);
de4=I*theta4ddot+B*theta4dot+K*(L^2*(theta4-theta3)-d0)+beta*(L^2*(theta4-theta3)-d0)^3-K*(L^2*(theta5-theta4)-d0)-beta*(L^2*(theta5-theta4)-d0)^3+GPE*sin(theta4);
de5=I*theta5ddot+B*theta5dot+K*(L^2*(theta5-theta4)-d0)+beta*(L^2*(theta5-theta4)-d0)^3-K*(L^2*(theta6-theta5)-d0)-beta*(L^2*(theta6-theta5)-d0)^3+GPE*sin(theta5);
de6=I*theta6ddot+B*theta6dot+K*(L^2*(theta6-theta5)-d0)+beta*(L^2*(theta6-theta5)-d0)^3-K*(L^2*(theta7-theta6)-d0)-beta*(L^2*(theta7-theta6)-d0)^3+GPE*sin(theta6);
de7=I*theta7ddot+B*theta7dot+K*(L^2*(theta7-theta6)-d0)+beta*(L^2*(theta7-theta6)-d0)^3-K*(L^2*(-theta7)-d0)-beta*(L^2*(-theta7)-d0)^3+GPE*sin(theta7);
variables={theta1,theta2,theta3,theta4,theta5,theta6,theta7,theta1dot,theta2dot,theta3dot,theta4dot,theta5dot,theta6dot,theta7dot};
variablesshort={str2sym('x(1)'),str2sym('x(2)'),str2sym('x(3)'),str2sym('x(4)'),str2sym('x(5)'),str2sym('x(6)'),str2sym('x(7)'),str2sym('x(8)'),str2sym('x(9)'),str2sym('x(10)'),str2sym('x(11)'),str2sym('x(12)'),str2sym('x(13)'),str2sym('x(14)')};
DE1=subs(de1,variables,variablesshort);
DE2=subs(de2,variables,variablesshort);
DE3=subs(de3,variables,variablesshort);
DE4=subs(de4,variables,variablesshort);
DE5=subs(de5,variables,variablesshort);
DE6=subs(de6,variables,variablesshort);
DE7=subs(de7,variables,variablesshort);