1

I've implemented the modified Euler's method to solve ODEs as described in my lecture (here only important parts):

F = @(x,Y) [Y(2),-sin(Y(1))]; ... for i=1:N Yh=Y+h/2*F(x,Y); Y=Y+h*F(x+h/2,Yh); x=x+h; ... end

What I don't get is: Why do I give $x$ over to the function $F$? It is not used there, because only the elements of vector $Y$ are used. Therefore it does not make sense to me to give $x$ or $x+h/2$. Can anybody help me?

tinlyx
  • 1,534
Hobo
  • 21

1 Answers1

1

Generally, ordinary differential equations are formulated as non-autonomous, $y'=f(x,y)$. One can make such an ODE autonomous by adding $x$ as additional coordinate to the vector $y$. This is often useful for theoretical purposes, the expansions for Runge-Kutta methods are shorter for the autonomous case. In applications this transformation is an unnecessary complication.

That is why numerical integration methods for ODE are formulated for the more general equation $y'=f(x,y)$. That $x$ is unused in autonomous ODE is then not even a disadvantage. There are no essential simplifications in the autonomous case to value the extra effort for a separate implementation of this case.

Thus your integration loop applies to a greater class of ODE than required for the example, autonomous as in the example as well as non-autonomous.

Lutz Lehmann
  • 126,666
  • sorry, I do not get what you want to say :/ – Hobo Oct 17 '15 at 16:07
  • There are cases where the $x$ is used. It just happens that in this case the $x$ is not used. – marty cohen Oct 17 '15 at 16:42
  • Thanks! But then I do not get why I call this function one time with 'x+h/2'. I could also call it with 'x' only, would be the same. But modified euler is calculation the derivate at two different places on the graph. What therefore would not be achieved by this function calling... – Hobo Oct 17 '15 at 20:54
  • $y_0(x)=x$ satisfies the differential equation $y_0'=1$. In this extended version, $K_1=[1, Yh]$ and $[x,Y]+h/2·K_1=[x+h/2·1, Y+h/2·Yh]$. This is not arbitrary, but consistent. – Lutz Lehmann Oct 17 '15 at 20:58