Several methods for Solving DAE cases using Simulink and S-fucntion

Try to solve DAE case using Simulink and S-function, compared the results and CPU time.
1.2K Downloads
Updated 23 Apr 2009

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
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Block Libraries in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0