Midpoint Method
📂Numerical AnalysisMidpoint Method
Methods
In the continuous function defined by D⊂R2 for the initial value problem {y′=f(x,y)(y(x0),y(x1))=(Y0,Y1) given for f, assume the interval (a,b) is divided into nodes like a≤x0<x1<⋯<xn<⋯xN≤b. Particularly, for sufficiently small h>0 if xj=x0+jh then for the initial value y0=Y0
yn+1:=yn−1+2hf(xn,yn)
Derivation
Expanding Y’(t) into a Taylor series for xn yields
Y’(t)=y′(xn)+(t−xn)Y’’(xn)+2(t−xn)2Y(3)(ξn)
satisfying ξn∈[xn−1,xn] exists. Taking the definite integral from t=xn−1 to xn+1 on both sides gives us
∫xn−1xn+1Y’(t)dt=∫xn−1xn+1[y′(xn)+(t−xn)Y’’(xn)+2(t−xn)2Y(3)(ξn)]dt
Since xn−1=xn−h and xn+1=xn+h,
∫xn−1xn+1Y’(t)dt=(xn+h−(xn−h))y′(xn)+6h3−(−h3)Y(3)(ξn)
according to the fundamental theorem of calculus, we have
Y(xn+1)−Y(xn−1)=2hy′(xn)+3h3Y(3)(ξn)
Assuming Y’=f and omitting 3h3Y(3)(ξn),
yn+1=yn−1+2hf(xn,yn)
■
Comparison with Euler’s Method
Error Analysis
Compared to Euler’s method, using two data points might increase the computation, but it is expected that the error would be smaller. Even with many conditions, the error in Euler’s method is only bounded by O(h).
On the other hand, the midpoint method, being a multi-point method, has its error calculated as:
x0≤xn≤bmax∣Y(xn)−yh(xn)∣≤e2K(b−x0)η(h)+[2Ke2K(b−x0)−1][31h2∣Y(3)∣∞]
Here, the initial error is η(h)=max{∣Y0−y0∣,∣Y(x1)−yh(x1)∣}, but since y0=Y0, it essentially becomes η(h)=∣Y(x1)−yh(x1)∣. Expanding Y using Taylor series gives
Y(x1)=Y(x0)+hY(x0)+2h2Y’’(ζ)=y0+hf(x0,y0)+2h2Y’’(ζ)
Since according to Euler’s method y0+hf(x0,y0)=y1,
Y(x1)−yh(x1)=2h2Y’’(ζ)=O(h2)
Consequently, the midpoint method can be said to be more accurate than Euler’s method since it is bound by O(h2).
Stability Issues
However, the midpoint method has a critical flaw. Below is the code implementing the midpoint method in R.
Midpoint<-function(f,Y\_0,Y\_1=NA,a,b,h=10^(-3))
{
Y <- t(Y\_0)
if(is.na(Y\_1))
{
Y<-rbind(Y,Y[1,]+h*f(a,Y[1,]))
}
else
{
Y<-rbind(Y,Y\_1)
}
node <- seq(a,b,by=h)
for(x in node[-1])
{
Y<-rbind(Y,Y[length(Y[,1])-1,]+2*h*f(x,Y[length(Y[,1]),]))
}
return(Y)
}
f<-function(x,y) {1/(1+x^2) + - 2*(y^(2))}
out<-Midpoint(f,seq(0,0,len=1),0,2,h=0.1)
out[,1]
g<-function(x,y) {x-y^2}
out<-Midpoint(g,seq(0,0,len=1),0,3.25,h=0.25)
out[,1]
Upon running, unlike the function f()
, g()
does not yield a proper solution, showcasing an issue with the stability of the midpoint method.
