|
16 | 16 |
|
17 | 17 | import numpy as np
|
18 | 18 | import scipy as sp
|
| 19 | +import math |
19 | 20 |
|
20 | 21 | import control as ct
|
21 | 22 |
|
@@ -659,3 +660,32 @@ def test_interconnect_rewrite():
|
659 | 660 | outputs=['y', 'z'])
|
660 | 661 |
|
661 | 662 | assert icsys.input_labels == ['u[0]', 'u[1]', 'w[0]', 'w[1]']
|
| 663 | + |
| 664 | + |
| 665 | +def test_interconnect_params(): |
| 666 | + # Create a nominally unstable system |
| 667 | + sys1 = ct.nlsys( |
| 668 | + lambda t, x, u, params: params['a'] * x[0] + u[0], |
| 669 | + states=1, inputs='u', outputs='y', params={'a': 1}) |
| 670 | + |
| 671 | + # Simple system for serial interconnection |
| 672 | + sys2 = ct.nlsys( |
| 673 | + None, lambda t, x, u, params: u[0], |
| 674 | + inputs='r', outputs='u') |
| 675 | + |
| 676 | + # Create a series interconnection |
| 677 | + sys = ct.interconnect([sys1, sys2], inputs='r', outputs='y') |
| 678 | + |
| 679 | + # Make sure we can call the update function |
| 680 | + sys.updfcn(0, [0], [0], {}) |
| 681 | + |
| 682 | + # Make sure the serial interconnection is unstable to start |
| 683 | + assert sys.linearize([0], [0]).poles()[0].real == 1 |
| 684 | + |
| 685 | + # Change the parameter and make sure it takes |
| 686 | + assert sys.linearize([0], [0], params={'a': -1}).poles()[0].real == -1 |
| 687 | + |
| 688 | + # Now try running a simulation |
| 689 | + timepts = np.linspace(0, 10) |
| 690 | + resp = ct.input_output_response(sys, timepts, 0, params={'a': -1}) |
| 691 | + assert resp.states[0, -1].item() < 2 * math.exp(-10) |
0 commit comments