# Thread: Numerical methods: Midpoint rule for integration

1. ## Numerical methods: Midpoint rule for integration

Hi. I want to solve an ode using some numerical integration methods. I have an equation of the form $\displaystyle y'(t)=f(t,y(t))$.

Let's say my equation is: $\displaystyle y'(t)=\mu y(t)+g(t)$, with $\displaystyle \mu$ a constant, and g an arbitrary function.

If I use Euler method, I have that $\displaystyle y_{n+1}=y_n+hf(t_n,y_n)$.

So I would have: $\displaystyle y_{n+1}=y_n+h[\mu y_n+g_n]$

Now, if I want to use the midpoint rule, I would have:

$\displaystyle y_{n+1}=y_n+hf(t_n+\frac{h}{2},y_n+\frac{h}{2}f(t_ n,y_n))$.

The problem I have is with how to intepret the term $\displaystyle f(t_n+\frac{h}{2},y_n+\frac{h}{2}f(t_n,y_n))$, for my example, what would it explicitly be? Would be it ok to take:

$\displaystyle f(t_n+\frac{h}{2},y_n+\frac{h}{2}f(t_n,y_n))=\mu y_n+\mu\frac{h}{2}[\mu y_n +q_n]+q(t_n+\frac{h}{2})$?

Thanks.

2. ## Re: Numerical methods: Midpoint rule for integration

You seem to have switched from "g" to "q".

3. ## Re: Numerical methods: Midpoint rule for integration

Yes, you are right, it should read $\displaystyle f(t_n+\frac{h}{2},y_n+\frac{h}{2}f(t_n,y_n))=\mu y_n+\mu\frac{h}{2}[\mu y_n +g_n]+g(t_n+\frac{h}{2})$

That would be ok?

Great, just made a numerical testing and seems to work! thanks.