How does Matlab's RK4 solve an ODE?












1












$begingroup$


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.



ODE4 Solver



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?










share|cite|improve this question











$endgroup$








  • 1




    $begingroup$
    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.
    $endgroup$
    – LutzL
    Jul 26 '18 at 8:39










  • $begingroup$
    @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
    $endgroup$
    – e.jahandar
    Jul 26 '18 at 9:40










  • $begingroup$
    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.
    $endgroup$
    – LutzL
    Jul 26 '18 at 15:23


















1












$begingroup$


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.



ODE4 Solver



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?










share|cite|improve this question











$endgroup$








  • 1




    $begingroup$
    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.
    $endgroup$
    – LutzL
    Jul 26 '18 at 8:39










  • $begingroup$
    @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
    $endgroup$
    – e.jahandar
    Jul 26 '18 at 9:40










  • $begingroup$
    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.
    $endgroup$
    – LutzL
    Jul 26 '18 at 15:23
















1












1








1


0



$begingroup$


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.



ODE4 Solver



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?










share|cite|improve this question











$endgroup$




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.



ODE4 Solver



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 ordinary-differential-equations matlab






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Jul 26 '18 at 8:50









Rodrigo de Azevedo

13.2k41962




13.2k41962










asked Jul 26 '18 at 8:24









e.jahandare.jahandar

1061




1061








  • 1




    $begingroup$
    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.
    $endgroup$
    – LutzL
    Jul 26 '18 at 8:39










  • $begingroup$
    @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
    $endgroup$
    – e.jahandar
    Jul 26 '18 at 9:40










  • $begingroup$
    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.
    $endgroup$
    – LutzL
    Jul 26 '18 at 15:23
















  • 1




    $begingroup$
    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.
    $endgroup$
    – LutzL
    Jul 26 '18 at 8:39










  • $begingroup$
    @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
    $endgroup$
    – e.jahandar
    Jul 26 '18 at 9:40










  • $begingroup$
    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.
    $endgroup$
    – LutzL
    Jul 26 '18 at 15:23










1




1




$begingroup$
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.
$endgroup$
– LutzL
Jul 26 '18 at 8:39




$begingroup$
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.
$endgroup$
– LutzL
Jul 26 '18 at 8:39












$begingroup$
@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
$endgroup$
– e.jahandar
Jul 26 '18 at 9:40




$begingroup$
@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
$endgroup$
– e.jahandar
Jul 26 '18 at 9:40












$begingroup$
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.
$endgroup$
– LutzL
Jul 26 '18 at 15:23






$begingroup$
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.
$endgroup$
– LutzL
Jul 26 '18 at 15:23












1 Answer
1






active

oldest

votes


















0












$begingroup$

Matlab has a number of basic solvers. There is no ode4 method. These are the methods listed.



enter image description here



If you're referring to ODE45. It is the Dormand-Prince method. It is a combination of the 4th and 5th order Runge-Kutta 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.






share|cite|improve this answer











$endgroup$













  • $begingroup$
    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?
    $endgroup$
    – Ian
    Jul 26 '18 at 15:23








  • 1




    $begingroup$
    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?
    $endgroup$
    – LutzL
    Jul 26 '18 at 15:28












  • $begingroup$
    @Ian i realize you can download the normal methods but I'm also confused whether his simulink model is actually doing anything.
    $endgroup$
    – Shogun
    Jul 26 '18 at 15:29










  • $begingroup$
    @LutzL he says it is working but I'm not sure if he is referring to a supplied method or the matlab method.
    $endgroup$
    – Shogun
    Jul 26 '18 at 15:36










  • $begingroup$
    One-step Runge-Kutta methods, especially the explicit ones, have nothing to do with a predictor-corrector method. These are usually used with linear multi-step methods of the implicit type. Of course, also for implicit RK methods the non-linear solver needs a sensible initial state, which could also be called predictor-corrector.
    $endgroup$
    – LutzL
    Jan 14 at 16:21












Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0












$begingroup$

Matlab has a number of basic solvers. There is no ode4 method. These are the methods listed.



enter image description here



If you're referring to ODE45. It is the Dormand-Prince method. It is a combination of the 4th and 5th order Runge-Kutta 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.






share|cite|improve this answer











$endgroup$













  • $begingroup$
    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?
    $endgroup$
    – Ian
    Jul 26 '18 at 15:23








  • 1




    $begingroup$
    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?
    $endgroup$
    – LutzL
    Jul 26 '18 at 15:28












  • $begingroup$
    @Ian i realize you can download the normal methods but I'm also confused whether his simulink model is actually doing anything.
    $endgroup$
    – Shogun
    Jul 26 '18 at 15:29










  • $begingroup$
    @LutzL he says it is working but I'm not sure if he is referring to a supplied method or the matlab method.
    $endgroup$
    – Shogun
    Jul 26 '18 at 15:36










  • $begingroup$
    One-step Runge-Kutta methods, especially the explicit ones, have nothing to do with a predictor-corrector method. These are usually used with linear multi-step methods of the implicit type. Of course, also for implicit RK methods the non-linear solver needs a sensible initial state, which could also be called predictor-corrector.
    $endgroup$
    – LutzL
    Jan 14 at 16:21
















0












$begingroup$

Matlab has a number of basic solvers. There is no ode4 method. These are the methods listed.



enter image description here



If you're referring to ODE45. It is the Dormand-Prince method. It is a combination of the 4th and 5th order Runge-Kutta 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.






share|cite|improve this answer











$endgroup$













  • $begingroup$
    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?
    $endgroup$
    – Ian
    Jul 26 '18 at 15:23








  • 1




    $begingroup$
    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?
    $endgroup$
    – LutzL
    Jul 26 '18 at 15:28












  • $begingroup$
    @Ian i realize you can download the normal methods but I'm also confused whether his simulink model is actually doing anything.
    $endgroup$
    – Shogun
    Jul 26 '18 at 15:29










  • $begingroup$
    @LutzL he says it is working but I'm not sure if he is referring to a supplied method or the matlab method.
    $endgroup$
    – Shogun
    Jul 26 '18 at 15:36










  • $begingroup$
    One-step Runge-Kutta methods, especially the explicit ones, have nothing to do with a predictor-corrector method. These are usually used with linear multi-step methods of the implicit type. Of course, also for implicit RK methods the non-linear solver needs a sensible initial state, which could also be called predictor-corrector.
    $endgroup$
    – LutzL
    Jan 14 at 16:21














0












0








0





$begingroup$

Matlab has a number of basic solvers. There is no ode4 method. These are the methods listed.



enter image description here



If you're referring to ODE45. It is the Dormand-Prince method. It is a combination of the 4th and 5th order Runge-Kutta 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.






share|cite|improve this answer











$endgroup$



Matlab has a number of basic solvers. There is no ode4 method. These are the methods listed.



enter image description here



If you're referring to ODE45. It is the Dormand-Prince method. It is a combination of the 4th and 5th order Runge-Kutta 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.







share|cite|improve this answer














share|cite|improve this answer



share|cite|improve this answer








edited Jan 14 at 16:18









LutzL

60.9k42157




60.9k42157










answered Jul 26 '18 at 15:08









ShogunShogun

2,52911324




2,52911324












  • $begingroup$
    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?
    $endgroup$
    – Ian
    Jul 26 '18 at 15:23








  • 1




    $begingroup$
    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?
    $endgroup$
    – LutzL
    Jul 26 '18 at 15:28












  • $begingroup$
    @Ian i realize you can download the normal methods but I'm also confused whether his simulink model is actually doing anything.
    $endgroup$
    – Shogun
    Jul 26 '18 at 15:29










  • $begingroup$
    @LutzL he says it is working but I'm not sure if he is referring to a supplied method or the matlab method.
    $endgroup$
    – Shogun
    Jul 26 '18 at 15:36










  • $begingroup$
    One-step Runge-Kutta methods, especially the explicit ones, have nothing to do with a predictor-corrector method. These are usually used with linear multi-step methods of the implicit type. Of course, also for implicit RK methods the non-linear solver needs a sensible initial state, which could also be called predictor-corrector.
    $endgroup$
    – LutzL
    Jan 14 at 16:21


















  • $begingroup$
    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?
    $endgroup$
    – Ian
    Jul 26 '18 at 15:23








  • 1




    $begingroup$
    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?
    $endgroup$
    – LutzL
    Jul 26 '18 at 15:28












  • $begingroup$
    @Ian i realize you can download the normal methods but I'm also confused whether his simulink model is actually doing anything.
    $endgroup$
    – Shogun
    Jul 26 '18 at 15:29










  • $begingroup$
    @LutzL he says it is working but I'm not sure if he is referring to a supplied method or the matlab method.
    $endgroup$
    – Shogun
    Jul 26 '18 at 15:36










  • $begingroup$
    One-step Runge-Kutta methods, especially the explicit ones, have nothing to do with a predictor-corrector method. These are usually used with linear multi-step methods of the implicit type. Of course, also for implicit RK methods the non-linear solver needs a sensible initial state, which could also be called predictor-corrector.
    $endgroup$
    – LutzL
    Jan 14 at 16:21
















$begingroup$
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?
$endgroup$
– Ian
Jul 26 '18 at 15:23






$begingroup$
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?
$endgroup$
– Ian
Jul 26 '18 at 15:23






1




1




$begingroup$
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?
$endgroup$
– LutzL
Jul 26 '18 at 15:28






$begingroup$
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?
$endgroup$
– LutzL
Jul 26 '18 at 15:28














$begingroup$
@Ian i realize you can download the normal methods but I'm also confused whether his simulink model is actually doing anything.
$endgroup$
– Shogun
Jul 26 '18 at 15:29




$begingroup$
@Ian i realize you can download the normal methods but I'm also confused whether his simulink model is actually doing anything.
$endgroup$
– Shogun
Jul 26 '18 at 15:29












$begingroup$
@LutzL he says it is working but I'm not sure if he is referring to a supplied method or the matlab method.
$endgroup$
– Shogun
Jul 26 '18 at 15:36




$begingroup$
@LutzL he says it is working but I'm not sure if he is referring to a supplied method or the matlab method.
$endgroup$
– Shogun
Jul 26 '18 at 15:36












$begingroup$
One-step Runge-Kutta methods, especially the explicit ones, have nothing to do with a predictor-corrector method. These are usually used with linear multi-step methods of the implicit type. Of course, also for implicit RK methods the non-linear solver needs a sensible initial state, which could also be called predictor-corrector.
$endgroup$
– LutzL
Jan 14 at 16:21




$begingroup$
One-step Runge-Kutta methods, especially the explicit ones, have nothing to do with a predictor-corrector method. These are usually used with linear multi-step methods of the implicit type. Of course, also for implicit RK methods the non-linear solver needs a sensible initial state, which could also be called predictor-corrector.
$endgroup$
– LutzL
Jan 14 at 16:21


















draft saved

draft discarded




















































Thanks for contributing an answer to Mathematics Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














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















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Cabo Verde

Gyllenstierna