Why in Simulink a Matlab function block changes its output when changing the solver?

1 回表示 (過去 30 日間)
Dani Tormo
Dani Tormo 2016 年 4 月 22 日
編集済み: Azzi Abdelmalek 2016 年 4 月 22 日
Hello,
I have in Simulink a Matlab function block with some equations written inside.
The problem comes when I change the solver from ODE1 (Euler) to ODE4 (Runge-Kutta), always using fixed step time.
How come that I get different output values if the outputs are direct equations of the inputs? Should not be they the same independently of the solver I chose?
Here the code:
function x = fcn(T, A, B, u)
persistent x_1 u_1
if isempty(x_1)
x_1 = 0;
u_1 = 0;
end
x = x_1 + T * (A * x_1 + B * u_1);
x_1 = x;
u_1 = u;
Thanks!

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 22 日
編集済み: Azzi Abdelmalek 2016 年 4 月 22 日
It happens that Simulink gives different results for different solvers, especially when the type of equations it has to solve, requires an appropriate solver. Read how to choose a solver. http://www.mathworks.com/help/simulink/ug/types-of-solvers.html

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by