How does Matlab's RK4 solve an ODE?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
As we know, when we integrate the ODE with the fourth-order Runge-Kutta method we call the differential equations (function), named fx(), 4 times. But when I run a Simulink model with ode4
, Simulink executes model only 1 time, instead of 4. My simple model is shown here.
The output of MatlabFunction increases by 1 after every execution. Fix-step is chosen and equal 0.1s. Integration time is 0.1s. Output of block MatlabFunction is 1, while in Matlab code, realizing the same model, i've got 4.
So my question is, if Simulink really executes model only one time, instead of 4 times, on every step of ode4, in what meaning Simulink realizes the runge-kutta 4 method?
When using ode4, every time the function fx() is called, the inputs and ouputs may change their values (for example, when we integrate the equations of airplane motion, every time these equations are called we have got the different values of airplane state, of aerodynamic coefficients, of enviroment parameters, of engine state and ect). If Simulink executes model only 1 time per integration step, how it can ensure the numerical accuracy?
integration differential-equations matlab
add a comment |Â
up vote
1
down vote
favorite
As we know, when we integrate the ODE with the fourth-order Runge-Kutta method we call the differential equations (function), named fx(), 4 times. But when I run a Simulink model with ode4
, Simulink executes model only 1 time, instead of 4. My simple model is shown here.
The output of MatlabFunction increases by 1 after every execution. Fix-step is chosen and equal 0.1s. Integration time is 0.1s. Output of block MatlabFunction is 1, while in Matlab code, realizing the same model, i've got 4.
So my question is, if Simulink really executes model only one time, instead of 4 times, on every step of ode4, in what meaning Simulink realizes the runge-kutta 4 method?
When using ode4, every time the function fx() is called, the inputs and ouputs may change their values (for example, when we integrate the equations of airplane motion, every time these equations are called we have got the different values of airplane state, of aerodynamic coefficients, of enviroment parameters, of engine state and ect). If Simulink executes model only 1 time per integration step, how it can ensure the numerical accuracy?
integration differential-equations matlab
1
This looks like it is evaluated once symbolically, that is with a symbolic data type that constructs an expression tree, and only the part that computes the output from the input is retained in the parsed representation of the function. All other evaluations are done using this expression tree, not the supplied function.
– LutzL
Jul 26 at 8:39
@LutzL I tested the same block with discrete random numbers as input, and the result was correct, it means there isn't any symbolic solve as you mentioned
– e.jahandar
Jul 26 at 9:40
Also, there is no ODE in that diagram, it is just computing the anti-derivative which can be done by quadrature methods like the Simpson method. Simulink may be intelligent enough to recognize the constant input and thus evaluate the function just once, as the function value should be always the same. I see no reason why strange side effects of user supplied functions should be taken into account from the Simulink side.
– LutzL
Jul 26 at 15:23
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
As we know, when we integrate the ODE with the fourth-order Runge-Kutta method we call the differential equations (function), named fx(), 4 times. But when I run a Simulink model with ode4
, Simulink executes model only 1 time, instead of 4. My simple model is shown here.
The output of MatlabFunction increases by 1 after every execution. Fix-step is chosen and equal 0.1s. Integration time is 0.1s. Output of block MatlabFunction is 1, while in Matlab code, realizing the same model, i've got 4.
So my question is, if Simulink really executes model only one time, instead of 4 times, on every step of ode4, in what meaning Simulink realizes the runge-kutta 4 method?
When using ode4, every time the function fx() is called, the inputs and ouputs may change their values (for example, when we integrate the equations of airplane motion, every time these equations are called we have got the different values of airplane state, of aerodynamic coefficients, of enviroment parameters, of engine state and ect). If Simulink executes model only 1 time per integration step, how it can ensure the numerical accuracy?
integration differential-equations matlab
As we know, when we integrate the ODE with the fourth-order Runge-Kutta method we call the differential equations (function), named fx(), 4 times. But when I run a Simulink model with ode4
, Simulink executes model only 1 time, instead of 4. My simple model is shown here.
The output of MatlabFunction increases by 1 after every execution. Fix-step is chosen and equal 0.1s. Integration time is 0.1s. Output of block MatlabFunction is 1, while in Matlab code, realizing the same model, i've got 4.
So my question is, if Simulink really executes model only one time, instead of 4 times, on every step of ode4, in what meaning Simulink realizes the runge-kutta 4 method?
When using ode4, every time the function fx() is called, the inputs and ouputs may change their values (for example, when we integrate the equations of airplane motion, every time these equations are called we have got the different values of airplane state, of aerodynamic coefficients, of enviroment parameters, of engine state and ect). If Simulink executes model only 1 time per integration step, how it can ensure the numerical accuracy?
integration differential-equations matlab
edited Jul 26 at 8:50
Rodrigo de Azevedo
12.5k41751
12.5k41751
asked Jul 26 at 8:24
e.jahandar
1061
1061
1
This looks like it is evaluated once symbolically, that is with a symbolic data type that constructs an expression tree, and only the part that computes the output from the input is retained in the parsed representation of the function. All other evaluations are done using this expression tree, not the supplied function.
– LutzL
Jul 26 at 8:39
@LutzL I tested the same block with discrete random numbers as input, and the result was correct, it means there isn't any symbolic solve as you mentioned
– e.jahandar
Jul 26 at 9:40
Also, there is no ODE in that diagram, it is just computing the anti-derivative which can be done by quadrature methods like the Simpson method. Simulink may be intelligent enough to recognize the constant input and thus evaluate the function just once, as the function value should be always the same. I see no reason why strange side effects of user supplied functions should be taken into account from the Simulink side.
– LutzL
Jul 26 at 15:23
add a comment |Â
1
This looks like it is evaluated once symbolically, that is with a symbolic data type that constructs an expression tree, and only the part that computes the output from the input is retained in the parsed representation of the function. All other evaluations are done using this expression tree, not the supplied function.
– LutzL
Jul 26 at 8:39
@LutzL I tested the same block with discrete random numbers as input, and the result was correct, it means there isn't any symbolic solve as you mentioned
– e.jahandar
Jul 26 at 9:40
Also, there is no ODE in that diagram, it is just computing the anti-derivative which can be done by quadrature methods like the Simpson method. Simulink may be intelligent enough to recognize the constant input and thus evaluate the function just once, as the function value should be always the same. I see no reason why strange side effects of user supplied functions should be taken into account from the Simulink side.
– LutzL
Jul 26 at 15:23
1
1
This looks like it is evaluated once symbolically, that is with a symbolic data type that constructs an expression tree, and only the part that computes the output from the input is retained in the parsed representation of the function. All other evaluations are done using this expression tree, not the supplied function.
– LutzL
Jul 26 at 8:39
This looks like it is evaluated once symbolically, that is with a symbolic data type that constructs an expression tree, and only the part that computes the output from the input is retained in the parsed representation of the function. All other evaluations are done using this expression tree, not the supplied function.
– LutzL
Jul 26 at 8:39
@LutzL I tested the same block with discrete random numbers as input, and the result was correct, it means there isn't any symbolic solve as you mentioned
– e.jahandar
Jul 26 at 9:40
@LutzL I tested the same block with discrete random numbers as input, and the result was correct, it means there isn't any symbolic solve as you mentioned
– e.jahandar
Jul 26 at 9:40
Also, there is no ODE in that diagram, it is just computing the anti-derivative which can be done by quadrature methods like the Simpson method. Simulink may be intelligent enough to recognize the constant input and thus evaluate the function just once, as the function value should be always the same. I see no reason why strange side effects of user supplied functions should be taken into account from the Simulink side.
– LutzL
Jul 26 at 15:23
Also, there is no ODE in that diagram, it is just computing the anti-derivative which can be done by quadrature methods like the Simpson method. Simulink may be intelligent enough to recognize the constant input and thus evaluate the function just once, as the function value should be always the same. I see no reason why strange side effects of user supplied functions should be taken into account from the Simulink side.
– LutzL
Jul 26 at 15:23
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
Matlab has a number of basic solvers. There is no ode4 method. These are the methods listed.
If you're referring to ODE45. It is the Dormand Price method. It is a combination of the 4th and 5th order Runge-Kutte methods. How does it ensure accuracy? It is an adaptive algorithm. Since it knows the error approximation for fourth and fifth order it bounds them between them and makes local approximations. However, I am not sure how this works with Simulink exactly.
The method by which Runge Kutta methods work is the same. It interpolates in space uses a Butcher Tableau. This is known as a predictor-corrector method. There is an infinite family of them. The higher the order you would seemingly get better accuracy but it takes more time. The tableau gives you the coefficients for the polynomials.
It looks like you can get semi-official functions called ode1, ode2, etc. in a zip file from MathWorks. See mathworks.com/matlabcentral/answers/… I assume this is what the OP is using?
– Ian
Jul 26 at 15:23
1
But does the standard integration box in Simulink allow for user-supplied integrators or does it use some fixed summation method, possibly different from the usual ODE solvers?
– LutzL
Jul 26 at 15:28
@Ian i realize you can download the normal methods but I'm also confused whether his simulink model is actually doing anything.
– RHowe
Jul 26 at 15:29
@LutzL he says it is working but I'm not sure if he is referring to a supplied method or the matlab method.
– RHowe
Jul 26 at 15:36
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Matlab has a number of basic solvers. There is no ode4 method. These are the methods listed.
If you're referring to ODE45. It is the Dormand Price method. It is a combination of the 4th and 5th order Runge-Kutte methods. How does it ensure accuracy? It is an adaptive algorithm. Since it knows the error approximation for fourth and fifth order it bounds them between them and makes local approximations. However, I am not sure how this works with Simulink exactly.
The method by which Runge Kutta methods work is the same. It interpolates in space uses a Butcher Tableau. This is known as a predictor-corrector method. There is an infinite family of them. The higher the order you would seemingly get better accuracy but it takes more time. The tableau gives you the coefficients for the polynomials.
It looks like you can get semi-official functions called ode1, ode2, etc. in a zip file from MathWorks. See mathworks.com/matlabcentral/answers/… I assume this is what the OP is using?
– Ian
Jul 26 at 15:23
1
But does the standard integration box in Simulink allow for user-supplied integrators or does it use some fixed summation method, possibly different from the usual ODE solvers?
– LutzL
Jul 26 at 15:28
@Ian i realize you can download the normal methods but I'm also confused whether his simulink model is actually doing anything.
– RHowe
Jul 26 at 15:29
@LutzL he says it is working but I'm not sure if he is referring to a supplied method or the matlab method.
– RHowe
Jul 26 at 15:36
add a comment |Â
up vote
0
down vote
Matlab has a number of basic solvers. There is no ode4 method. These are the methods listed.
If you're referring to ODE45. It is the Dormand Price method. It is a combination of the 4th and 5th order Runge-Kutte methods. How does it ensure accuracy? It is an adaptive algorithm. Since it knows the error approximation for fourth and fifth order it bounds them between them and makes local approximations. However, I am not sure how this works with Simulink exactly.
The method by which Runge Kutta methods work is the same. It interpolates in space uses a Butcher Tableau. This is known as a predictor-corrector method. There is an infinite family of them. The higher the order you would seemingly get better accuracy but it takes more time. The tableau gives you the coefficients for the polynomials.
It looks like you can get semi-official functions called ode1, ode2, etc. in a zip file from MathWorks. See mathworks.com/matlabcentral/answers/… I assume this is what the OP is using?
– Ian
Jul 26 at 15:23
1
But does the standard integration box in Simulink allow for user-supplied integrators or does it use some fixed summation method, possibly different from the usual ODE solvers?
– LutzL
Jul 26 at 15:28
@Ian i realize you can download the normal methods but I'm also confused whether his simulink model is actually doing anything.
– RHowe
Jul 26 at 15:29
@LutzL he says it is working but I'm not sure if he is referring to a supplied method or the matlab method.
– RHowe
Jul 26 at 15:36
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Matlab has a number of basic solvers. There is no ode4 method. These are the methods listed.
If you're referring to ODE45. It is the Dormand Price method. It is a combination of the 4th and 5th order Runge-Kutte methods. How does it ensure accuracy? It is an adaptive algorithm. Since it knows the error approximation for fourth and fifth order it bounds them between them and makes local approximations. However, I am not sure how this works with Simulink exactly.
The method by which Runge Kutta methods work is the same. It interpolates in space uses a Butcher Tableau. This is known as a predictor-corrector method. There is an infinite family of them. The higher the order you would seemingly get better accuracy but it takes more time. The tableau gives you the coefficients for the polynomials.
Matlab has a number of basic solvers. There is no ode4 method. These are the methods listed.
If you're referring to ODE45. It is the Dormand Price method. It is a combination of the 4th and 5th order Runge-Kutte methods. How does it ensure accuracy? It is an adaptive algorithm. Since it knows the error approximation for fourth and fifth order it bounds them between them and makes local approximations. However, I am not sure how this works with Simulink exactly.
The method by which Runge Kutta methods work is the same. It interpolates in space uses a Butcher Tableau. This is known as a predictor-corrector method. There is an infinite family of them. The higher the order you would seemingly get better accuracy but it takes more time. The tableau gives you the coefficients for the polynomials.
edited Jul 26 at 15:17
answered Jul 26 at 15:08


RHowe
975715
975715
It looks like you can get semi-official functions called ode1, ode2, etc. in a zip file from MathWorks. See mathworks.com/matlabcentral/answers/… I assume this is what the OP is using?
– Ian
Jul 26 at 15:23
1
But does the standard integration box in Simulink allow for user-supplied integrators or does it use some fixed summation method, possibly different from the usual ODE solvers?
– LutzL
Jul 26 at 15:28
@Ian i realize you can download the normal methods but I'm also confused whether his simulink model is actually doing anything.
– RHowe
Jul 26 at 15:29
@LutzL he says it is working but I'm not sure if he is referring to a supplied method or the matlab method.
– RHowe
Jul 26 at 15:36
add a comment |Â
It looks like you can get semi-official functions called ode1, ode2, etc. in a zip file from MathWorks. See mathworks.com/matlabcentral/answers/… I assume this is what the OP is using?
– Ian
Jul 26 at 15:23
1
But does the standard integration box in Simulink allow for user-supplied integrators or does it use some fixed summation method, possibly different from the usual ODE solvers?
– LutzL
Jul 26 at 15:28
@Ian i realize you can download the normal methods but I'm also confused whether his simulink model is actually doing anything.
– RHowe
Jul 26 at 15:29
@LutzL he says it is working but I'm not sure if he is referring to a supplied method or the matlab method.
– RHowe
Jul 26 at 15:36
It looks like you can get semi-official functions called ode1, ode2, etc. in a zip file from MathWorks. See mathworks.com/matlabcentral/answers/… I assume this is what the OP is using?
– Ian
Jul 26 at 15:23
It looks like you can get semi-official functions called ode1, ode2, etc. in a zip file from MathWorks. See mathworks.com/matlabcentral/answers/… I assume this is what the OP is using?
– Ian
Jul 26 at 15:23
1
1
But does the standard integration box in Simulink allow for user-supplied integrators or does it use some fixed summation method, possibly different from the usual ODE solvers?
– LutzL
Jul 26 at 15:28
But does the standard integration box in Simulink allow for user-supplied integrators or does it use some fixed summation method, possibly different from the usual ODE solvers?
– LutzL
Jul 26 at 15:28
@Ian i realize you can download the normal methods but I'm also confused whether his simulink model is actually doing anything.
– RHowe
Jul 26 at 15:29
@Ian i realize you can download the normal methods but I'm also confused whether his simulink model is actually doing anything.
– RHowe
Jul 26 at 15:29
@LutzL he says it is working but I'm not sure if he is referring to a supplied method or the matlab method.
– RHowe
Jul 26 at 15:36
@LutzL he says it is working but I'm not sure if he is referring to a supplied method or the matlab method.
– RHowe
Jul 26 at 15:36
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2863206%2fhow-does-matlabs-rk4-solve-an-ode%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
This looks like it is evaluated once symbolically, that is with a symbolic data type that constructs an expression tree, and only the part that computes the output from the input is retained in the parsed representation of the function. All other evaluations are done using this expression tree, not the supplied function.
– LutzL
Jul 26 at 8:39
@LutzL I tested the same block with discrete random numbers as input, and the result was correct, it means there isn't any symbolic solve as you mentioned
– e.jahandar
Jul 26 at 9:40
Also, there is no ODE in that diagram, it is just computing the anti-derivative which can be done by quadrature methods like the Simpson method. Simulink may be intelligent enough to recognize the constant input and thus evaluate the function just once, as the function value should be always the same. I see no reason why strange side effects of user supplied functions should be taken into account from the Simulink side.
– LutzL
Jul 26 at 15:23