def test_singleterm_mimo_monomial_derivatives(self): m = Monomial(0, 1, [], [2], [], [3], [], [3]) y = [] u = [[1, 2, 3, 7], [4, 5, 6, 8]] dy, du = m.derivatives(y, u, 1, True, True) assert_array_almost_equal(du, [[0, 0, 0, 0], [0, 0, 0, 3*8**2]])
def test_singleterm_siso_monomial_derivatives(self): m = Monomial(1, 0, [2], [], [2], []) y = [[1.12], [2.12]] u = [] dy, du = m.derivatives(y, u, 1, True, True) assert_array_almost_equal(dy, [[0], [2.12*2]])
def test_singleterm_mimo_numeric_derivatives(self): m = Monomial(0, 1, [], [2], [], [4], [], [3]) y = [] u = [[1, 2.12, 3, 7], [4, 5, 6, 8]] du = m.derivatives(y, u, 1, deriv_y=False) du_numeric = monomial_numeric_derivatives(m, y, u, 1, deriv_y=False) assert_array_almost_equal(du, du_numeric)
def test_singleterm_siso_numeric_derivatives(self): m = Monomial(1, 0, [3], [], [4], []) y = [[1.12], [123.123], [1.2]] u = [] dy = m.derivatives(y, u, 1, deriv_u=False) dy_numeric = monomial_numeric_derivatives(m, y, u, 1, deriv_u=False) assert_array_almost_equal(dy, dy_numeric)
def test_siso_numeric_derivatives(self): m = Monomial(2, 3, [1, 2], [4, 5, 6]) y = [[1.12], [2.12]] u = [[21.1], [2.1], [3.4]] dy, du = m.derivatives(y, u, 4) dy_numeric, du_numeric = monomial_numeric_derivatives(m, y, u, 4) assert_array_almost_equal(dy, dy_numeric) assert_array_almost_equal(du, du_numeric)
def test_mimo_numeric_derivatives(self): m = Monomial(3, 2, [1, 2, 3], [4, 5], [1, 2, 1], [2, 2], [0, 2, 3], [0, 1]) y = [[1.12, 3, 4, 5], [2.12, 7, 8, 9], [3, 10, 11, 12]] u = [[2, 1], [2, 3.2]] dy, du = m.derivatives(y, u, 4) dy_numeric, du_numeric = monomial_numeric_derivatives(m, y, u, 4) assert_array_almost_equal(dy, dy_numeric) assert_array_almost_equal(du, du_numeric)
def test_siso_monomial_derivatives(self): m = Monomial(3, 2, [1, 2, 3], [4, 5], [1, 1, 1], [3, 3]) y = [[1.12], [2.12], [3]] u = [[2], [2]] dy, du = m.derivatives(y, u, 4) assert_array_almost_equal(dy, [[2.12*3*(2**3)*(2**3)], [1.12*3*(2**3)*(2**3)], [1.12*2.12*(2**3)*(2**3)]]) assert_array_almost_equal(du, [[1.12*2.12*3*(3*2**2)*(2**3)], [1.12*2.12*3*(2**3)*(3*2**2)]])
def test_mimo_monomial_derivatives(self): m = Monomial(3, 2, [1, 2, 3], [4, 5], [1, 1, 1], [2, 2], [1, 2, 3], [0, 1]) y = [[1.12, 3, 4, 5], [2.12, 7, 8, 9], [3, 10, 11, 12]] u = [[2, 1], [2, 3.2]] dy, du = m.derivatives(y, u, 4) assert_array_almost_equal(dy, [[0, 8*12*(2**2)*(3.2**2), 0, 0], [0, 0, 3*12*(2**2)*(3.2**2), 0], [0, 0, 0, 3*8*(2**2)*(3.2**2)]]) assert_array_almost_equal(du, [[3*8*12*(2*2)*(3.2**2), 0], [0, 3*8*12*(2**2)*(3.2*2)]])