def test_thrust_jacobian(self): '''Test thrust_jacobian i.e. test that jac(thrust_matrix(alpha) * u) * delta_alpha + thrust_matrix(alpha_0) * u_0 [jacobian evaluated at alpha = alpha_0, u = u_0] is close to thrust_matrix(delta_alpha + alpha_0) In English: That the implemented jacobian suffices to do a higher dimensional first-order Taylor approximation of the nonlinear behavior of the thrust_matrix ''' max_error = 0.2 tests = [ { 'u_0': (10, 10), 'alpha_0': (0.01, 0.01), 'delta_angle': (0.1, 0.1), }, { 'u_0': (10, 10), 'alpha_0': (0.1, 0.1), 'delta_angle': (0.05, 0.05), }, { 'u_0': (25, 10), 'alpha_0': (0.5, 0.3), 'delta_angle': (0.08, 0.05), }, ] for test in tests: u_0 = np.array(test['u_0']) alpha_0 = np.array(test['alpha_0']) delta_angle = np.array(test['delta_angle']) jacobian = Azi_Drive.thrust_jacobian(alpha_0, u_0) initial_thrust_matrix = Azi_Drive.thrust_matrix(alpha_0) linear_estimate = np.dot(initial_thrust_matrix, u_0) + np.dot(jacobian, delta_angle) true_thrust_matrix = Azi_Drive.thrust_matrix(alpha_0 + delta_angle) nonlinear_estimate = np.dot(true_thrust_matrix, u_0) error = np.linalg.norm(nonlinear_estimate - linear_estimate) self.assertLess( error, max_error, msg='error of {} exceeds maximum of {}\n Estimates: nonlinear {}, linear {}'.format( error, max_error, nonlinear_estimate, linear_estimate, ) )
# jBa_u = Azi_Drive.thrust_jacobian(a_0, u_0) a_min = -3 * np.pi / 2 a_max = 3 * np.pi / 2 u_min = -100.0 u_max = 100. da_max = 0.1 tau = np.array([200.0, 200.0, 0.0]).astype(np.double) Q = np.diag([10., 10., 30.]).astype(np.double) Ohm = np.diag([0., 0.]).astype(np.double) tic = time() for k in range(200): Ba = Azi_Drive.thrust_matrix(a_0).astype(np.double) jBa_u = Azi_Drive.thrust_jacobian(a_0, u_0).astype(np.double) soln = cvxbind.ksolve( u_0.flatten(), a_0.flatten(), Ohm.flatten(), Q.flatten(), Ba.transpose().flatten(), jBa_u.transpose().A1, u_max, u_min, a_min, a_max, da_max, tau.flatten(), )
# jBa_u = Azi_Drive.thrust_jacobian(a_0, u_0) a_min = -3 * np.pi / 2 a_max = 3 * np.pi / 2 u_min = -100.0 u_max = 100. da_max = 0.1 tau = np.array([200.0, 200.0, 0.0]).astype(np.double) Q = np.diag([10., 10., 30.]).astype(np.double) Ohm = np.diag([0., 0.]).astype(np.double) tic = time() for k in range(200): Ba = Azi_Drive.thrust_matrix(a_0).astype(np.double) jBa_u = Azi_Drive.thrust_jacobian(a_0, u_0).astype(np.double) soln = cvxbind.ksolve( u_0.flatten(), a_0.flatten(), Ohm.flatten(), Q.flatten(), Ba.transpose().flatten(), jBa_u.transpose().A1, u_max, u_min, a_min, a_max, da_max, tau.flatten(), )
def test_thrust_jacobian(self): '''Test thrust_jacobian i.e. test that jac(thrust_matrix(alpha) * u) * delta_alpha + thrust_matrix(alpha_0) * u_0 [jacobian evaluated at alpha = alpha_0, u = u_0] is close to thrust_matrix(delta_alpha + alpha_0) In English: That the implemented jacobian suffices to do a higher dimensional first-order Taylor approximation of the nonlinear behavior of the thrust_matrix ''' max_error = 0.2 tests = [ { 'u_0': (10, 10), 'alpha_0': (0.01, 0.01), 'delta_angle': (0.1, 0.1), }, { 'u_0': (10, 10), 'alpha_0': (0.1, 0.1), 'delta_angle': (0.05, 0.05), }, { 'u_0': (25, 10), 'alpha_0': (0.5, 0.3), 'delta_angle': (0.08, 0.05), }, ] for test in tests: u_0 = np.array(test['u_0']) alpha_0 = np.array(test['alpha_0']) delta_angle = np.array(test['delta_angle']) jacobian = Azi_Drive.thrust_jacobian(alpha_0, u_0) initial_thrust_matrix = Azi_Drive.thrust_matrix(alpha_0) linear_estimate = np.dot(initial_thrust_matrix, u_0) + np.dot( jacobian, delta_angle) true_thrust_matrix = Azi_Drive.thrust_matrix(alpha_0 + delta_angle) nonlinear_estimate = np.dot(true_thrust_matrix, u_0) error = np.linalg.norm(nonlinear_estimate - linear_estimate) self.assertLess( error, max_error, msg= 'error of {} exceeds maximum of {}\n Estimates: nonlinear {}, linear {}' .format( error, max_error, nonlinear_estimate, linear_estimate, ))