Skip to content

Commit fceec05

Browse files
committed
Added OutputResponse method.
Renamed response method to StateResponse. Modified StateResponse docstrings.
1 parent e739c81 commit fceec05

File tree

1 file changed

+58
-3
lines changed

1 file changed

+58
-3
lines changed

control/system.py

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -757,16 +757,16 @@ def eigplot(self, ret=True):
757757
if ret == True:
758758
return eig_val
759759

760-
def response(self, t, initial_cond, u, ret=False, show=True):
760+
def StateResponse(self, t, initial_cond, u, ret=False, show=True):
761761
'''
762762
Parameters
763763
----------
764764
t : integer
765765
DESCRIPTION. time period
766766
initial_cond : numpy array
767-
DESCRIPTION. numpy array of initial conditions x(0). The default is None.
767+
DESCRIPTION. numpy array of initial conditions x(0).
768768
u : numpy array
769-
DESCRIPTION. numpy array of inputs. The default is None.
769+
DESCRIPTION. numpy array of inputs.
770770
771771
Returns
772772
-------
@@ -805,5 +805,60 @@ def response(self, t, initial_cond, u, ret=False, show=True):
805805
plt.legend()
806806
plt.show()
807807

808+
if ret == True:
809+
return resp_dict
810+
811+
def OutputResponse(self, t, initial_cond, u, ret=False, show=True):
812+
'''
813+
Parameters
814+
----------
815+
t : integer
816+
DESCRIPTION. time period
817+
initial_cond : numpy array
818+
DESCRIPTION. numpy array of initial conditions x(0).
819+
u : numpy array
820+
DESCRIPTION. numpy array of inputs.
821+
ret : bool, optional
822+
DESCRIPTION. Returns the response dictioanry if True. The default is False.
823+
show : bool, optional
824+
DESCRIPTION. Returns the response plot if True. The default is True.
825+
826+
Returns
827+
-------
828+
resp_dict : dict
829+
DESCRIPTION. Response dictionary.
830+
831+
'''
832+
B = self.B
833+
C = self.C
834+
D = self.D
835+
initial_cond = initial_cond.reshape((len(self.A)))
836+
837+
resp = []
838+
conv = np.dot(C.T, signal.convolve2d(np.array(np.dot(B.T,u)).reshape(1,1), np.exp(self.A), mode='same')).T + np.dot(D,u.T)
839+
840+
for i in range(t+1):
841+
resp_elem = np.dot(C, np.dot(initial_cond, np.exp(self.A*i))) + conv
842+
resp.append(resp_elem)
843+
844+
resp_dict = {}
845+
temp_list = []
846+
847+
for m in range(resp[0][0].shape[0]):
848+
var = "y" + str(m+1)
849+
for n in range(len(resp)):
850+
temp_val = resp[n][0][m]
851+
temp_list.append(temp_val)
852+
resp_dict[var] = temp_list[:]
853+
temp_list.clear()
854+
855+
856+
if show == True:
857+
for i in range(len(resp_dict)):
858+
selector = 'y' + str(i+1)
859+
plt.plot(resp_dict[selector], label=selector)
860+
plt.legend()
861+
plt.show()
862+
808863
if ret == True:
809864
return resp_dict

0 commit comments

Comments
 (0)