Try to solve DAE( DifferentialAlgebraic Equation) using Simulink and sfunction.
Use a simple case as example:
der(x1)=0.2*x1+x2*x3+0.3*x1*x2;
der(x2)=2*x1*x25*x2*x32*x2^2;
1+x1+x2+x3=0;
(of course, this example can be translated to ODE form if we let x3=1x1x2, but for more complicated cases, this might be impossible, here we just keep this form).
1).Build this case in Simulink only. Use the block ‘Simulink/Math Operations/Algebraic Constraint’. See the attached file ‘DAEcase_simulink.mdl’.
2). Use level1 Sfunction and ‘Simulink/Signal Attributes/IC’ block to initialize x3. See the attached file ‘DAEexamp1.m’(Sfunction file) and ‘DAEcase_1st.mdl’(Simulink file).
3). Try to use iteration (fsolve) in Derivative block of level1 sfunction to get the value of x3. See the attached file ‘DAEexamp2.m’(Sfunction file) and ‘DAEcase_2nd.mdl’(Simulink file).
4). Use level1 Sfunction and ‘Simulink/Math Operations/Algebraic Constraint’ block to initialize x3. See the attached file ‘DAEexamp3.m’(Sfunction file) and ‘DAEcase_3rd.mdl’(Simulink file).
The simulation results are the same, but CPU time costs are different [1):0.121079s 2):0.160547s 3):0.513035s 4):0.167822s]. It seems the first method is the fastest, but for more complicated case, method 1 is impossible. In these 3 cases using Sfunction, Method 3 is much slower, but when I compare the CPU time cost using a more complicated case , it shows this method is faster than 2) and 4).
What I want to ask is: are all these methods correct? Which one is the best? Has any other method to solve DAE case? What’s more, I compared the solvers of Matlab(ode15s: for DAE and stiff case, it’s the fastest in Simulink) and Dassl, Dassl is almost more than 10X faster than ode15s, does anyone know how to accelerate Simulink simulation speed?
You are welcome to send me your comments and questions. Thanks.
