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

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

1. 选定 CFR (Continuous Fermentation Reactor) 的机理模型作为实例对象

为生物浓度,作为输出; 为稀释率,作为输入。为方便推到,做如下标记:
,,其中:,,。
这样我们将模型简化为:;

2. 对模型进行泰勒展开前,需要先找到一个稳态点
先取一个输入值:,令 ,解得多组解,取合适的一组即可。 为本文所选。顺便可得:。

3. 泰勒展开

其中偏导公式为:\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。

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.

依据 可得到最终的差分方程。
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:非线性微分方程离散化转差分方程(附代码))