Runge-Kutta fourth order with negative stepsize












0














I am solving an ODE using the Runge-Kutta method 4th order and the integration is backward i.e step size ($h$) is negative. All the references that I have seen consider the positive step size.



Is it ok to change $h$ to $-h$ in Runge-Kutta method or is there any change in sign in $K$ values?










share|cite|improve this question
























  • No, if you do it consistently, then there should be no change. Also check your loop conditions, going backwards is not as intuitive as going forward.
    – LutzL
    Nov 24 at 12:18










  • You mean there is no change in equations and I can use -h instead of h. Can you give me any references.
    – mageshwaran T
    Nov 24 at 13:39










  • I do not know where this is explicitly stated, Hairer-Norsett-Wanner is always a good reference to look into. If you have a procedure y_next = rk4step(f,t,y,h) that works correctly for positive h, then it works also correctly for negative h. Remember that the time step remains t_next = t+h.
    – LutzL
    Nov 24 at 13:42
















0














I am solving an ODE using the Runge-Kutta method 4th order and the integration is backward i.e step size ($h$) is negative. All the references that I have seen consider the positive step size.



Is it ok to change $h$ to $-h$ in Runge-Kutta method or is there any change in sign in $K$ values?










share|cite|improve this question
























  • No, if you do it consistently, then there should be no change. Also check your loop conditions, going backwards is not as intuitive as going forward.
    – LutzL
    Nov 24 at 12:18










  • You mean there is no change in equations and I can use -h instead of h. Can you give me any references.
    – mageshwaran T
    Nov 24 at 13:39










  • I do not know where this is explicitly stated, Hairer-Norsett-Wanner is always a good reference to look into. If you have a procedure y_next = rk4step(f,t,y,h) that works correctly for positive h, then it works also correctly for negative h. Remember that the time step remains t_next = t+h.
    – LutzL
    Nov 24 at 13:42














0












0








0







I am solving an ODE using the Runge-Kutta method 4th order and the integration is backward i.e step size ($h$) is negative. All the references that I have seen consider the positive step size.



Is it ok to change $h$ to $-h$ in Runge-Kutta method or is there any change in sign in $K$ values?










share|cite|improve this question















I am solving an ODE using the Runge-Kutta method 4th order and the integration is backward i.e step size ($h$) is negative. All the references that I have seen consider the positive step size.



Is it ok to change $h$ to $-h$ in Runge-Kutta method or is there any change in sign in $K$ values?







differential-equations numerical-methods runge-kutta-methods






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Nov 24 at 12:20









LutzL

55.4k42053




55.4k42053










asked Nov 24 at 11:41









mageshwaran T

91




91












  • No, if you do it consistently, then there should be no change. Also check your loop conditions, going backwards is not as intuitive as going forward.
    – LutzL
    Nov 24 at 12:18










  • You mean there is no change in equations and I can use -h instead of h. Can you give me any references.
    – mageshwaran T
    Nov 24 at 13:39










  • I do not know where this is explicitly stated, Hairer-Norsett-Wanner is always a good reference to look into. If you have a procedure y_next = rk4step(f,t,y,h) that works correctly for positive h, then it works also correctly for negative h. Remember that the time step remains t_next = t+h.
    – LutzL
    Nov 24 at 13:42


















  • No, if you do it consistently, then there should be no change. Also check your loop conditions, going backwards is not as intuitive as going forward.
    – LutzL
    Nov 24 at 12:18










  • You mean there is no change in equations and I can use -h instead of h. Can you give me any references.
    – mageshwaran T
    Nov 24 at 13:39










  • I do not know where this is explicitly stated, Hairer-Norsett-Wanner is always a good reference to look into. If you have a procedure y_next = rk4step(f,t,y,h) that works correctly for positive h, then it works also correctly for negative h. Remember that the time step remains t_next = t+h.
    – LutzL
    Nov 24 at 13:42
















No, if you do it consistently, then there should be no change. Also check your loop conditions, going backwards is not as intuitive as going forward.
– LutzL
Nov 24 at 12:18




No, if you do it consistently, then there should be no change. Also check your loop conditions, going backwards is not as intuitive as going forward.
– LutzL
Nov 24 at 12:18












You mean there is no change in equations and I can use -h instead of h. Can you give me any references.
– mageshwaran T
Nov 24 at 13:39




You mean there is no change in equations and I can use -h instead of h. Can you give me any references.
– mageshwaran T
Nov 24 at 13:39












I do not know where this is explicitly stated, Hairer-Norsett-Wanner is always a good reference to look into. If you have a procedure y_next = rk4step(f,t,y,h) that works correctly for positive h, then it works also correctly for negative h. Remember that the time step remains t_next = t+h.
– LutzL
Nov 24 at 13:42




I do not know where this is explicitly stated, Hairer-Norsett-Wanner is always a good reference to look into. If you have a procedure y_next = rk4step(f,t,y,h) that works correctly for positive h, then it works also correctly for negative h. Remember that the time step remains t_next = t+h.
– LutzL
Nov 24 at 13:42










1 Answer
1






active

oldest

votes


















2














If you have a procedure



y_next = rk4step(f,t,y,h) 


that works correctly for positive h, then this same procedure also works correctly for negative h. Remember that the time step remains



t_next = t+h


The only problem that may arise is the control of the loop. If the sampling times are given as array, then the loop



 for k in range(1,len(t)):
y[k] = rk4step(f,t[k-1],y[k-1], t[k]-t[k-1])


will work independent of the direction of the time sample points.



If the loop control is based on the end time, then while t < tf works for positive h, for negative h one has to switch the sign or include h as in while 0<(tf-t)*h.






share|cite|improve this answer





















  • Thanks for the answer. My only worry is the signs within K's . Is h needs to be multiplied to all K's or just at the end while calculating y_next.
    – mageshwaran T
    Nov 24 at 14:14










  • As I said, you use the same sequence of computations as for positive $h$, the RK4 step does not depend on the sign of $h$. If you use k.. = h*f(..) or shift the multiplication with h to the combinations of the k, y_next = y + h*(k...) does not matter, as long as you use only one variant of these.
    – LutzL
    Nov 24 at 14:37











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");

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%2f3011452%2frunge-kutta-fourth-order-with-negative-stepsize%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









2














If you have a procedure



y_next = rk4step(f,t,y,h) 


that works correctly for positive h, then this same procedure also works correctly for negative h. Remember that the time step remains



t_next = t+h


The only problem that may arise is the control of the loop. If the sampling times are given as array, then the loop



 for k in range(1,len(t)):
y[k] = rk4step(f,t[k-1],y[k-1], t[k]-t[k-1])


will work independent of the direction of the time sample points.



If the loop control is based on the end time, then while t < tf works for positive h, for negative h one has to switch the sign or include h as in while 0<(tf-t)*h.






share|cite|improve this answer





















  • Thanks for the answer. My only worry is the signs within K's . Is h needs to be multiplied to all K's or just at the end while calculating y_next.
    – mageshwaran T
    Nov 24 at 14:14










  • As I said, you use the same sequence of computations as for positive $h$, the RK4 step does not depend on the sign of $h$. If you use k.. = h*f(..) or shift the multiplication with h to the combinations of the k, y_next = y + h*(k...) does not matter, as long as you use only one variant of these.
    – LutzL
    Nov 24 at 14:37
















2














If you have a procedure



y_next = rk4step(f,t,y,h) 


that works correctly for positive h, then this same procedure also works correctly for negative h. Remember that the time step remains



t_next = t+h


The only problem that may arise is the control of the loop. If the sampling times are given as array, then the loop



 for k in range(1,len(t)):
y[k] = rk4step(f,t[k-1],y[k-1], t[k]-t[k-1])


will work independent of the direction of the time sample points.



If the loop control is based on the end time, then while t < tf works for positive h, for negative h one has to switch the sign or include h as in while 0<(tf-t)*h.






share|cite|improve this answer





















  • Thanks for the answer. My only worry is the signs within K's . Is h needs to be multiplied to all K's or just at the end while calculating y_next.
    – mageshwaran T
    Nov 24 at 14:14










  • As I said, you use the same sequence of computations as for positive $h$, the RK4 step does not depend on the sign of $h$. If you use k.. = h*f(..) or shift the multiplication with h to the combinations of the k, y_next = y + h*(k...) does not matter, as long as you use only one variant of these.
    – LutzL
    Nov 24 at 14:37














2












2








2






If you have a procedure



y_next = rk4step(f,t,y,h) 


that works correctly for positive h, then this same procedure also works correctly for negative h. Remember that the time step remains



t_next = t+h


The only problem that may arise is the control of the loop. If the sampling times are given as array, then the loop



 for k in range(1,len(t)):
y[k] = rk4step(f,t[k-1],y[k-1], t[k]-t[k-1])


will work independent of the direction of the time sample points.



If the loop control is based on the end time, then while t < tf works for positive h, for negative h one has to switch the sign or include h as in while 0<(tf-t)*h.






share|cite|improve this answer












If you have a procedure



y_next = rk4step(f,t,y,h) 


that works correctly for positive h, then this same procedure also works correctly for negative h. Remember that the time step remains



t_next = t+h


The only problem that may arise is the control of the loop. If the sampling times are given as array, then the loop



 for k in range(1,len(t)):
y[k] = rk4step(f,t[k-1],y[k-1], t[k]-t[k-1])


will work independent of the direction of the time sample points.



If the loop control is based on the end time, then while t < tf works for positive h, for negative h one has to switch the sign or include h as in while 0<(tf-t)*h.







share|cite|improve this answer












share|cite|improve this answer



share|cite|improve this answer










answered Nov 24 at 13:50









LutzL

55.4k42053




55.4k42053












  • Thanks for the answer. My only worry is the signs within K's . Is h needs to be multiplied to all K's or just at the end while calculating y_next.
    – mageshwaran T
    Nov 24 at 14:14










  • As I said, you use the same sequence of computations as for positive $h$, the RK4 step does not depend on the sign of $h$. If you use k.. = h*f(..) or shift the multiplication with h to the combinations of the k, y_next = y + h*(k...) does not matter, as long as you use only one variant of these.
    – LutzL
    Nov 24 at 14:37


















  • Thanks for the answer. My only worry is the signs within K's . Is h needs to be multiplied to all K's or just at the end while calculating y_next.
    – mageshwaran T
    Nov 24 at 14:14










  • As I said, you use the same sequence of computations as for positive $h$, the RK4 step does not depend on the sign of $h$. If you use k.. = h*f(..) or shift the multiplication with h to the combinations of the k, y_next = y + h*(k...) does not matter, as long as you use only one variant of these.
    – LutzL
    Nov 24 at 14:37
















Thanks for the answer. My only worry is the signs within K's . Is h needs to be multiplied to all K's or just at the end while calculating y_next.
– mageshwaran T
Nov 24 at 14:14




Thanks for the answer. My only worry is the signs within K's . Is h needs to be multiplied to all K's or just at the end while calculating y_next.
– mageshwaran T
Nov 24 at 14:14












As I said, you use the same sequence of computations as for positive $h$, the RK4 step does not depend on the sign of $h$. If you use k.. = h*f(..) or shift the multiplication with h to the combinations of the k, y_next = y + h*(k...) does not matter, as long as you use only one variant of these.
– LutzL
Nov 24 at 14:37




As I said, you use the same sequence of computations as for positive $h$, the RK4 step does not depend on the sign of $h$. If you use k.. = h*f(..) or shift the multiplication with h to the combinations of the k, y_next = y + h*(k...) does not matter, as long as you use only one variant of these.
– LutzL
Nov 24 at 14:37


















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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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.


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%2f3011452%2frunge-kutta-fourth-order-with-negative-stepsize%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

Quarter-circle Tiles

build a pushdown automaton that recognizes the reverse language of a given pushdown automaton?

Mont Emei