被控对象为G(s)=1000/(s^3+87.35s^2+10470s)的基于RBF神经网络的监督控制代码设计
时间: 2024-01-01 10:05:03 浏览: 24
以下是基于RBF神经网络的监督控制代码设计,用于控制被控对象G(s)=1000/(s^3+87.35s^2+10470s):
```python
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
# Define the transfer function for the plant G(s)
def plant_tf(s):
return 1000/(s**3 + 87.35*s**2 + 10470*s)
# Define the RBF neural network function
def RBF_nn(x, c, w):
return np.sum(w*np.exp(-1*np.sum((x-c)**2,axis=1)))
# Define the control input function
def control_input(y, y_d, c, w):
e = y_d - y
x = np.array([e])
u = RBF_nn(x, c, w)
return u
# Define the function for the system dynamics
def system_dynamics(x, t, c, w):
y = x[0]
y_d = x[1]
s = x[2]
u = control_input(y, y_d, c, w)
dsdt = -s + u
dydt = s
dy_ddt = y_d
dxdt = [dydt, dy_ddt, dsdt]
return dxdt
# Define the RBF neural network training function
def RBF_nn_training(c, w, X_train, Y_train):
for i in range(len(X_train)):
x = X_train[i]
y = Y_train[i]
phi = np.exp(-1*np.sum((x-c)**2,axis=1))
delta_w = 0.01*(y - np.sum(w*phi))*phi
w = w + delta_w
return w
# Define the main function
def main():
# Define the time span and the initial conditions
t = np.linspace(0, 10, 1000)
x0 = [0, 0, 0]
# Define the RBF neural network parameters
c = np.array([[-1], [1]])
w = np.array([0, 0])
# Define the training data
X_train = np.array([[-1], [1]])
Y_train = np.array([[0], [1000]])
# Train the RBF neural network
for i in range(1000):
w = RBF_nn_training(c, w, X_train, Y_train)
# Simulate the system dynamics
x = odeint(system_dynamics, x0, t, args=(c, w))
y = x[:,0]
y_d = plant_tf(s=t)
# Plot the results
plt.plot(t, y, label='y')
plt.plot(t, y_d, label='y_d')
plt.legend()
plt.show()
if __name__ == '__main__':
main()
```
解释如下:
1. 定义了被控对象的传递函数 `plant_tf(s)`,用于计算参考输出值 `y_d`。
2. 定义了 RBF 神经网络函数 `RBF_nn(x, c, w)`,其中 `x` 是输入向量,`c` 是中心向量,`w` 是权重向量。该函数用于计算控制输入值 `u`。
3. 定义了控制输入函数 `control_input(y, y_d, c, w)`,其中 `y` 是当前输出值,`y_d` 是参考输出值,`c` 和 `w` 是 RBF 神经网络参数。该函数用于计算控制输入值 `u`。
4. 定义了系统动力学函数 `system_dynamics(x, t, c, w)`,其中 `x` 是状态向量,`t` 是时间向量,`c` 和 `w` 是 RBF 神经网络参数。该函数用于计算状态向量的导数。
5. 定义了 RBF 神经网络训练函数 `RBF_nn_training(c, w, X_train, Y_train)`,其中 `c` 和 `w` 是初始的 RBF 神经网络参数,`X_train` 和 `Y_train` 是训练数据。该函数用于训练 RBF 神经网络参数。
6. 定义了主函数 `main()`,其中定义了时间向量 `t` 和初始状态向量 `x0`,然后定义了 RBF 神经网络参数 `c` 和 `w`,以及训练数据 `X_train` 和 `Y_train`。接着,使用训练数据训练 RBF 神经网络参数,并通过解微分方程模拟系统动力学。最后,绘制输出结果图像。
这份代码可以帮助你实现基于 RBF 神经网络的监督控制,并对被控对象进行控制。