Pole location vs. Tran behavior

https://web.mit.edu/2.14/www/Handouts/PoleZero.pdf

The location of the poles in the s-plane therefore define the n components in the homogeneous response as described below:

1. A real pole pi = −σ in the left-half of the s-plane defines an exponentially decaying component , Ce−σt, in the homogeneous response. The rate of the decay is determined by the pole location; poles far from the origin in the left-half plane correspond to components that decay rapidly, while poles near the origin correspond to slowly decaying components.

2. A pole at the origin pi = 0 defines a component that is constant in amplitude and defined by the initial conditions.

3. A real pole in the right-half plane corresponds to an exponentially increasing component Ceσt in the homogeneous response; thus defining the system to be unstable.

4. A complex conjugate pole pair σ ± jω in the left-half of the s-plane combine to generate a response component that is a decaying sinusoid of the form Ae−σt sin (ωt + φ) where A and φ are determined by the initial conditions. The rate of decay is specified by σ; the frequency of oscillation is determined by ω.

5. An imaginary pole pair, that is a pole pair lying on the imaginary axis, ±jω generates an oscillatory component with a constant amplitude determined by the initial conditions.

6. A complex pole pair in the right half plane generates an exponentially increasing component. These results are summarized in Fig. 2.

引申:

If the open loop T(s) contains no RHP poles, the close loop 1/(1+T) and T/(1+T) contain no RHP poles when PM >0.

If T contains RH poles, the PM test cannot be used. (the original OL system is unstable)

请优化下面的代码:import turtle # 控制台显示部分 print("Hanoi Tower Game") # 获取用户输入 n = int(input("请输入盘子的个数:")) # 初始化三个柱子 a = list(range(n, 0, -1)) b, c = [], [] # 定义移动函数 def move(n, source, target, auxiliary): if n > 0: # 移动 n-1 个盘子到辅助柱子 move(n-1, source, auxiliary, target) # 将最大的盘子移动到目标柱子 target.append(source.pop()) # 显示移动过程 print("Move disk", n, "from", source, "to", target) # 移动 n-1 个盘子从辅助柱子到目标柱子 move(n-1, auxiliary, target, source) # 开始移动 move(n, a, c, b) # turtle部分 screen = turtle.Screen() screen.setup(600, 600) screen.bgcolor("white") # 绘制柱子 pole1 = turtle.Turtle() pole1.hideturtle() pole1.speed(0) pole1.penup() pole1.goto(-150, -200) pole1.pendown() pole1.width(5) pole1.color("black") pole1.left(90) pole1.forward(400) pole2 = pole1.clone() pole2.penup() pole2.goto(0, -200) pole2.pendown() pole2.forward(400) pole3 = pole1.clone() pole3.penup() pole3.goto(150, -200) pole3.pendown() pole3.forward(400) # 绘制盘子 colors = ["red", "green", "blue", "yellow", "purple", "orange"] turtles = [] for i in range(n): t = turtle.Turtle() t.hideturtle() t.shape("square") t.color(colors[i%6]) t.shapesize(1, (n-i)*2, 1) t.penup() t.goto(-150, -200+(i+1)*20) t.pendown() turtles.append(t) # 移动盘子 def move_turtle(disk, source, target): disk.penup() disk.goto(source, 200) disk.pendown() disk.goto(target, 200) disk.goto(target, -200+len(target)*20) # 开始移动 for i in range(2**n-1): disk = turtles[a.index(n-i)] move_turtle(disk, disk.xcor(), -150) a.remove(n-i) b.append(n-i) disk_index = a.index(n-i-1) if (n-i-1) in a else b.index(n-i-1) disk = turtles[disk_index] move_turtle(disk, disk.xcor(), pole_positions[disk_index]) if (n-i-1) in a: a.remove(n-i-1) else: b.remove(n-i-1) c.append(n-i-1) disk_index = a.index(n-i) if (n-i) in a else b.index(n-i) disk = turtles[disk_index] move_turtle(disk, disk.xcor(), pole_positions[disk_index]) if (n-i) in a: a.remove(n-i) else: b.remove(n-i) c.append(n-i) # 等待用户关闭窗口 screen.mainloop()
05-31
优化建议如下: 1. 可以将代码封装成函数,从而提高代码的可重用性和可读性。 2. 可以使用字典来存储柱子的位置,从而避免重复代码。 3. 可以使用 turtle.tracer() 函数来关闭动画效果,从而提高绘制速度。 4. 可以使用 turtle.clear() 函数来清除绘制的盘子,从而避免重复绘制。 重构后的代码如下: ```python import turtle def draw_pole(x, y): pole = turtle.Turtle() pole.hideturtle() pole.speed(0) pole.penup() pole.goto(x, y) pole.pendown() pole.width(5) pole.color("black") pole.left(90) pole.forward(400) return pole def draw_disk(x, y, size, color): disk = turtle.Turtle() disk.hideturtle() disk.shape("square") disk.color(color) disk.shapesize(1, size*2, 1) disk.penup() disk.goto(x, y) disk.pendown() return disk def move_turtle(disk, source, target): disk.penup() disk.goto(source, 200) disk.pendown() disk.goto(target, 200) disk.goto(target, -200+len(target)*20) def move(n, source, target, auxiliary, poles): if n > 0: move(n-1, source, auxiliary, target, poles) target.append(source.pop()) disk_index = poles[source][-1] move_turtle(disk_index, disk_index.xcor(), poles[target][0]) poles[target].insert(0, poles[source].pop()) move(n-1, auxiliary, target, source, poles) def hanoi(n): a = list(range(n, 0, -1)) b, c = [], [] poles = {'a': [], 'b': [], 'c': []} poles['a'] = [draw_disk(-150, -200+(i+1)*20, n-i, colors[i%6]) for i in range(n)] pole1 = draw_pole(-150, -200) pole2 = draw_pole(0, -200) pole3 = draw_pole(150, -200) turtle.tracer(False) move(n, a, c, b, poles) turtle.clear() if __name__ == "__main__": print("Hanoi Tower Game") n = int(input("请输入盘子的个数:")) colors = ["red", "green", "blue", "yellow", "purple", "orange"] hanoi(n) turtle.mainloop() ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值