Several methods for Solving DAE cases using Simulink and S-fucntion
No License
Try to solve DAE( Differential-Algebraic Equation) using Simulink and s-function.
Use a simple case as example:
der(x1)=-0.2*x1+x2*x3+0.3*x1*x2;
der(x2)=2*x1*x2-5*x2*x3-2*x2^2;
-1+x1+x2+x3=0;
(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.
Cite As
Fengcheng Sun (2024). Several methods for Solving DAE cases using Simulink and S-fucntion (https://www.mathworks.com/matlabcentral/fileexchange/23869-several-methods-for-solving-dae-cases-using-simulink-and-s-fucntion), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 |