美文网首页
利用matlab:非线性微分方程离散化转差分方程(附代码)

利用matlab:非线性微分方程离散化转差分方程(附代码)

作者: 该_大白 | 来源:发表于2020-12-14 18:29 被阅读0次

关键字:机理模型、泰勒展开、传递函数、Z 变换、连续系统离散化

1. 选定 CFR (Continuous Fermentation Reactor) 的机理模型作为实例对象
\dot{h}_1=-uh_1+\mu h_1 \dot{h}_2=u\left( S_f-h_2 \right) -\mu h_1/Y_{X/S} \dot{h}_3=-uh_3+\left( \alpha \mu +\beta \right) h_1 \text{其中:}\mu =\mu _m\left( 1-h_3/P_m \right) h_2\left( K_m+h_2+h_{2}^{2}/K_i \right) ^{-1} Y_{X/S}=0.4\text{;}S_f=20\text{;}\alpha =2.2\text{;}\beta =0.2\text{;} \mu _m=0.48;P_m=50;K_m=1.2;K_i=22.
h_1 为生物浓度,作为输出;u 为稀释率,作为输入。为方便推到,做如下标记:
h=[h_1,h_2,h_3]^Tf=[f_1,f_2,f_3]^T,其中:f_1=\dot{h}_1f_2=\dot{h}_2f_3=\dot{h}_3
这样我们将模型简化为:\dot{h}=f(h,u)y=g(h)=Ch=[1 \quad 0 \quad 0]h=h_1

2. 对模型进行泰勒展开前,需要先找到一个稳态点
先取一个输入值:u_0=0.175,令 f(h,u_0)=0,解得多组解,取合适的一组即可。 h_0=[6.6922,3.2695,22.3711]为本文所选。顺便可得:f(h_0,u_0)=0;g(h_0)=6.6922

3. 泰勒展开
\dot{h}=f\left( h_0,u_0 \right) +\frac{\partial f}{\partial h}|_{h_0,u_0}\left( h-h_0 \right) +\frac{\partial f}{\partial u}|_{h_0,u_0}\left( u-u_0 \right) y=g\left( h_0 \right) +\frac{\partial g}{\partial h}|_{h_0}\left( h-h_0 \right) \text{标记:}\tilde{h}=h-h_0\text{;}\tilde{u}=u-u_0\text{;}\tilde{y}=y-y_0\ \left( y_0=g\left( h_0 \right) \right) A=\frac{\partial f}{\partial h}|_{h_0,u_0}\text{;}B=\frac{\partial f}{\partial u}|_{h_0,u_0}\text{;}C=\frac{\partial g}{\partial h}|_{h_0} =[1\quad0\quad 0] \frac{d\tilde{h}}{dt}=A\tilde{h}+B\tilde{u}\text{;}\tilde{y}=C\tilde{h}\text{(状态空间方程) }
其中偏导公式为:\frac{\partial f}{\partial h}=\left[ \begin{matrix} \frac{\partial f_1}{\partial h_1}& \frac{\partial f_1}{\partial h_2}& \frac{\partial f_1}{\partial h_3}\\ \frac{\partial f_2}{\partial h_1}& \frac{\partial f_2}{\partial h_2}& \frac{\partial f_2}{\partial h_3}\\ \frac{\partial f_3}{\partial h_1}& \frac{\partial f_3}{\partial h_2}& \frac{\partial f_3}{\partial h_3}\\ \end{matrix} \right] \text{,}\frac{\partial f}{\partial u}=\left[ \begin{array}{c} \frac{\partial f_1}{\partial u}\\ \frac{\partial f_2}{\partial u}\\ \frac{\partial f_3}{\partial u}\\ \end{array} \right]
带入稳态值即可计算 A,B。
A=\left[ \begin{matrix} 0.0000& 0.0516& -0.0424\\ -0.4375& -0.3040& 0.1060\\ 0.5850& 0.1136& -0.2683\\ \end{matrix} \right] \text{;}B=\left[ \begin{array}{c} -6.6922\\ 16.7305\\ -22.3711\\ \end{array} \right]
4. 由状态空间方程求传递函数

H(s) =
      -6.692 s^2 - 2.018 s - 0.1482
    ---------------------------------------
    s^3 + 0.5723 s^2 + 0.1169 s + 0.008292
Continuous-time transfer function.

s 域到 z 域:

H(z) =
     -5.85 z^2 + 10.07 z - 4.327
     ----------------------------------
     z^3 - 2.473 z^2 + 2.043 z - 0.5642
Sample time: 1 seconds
Discrete-time transfer function.

依据 H(z) 可得到最终的差分方程。
matlab 实现代码:

求导
设置参数值
clc;clear;
close all
syms h1 h2 h3 u;
y=0.4;
alph=2.2;
bet=0.2;
mum=0.48;
Pm=50;
Km=1.2;
Ki=22;
Sf=20;
mu=mum*(1-h3/Pm)*h2/(Km+h2+h2^2/Ki);
表示函数 ,并分别对变量求偏导
f1 = -u*h1+mu*h1;
df1h1 = diff(f1, h1);
df1h2 = diff(f1, h2);
df1h3 = diff(f1, h3);  
df1u = diff(f1, u); 

f2 = u*(Sf-h2)-mu*h1/y;
df2h1 = diff(f2, h1);    
df2h2 = diff(f2, h2);    
df2h3 = diff(f2, h3);  
df2u = diff(f2, u); 

f3 = -u*h3+(alph*mu+bet)*h1;
df3h1 = diff(f3, h1);    
df3h2 = diff(f3, h2);    
df3h3 = diff(f3, h3);  
df3u = diff(f3, u);
解方程组找稳态点:给定一个输入带入方程,求出稳态点
us=0.175;
f11=subs(f1,'u',us);
f22=subs(f2,'u',us);
f33=subs(f3,'u',us);
eqns=[f11,f22,f33];
vars=[h1 h2 h3];
[h1s,h2s,h3s]=solve(eqns,vars);
hs=double([h1s h2s h3s]) % 稳态值(有多个解)

带入稳态值后得到线性化方程组:状态空间方程
F1=[df1h1 df1h2 df1h3;df2h1 df2h2 df2h3;df3h1 df3h2 df3h3];% 偏导 df/dh
F2=[df1u;df2u;df3u];% 偏导 df/du
US=[hs(2,:) us];% 稳态点
A=double(subs(F1,[h1 h2 h3 u],US))
B=double(subs(F2,[h1 h2 h3 u],US))
C=[1 0 0];
D=0;
依据求得的状态空间方程离散化
% [Ad,Bd]=c2d(A,B,1) % 离散化
% [num,den]=ss2tf(Ad,Bd,C,D) % 状态空间变传递函数
% sysd1=tf(num,den)

[num,den]=ss2tf(A,B,C,D) % 状态空间变传递函数
sys=tf(num,den)
ts=1;% 采样
sysd2=c2d(sys,ts) 
[num, den] = tfdata(sysd2,'v')

N=1200;
theta=[-den(2:end) num(2:end) sum(den)*US(1)-sum(num)*US(4)] 
Du=idinput(N,'rbs',[0,0.08],[0.175 0.19]);
y1=zeros(N,1);
y1(1)=theta*[0 0 0 0 0 0 1]';
y1(2)=theta*[y1(1) 0 0 Du(1) 0 0 1]';
y1(3)=theta*[y1(2) y1(1) 0 Du(2) Du(1) 0 1]';
for t=4:N
    y1(t)=theta*[y1(t-1) y1(t-2) y1(t-3) Du(t-1) Du(t-2) Du(t-3) 1]';
end
subplot(2,1,1)
plot(Du(201:N),'r-.',"LineWidth",1)
subplot(2,1,2)
plot(y1(201:N),'r-.',"LineWidth",1)

相关文章

网友评论

      本文标题:利用matlab:非线性微分方程离散化转差分方程(附代码)

      本文链接:https://www.haomeiwen.com/subject/lywvgktx.html