@@ -0,0 +1,1830 @@
+#!/usr/bin/env python%0A# -*- coding: utf-8 -*-%0A%22%22%22Exercise 9.14 from Kane 1985.%22%22%22%0A%0Afrom __future__ import division%0Afrom sympy import expand, symbols%0Afrom sympy.physics.mechanics import ReferenceFrame, Point%0Afrom sympy.physics.mechanics import dot, dynamicsymbols%0Afrom util import msprint, partial_velocities%0Afrom util import function_from_partials, generalized_active_forces%0A%0A%0Aq1, q2, q3, q4, q5, q6 = q = dynamicsymbols('q1:7')%0Au1, u2, u3, u4, u5, u6 = u = dynamicsymbols('u1:7')%0Aalpha, beta = symbols('%CE%B1 %CE%B2')%0A%0A# reference frames%0AA = ReferenceFrame('A')%0AB = A.orientnew('B', 'body', %5Bq1, q2, q3%5D, 'xyz')%0A%0A# define points%0ApO = Point('O')%0ApP = pO.locatenew('P', q1*A.x + q2*A.y + q3*A.z)%0ApP.set_vel(A, pP.pos_from(pO).dt(A))%0A%0A# kinematic differential equations%0Akde_map = dict(zip(map(lambda x: x.diff(), q), u))%0A%0A# forces%0Aforces = %5B(pP, -beta * pP.vel(A))%5D%0Atorques = %5B(B, -alpha * B.ang_vel_in(A))%5D%0A%0Apartials_c = partial_velocities(zip(*forces + torques )%5B0%5D, u, A, kde_map)%0AFr_c, _ = generalized_active_forces(partials_c, forces + torques)%0A%0Adissipation_function = function_from_partials(%0A        map(lambda x: 0 if x == 0 else -x.subs(kde_map), Fr_c),%0A        u,%0A        zero_constants=True)%0Afrom sympy import simplify, trigsimp%0Adissipation_function = trigsimp(dissipation_function)%0A#print('%E2%84%B1 = %7B0%7D'.format(msprint(dissipation_function)))%0A%0Aomega2 = trigsimp(dot(B.ang_vel_in(A), B.ang_vel_in(A)).subs(kde_map))%0Av2 = trigsimp(dot(pP.vel(A), pP.vel(A)).subs(kde_map))%0Asym_map = dict(zip(%5Bomega2, v2%5D, map(lambda x: x**2, symbols('%CF%89 v'))))%0A#print('%CF%89**2 = %7B0%7D'.format(msprint(omega2)))%0A#print('v**2 = %7B0%7D'.format(msprint(v2)))%0Aprint('%E2%84%B1 = %7B0%7D'.format(msprint(dissipation_function.subs(sym_map))))%0A%0Adissipation_function_expected = (alpha * omega2 + beta * v2) / 2%0Aassert expand(dissipation_function - dissipation_function_expected) == 0%0A

Add Exercise 9.14