Try to solve DAE( Differential-Algebraic Equation) using Simulink and s-function.
Use a simple case as example:
(of course, this example can be translated to ODE form if we let x3=1-x1-x2, 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 level-1 S-function and ‘Simulink/Signal Attributes/IC’ block to initialize x3. See the attached file ‘DAEexamp1.m’(S-function file) and ‘DAEcase_1st.mdl’(Simulink file).
3). Try to use iteration (fsolve) in Derivative block of level-1 s-function to get the value of x3. See the attached file ‘DAEexamp2.m’(S-function file) and ‘DAEcase_2nd.mdl’(Simulink file).
4). Use level-1 S-function and ‘Simulink/Math Operations/Algebraic Constraint’ block to initialize x3. See the attached file ‘DAEexamp3.m’(S-function 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 S-function, 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.
Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.