# 求解刚性晶体管微分代数方程

• 初始电压信号为 ${U}_{e}\left(t\right)=0.4\mathrm{sin}\left(200\pi t\right)$

• 工作电压为 ${\mathit{U}}_{\mathit{b}}=6$

• 节点处的电压由 ${\mathit{U}}_{\mathit{i}}\left(\mathit{t}\right)\text{}\left(\mathit{i}=1,2,3,4,5\right)$ 给出。

• 电阻 ${\mathit{R}}_{\mathit{i}}\text{}\left(\mathit{i}=1,2,3,4,5,6\right)$ 的值是常量，通过每个电阻的电流满足 $\mathit{I}=\mathit{U}/\mathit{R}$

• 电容 ${\mathit{C}}_{\mathit{i}}\text{}\left(\mathit{i}=1,2,3\right)$ 的值是常量，通过每个电容的电流满足 $\mathit{I}=\mathit{C}\cdot \mathrm{dU}/\mathrm{dt}$

### 编写质量矩阵代码

`$\begin{array}{l}\mathrm{node}\text{\hspace{0.17em}}1:\text{\hspace{0.17em}\hspace{0.17em}}\frac{{\mathit{U}}_{\mathit{e}}\left(\mathit{t}\right)}{{\mathit{R}}_{0}}-\frac{{\mathit{U}}_{1}}{{\mathit{R}}_{0}}+{\mathit{C}}_{1}\left({{\mathit{U}}_{2}}^{\prime }-{{\mathit{U}}_{1}}^{\prime }\right)=0,\\ \mathrm{node}\text{\hspace{0.17em}}2:\text{\hspace{0.17em}\hspace{0.17em}}\frac{{\mathit{U}}_{\mathit{b}}}{{\mathit{R}}_{2}}-{\mathit{U}}_{2}\left(\frac{1}{{\mathit{R}}_{1}}+\frac{1}{{\mathit{R}}_{2}}\right)+{\mathit{C}}_{1}\left({{\mathit{U}}_{1}}^{\prime }-{{\mathit{U}}_{2}}^{\prime }\right)-0.01\mathit{f}\left({\mathit{U}}_{2}-{\mathit{U}}_{3}\right)=0,\\ \mathrm{node}\text{\hspace{0.17em}}3:\text{\hspace{0.17em}}\text{\hspace{0.17em}}\mathit{f}\left({\mathit{U}}_{2}-{\mathit{U}}_{3}\right)-\frac{{\mathit{U}}_{3}}{{\mathit{R}}_{3}}-{\mathit{C}}_{2}{{\mathit{U}}_{3}}^{\prime }=0,\\ \mathrm{node}\text{\hspace{0.17em}}4:\text{\hspace{0.17em}\hspace{0.17em}}\frac{{\mathit{U}}_{\mathit{b}}}{{\mathit{R}}_{4}}-\frac{{\mathit{U}}_{4}}{{\mathit{R}}_{4}}+{\mathit{C}}_{3}\left({{\mathit{U}}_{5}}^{\prime }-{{\mathit{U}}_{4}}^{\prime }\right)-0.99\mathit{f}\left({\mathit{U}}_{2}-{\mathit{U}}_{3}\right)=0,\\ \mathrm{node}\text{\hspace{0.17em}}5:\text{\hspace{0.17em}}\text{\hspace{0.17em}}-\frac{{\mathit{U}}_{5}}{{\mathit{R}}_{5}}+{\mathit{C}}_{3}\left({{\mathit{U}}_{4}}^{\prime }-{{\mathit{U}}_{5}}^{\prime }\right)=0.\end{array}$`

`$M=\left(\begin{array}{ccccc}-{c}_{1}& {c}_{1}& 0& 0& 0\\ {c}_{1}& -{c}_{1}& 0& 0& 0\\ 0& 0& -{c}_{2}& 0& 0\\ 0& 0& 0& -{c}_{3}& {c}_{3}\\ 0& 0& 0& {c}_{3}& -{c}_{3}\end{array}\right),$`

```c = 1e-6 * (1:3); M = zeros(5,5); M(1,1) = -c(1); M(1,2) = c(1); M(2,1) = c(1); M(2,2) = -c(1); M(3,3) = -c(2); M(4,4) = -c(3); M(4,5) = c(3); M(5,4) = c(3); M(5,5) = -c(3); opts = odeset('Mass',M);```

### 编写方程代码

```function dudt = transampdae(t,u) % Define voltages and parameters Ue = @(t) 0.4*sin(200*pi*t); Ub = 6; R0 = 1000; R15 = 9000; alpha = 0.99; beta = 1e-6; Uf = 0.026; % Define system of equations f23 = beta*(exp((u(2) - u(3))/Uf) - 1); dudt = [ -(Ue(t) - u(1))/R0 -(Ub/R15 - u(2)*2/R15 - (1-alpha)*f23) -(f23 - u(3)/R15) -((Ub - u(4))/R15 - alpha*f23) (u(5)/R15) ]; end ```

### 编写初始条件代码

```Ub = 6; u0(1) = 0; u0(2) = Ub/2; u0(3) = Ub/2; u0(4) = Ub; u0(5) = 0;```

### 求解方程组

```tspan = [0 0.05]; [t,u] = ode23t(@transampdae,tspan,u0,opts);```

### 绘制结果

```Ue = @(t) 0.4*sin(200*pi*t); plot(t,Ue(t),'o',t,u(:,5),'.') axis([0 0.05 -3 2]); legend('Input Voltage U_e(t)','Output Voltage U_5(t)','Location','NorthWest'); title('One Transistor Amplifier DAE Problem Solved by ODE23T'); xlabel('t');```

### 参考

[1] Hairer, E., and Gerhard Wanner.Solving Ordinary Differential Equations II:Stiff and Differential-Algebraic Problems.Springer Berlin Heidelberg, 1991, p. 377.

### 局部函数

```function dudt = transampdae(t,u) % Define voltages and parameters Ue = @(t) 0.4*sin(200*pi*t); Ub = 6; R0 = 1000; R15 = 9000; alpha = 0.99; beta = 1e-6; Uf = 0.026; % Define system of equations f23 = beta*(exp((u(2) - u(3))/Uf) - 1); dudt = [ -(Ue(t) - u(1))/R0 -(Ub/R15 - u(2)*2/R15 - (1-alpha)*f23) -(f23 - u(3)/R15) -((Ub - u(4))/R15 - alpha*f23) (u(5)/R15) ]; end```