Main Content

Solve Stiff Transistor Differential Algebraic Equation

This example shows how to solve a stiff differential algebraic equation (DAE) that describes an electrical circuit [1]. The one-transistor amplifier problem coded in the example file amp1dae.m can be rewritten in semi-explicit form, but this example solves it in its original form Mu=ϕ(u). The problem includes a constant, singular mass matrix M.

The transistor amplifier circuit contains six resistors, three capacitors, and a transistor.

  • The initial voltage signal is Ue(t)=0.4sin(200πt).

  • The operating voltage is Ub=6.

  • The voltages at the nodes are given by Ui(t)  (i=1,2,3,4,5).

  • The values of the resistors Ri  (i=1,2,3,4,5,6) are constant, and the current through each resistor satisfies I=U/R.

  • The values of the capacitors Ci  (i=1,2,3) are constant, and the current through each capacitor satisfies I=CdU/dt.

The goal is to solve for the output voltage through node 5, U5(t).

To solve this equation in MATLAB®, you can use an ode object and set properties of the object to define the equations, mass matrix, and initial conditions. Then, use the solve method to simulate the system over time. You can either include the required functions as functions within a script (as done here), or save them as separate, named files in a directory on the MATLAB path.

Code Mass Matrix

Using Kirchoff's law to equalize the current through each node (1 through 5), you can obtain a system of five equations describing the circuit:

node1:  Ue(t)R0-U1R0+C1(U2-U1)=0,node2:  UbR2-U2(1R1+1R2)+C1(U1-U2)-0.01f(U2-U3)=0,node3:f(U2-U3)-U3R3-C2U3=0,node4:  UbR4-U4R4+C3(U5-U4)-0.99f(U2-U3)=0,node5:-U5R5+C3(U4-U5)=0.

The mass matrix of this system, found by collecting the derivative terms on the left side of the equations, has the form

M=(-c1c1000c1-c100000-c200000-c3c3000c3-c3),

where ck=k×10-6 for k=1,2,3.

Create a mass matrix with the appropriate constants ck, and then create an odeMassMatrix object to store the mass matrix. Even though it is apparent that the mass matrix is singular, leave the Singular property at its default value of "maybe" to test the automatic detection of a DAE problem by the solver.

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);
Mass = odeMassMatrix(MassMatrix=M);

Code Equations

The function transampdae contains the system of equations for this example. The function defines values for all of the voltages and constant parameters. The derivatives gathered on the left side of the equations are coded in the mass matrix, and transampdae codes the right side of the equations.

function dudt = transampdae(t,u)
% Define voltages and parameters
Ue = @(t) 0.4*sinpi(200*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

Code Initial Conditions

Set the initial conditions. This example uses the consistent initial conditions for the current through each node computed in [1].

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

Solve System of Equations

Create an ode object to describe the problem, setting the values of the ODEFcn, MassMatrix, and InitialValue properties. Also, select the ode23t solver to solve the problem.

F = ode(ODEFcn=@transampdae,MassMatrix=Mass,InitialValue=u0,Solver="ode23t")
F = 
  ode with properties:

   Problem definition
               ODEFcn: @transampdae
          InitialTime: 0
         InitialValue: [0 3 3 6 0]
             Jacobian: []
           MassMatrix: [1x1 odeMassMatrix]
         EquationType: standard

   Solver properties
    AbsoluteTolerance: 1.0000e-06
    RelativeTolerance: 1.0000e-03
               Solver: ode23t

  Show all properties


Solve the DAE system over the time interval [0 0.05] using the solve method.

S = solve(F,0,0.05);
t = S.Time;
u = S.Solution;

Plot Results

Plot the initial voltage Ue(t) and output voltage through node 5, U5(t).

Ue = @(t) 0.4*sinpi(200*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");

Figure contains an axes object. The axes object with title One Transistor Amplifier DAE Problem Solved by ODE23T, xlabel t contains 2 objects of type line. One or more of the lines displays its values using only markers These objects represent Input Voltage U_e(t), Output Voltage U_5(t).

References

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

See Also

|

Related Topics