From 8326fb1a0fd881b45862971b33c294df99d11bb4 Mon Sep 17 00:00:00 2001 From: Adam Friedrich Schrey <adam.schrey@gmx.de> Date: Sun, 29 Aug 2021 22:38:04 +0200 Subject: [PATCH] Add more support for 2 dimensional arrays --- notebooks/Pysim/Block.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/notebooks/Pysim/Block.py b/notebooks/Pysim/Block.py index 8e69b20..848490c 100644 --- a/notebooks/Pysim/Block.py +++ b/notebooks/Pysim/Block.py @@ -114,7 +114,7 @@ class SquareSignal(Block): def Step(self,t,dt): - d = t/self.Ts-floor(t/self.Ts); + d = t/self.Ts-int(t/self.Ts); if d > self.duty: self.y[0] = self.lo; else: @@ -451,7 +451,13 @@ class StateSpace(Block): else: print("WARNING: Can not handle self.C with dimension "+str(self.C.ndim)) for j in range(0,self.ninput): - self.y[i] = self.y[i] +self.D[j]*self.u[j] + if self.C.ndim == 1: + self.y[i] = self.y[i] + self.D[j]*self.u[j] + elif self.C.ndim == 2: + #prevent [ValueError: setting an array element with a sequence.] for 2 dimensional self.C: + self.y[i] = self.y[i] + self.D[i][j]*self.u[j] + else: + print("WARNING: Can not handle self.D with dimension "+str(self.C.ndim)) self.updatestate(t,dt) def Reset(self): @@ -531,4 +537,4 @@ class TransferFunction(Block): dxdt[i] = dxdt[i] + self.A[i,j]*x[j] return dxdt - + -- GitLab