示例:RLC电路微分方程 L d 2 i ( t ) d t 2 + R d i ( t ) d t + 1 C i ( t ) = v i n ( t ) L\frac{d^2i(t)}{dt^2} + R\frac{di(t)}{dt} + \frac{1}{C}i(t) = v_{in}(t) Ldt2d2i(t)+Rdtdi(t)+C1i(t)=vin(t)
特点:
时域连续描述
需要解析解或数值解
1.2 差分方程建模
核心思想:用离散时间步长描述系统变化
典型应用:数字滤波器、经济预测模型
示例:一阶线性差分方程 y [ n ] = a y [ n − 1 ] + b x [ n ] y[n] = a y[n-1] + b x[n] y[n]=ay[n−1]+bx[n]
特点:
适合计算机实现
可直接转化为Z变换分析
1.3 状态空间建模
核心思想:用状态变量组描述系统全貌
数学形式: { x ˙ ( t ) = A x ( t ) + B u ( t ) y ( t ) = C x ( t ) + D u ( t ) \begin{cases} \dot{\mathbf{x}}(t) = A\mathbf{x}(t) + B\mathbf{u}(t) \\ \mathbf{y}(t) = C\mathbf{x}(t) + D\mathbf{u}(t) \end{cases} {x˙(t)=Ax(t)+Bu(t)y(t)=Cx(t)+Du(t)
特点:
多输入多输出系统通用描述
适合现代控制理论
2. AI驱动的系统建模
2.1 从微分方程到神经网络
传统建模局限:
需要精确物理规律
非线性系统难以建模
AI建模优势:
数据驱动建模
自动学习复杂非线性关系
2.2 递归神经网络(RNN)
核心结构:
带有循环连接的神经元
记忆单元存储历史信息
数学表达: h t = σ ( W h h h t − 1 + W x h x t ) \mathbf{h}_t = \sigma(\mathbf{W}_{hh} \mathbf{h}_{t-1} + \mathbf{W}_{xh} \mathbf{x}_t) ht=σ(Whhht−1+Wxhxt) y t = W h y h t \mathbf{y}_t = \mathbf{W}_{hy} \mathbf{h}_t yt=Whyht
数学表达(简化版): f t = σ ( W f ⋅ [ h t − 1 , x t ] ) f_t = \sigma(\mathbf{W}_f \cdot [\mathbf{h}_{t-1}, \mathbf{x}_t]) ft=σ(Wf⋅[ht−1,xt]) i t = σ ( W i ⋅ [ h t − 1 , x t ] ) i_t = \sigma(\mathbf{W}_i \cdot [\mathbf{h}_{t-1}, \mathbf{x}_t]) it=σ(Wi⋅[ht−1,xt]) C ~ t = tanh ( W C ⋅ [ h t − 1 , x t ] ) \tilde{C}_t = \tanh(\mathbf{W}_C \cdot [\mathbf{h}_{t-1}, \mathbf{x}_t]) C~t=tanh(WC⋅[ht−1,xt]) C t = f t ⊙ C t − 1 + i t ⊙ C ~ t C_t = f_t \odot C_{t-1} + i_t \odot \tilde{C}_t Ct=ft⊙Ct−1+it⊙C~t o t = σ ( W o ⋅ [ h t − 1 , x t ] ) o_t = \sigma(\mathbf{W}_o \cdot [\mathbf{h}_{t-1}, \mathbf{x}_t]) ot=σ(Wo⋅[ht−1,xt]) h t = o t ⊙ tanh ( C t ) h_t = o_t \odot \tanh(C_t) ht=ot⊙tanh(Ct)
3. 系统建模与AI建模的对比
维度
传统系统建模
AI建模(RNN/LSTM)
建模基础
物理规律/经验公式
数据驱动
表达能力
有限(依赖数学形式)
强大(任意非线性关系)
可解释性
高(参数有明确物理意义)
低(黑箱模型)
计算效率
高(解析解/数值解)
中(依赖迭代训练)
适用场景
确定性系统
复杂非线性系统
4. Python实践:用TensorFlow构建RNN模型
4.1 数据准备
import numpy as np
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import SimpleRNN, Dense# 生成示例数据:预测下一个数值defgenerate_data(seq_len=10, num_samples=1000):X, y =[],[]for _ inrange(num_samples):seq = np.random.rand(seq_len)X.append(seq[:-1])y.append(seq[-1])return np.array(X), np.array(y)X, y = generate_data()
4.2 模型构建
model = Sequential([SimpleRNN(64, input_shape=(X.shape[1],1)),Dense(1)])model.compile(optimizer='adam', loss='mse')
4.3 模型训练
X = X.reshape((X.shape[0], X.shape[1],1))
history = model.fit(X, y, epochs=20, batch_size=32, validation_split=0.2)
4.4 模型评估
import matplotlib.pyplot as pltplt.plot(history.history['loss'], label='Train Loss')
plt.plot(history.history['val_loss'], label='Val Loss')
plt.legend()
plt.title('Training and Validation Loss')
plt.xlabel('Epoch')
plt.ylabel('Loss')
plt.grid(True)
plt.show()