If we are given an equation $-y''+b y'=0$ how would I construct a forward and backward difference for it. Would I write out the general Taylor series and then rearrange terms to get the needed equation on the LHS?
Thank you.
If we are given an equation $-y''+b y'=0$ how would I construct a forward and backward difference for it. Would I write out the general Taylor series and then rearrange terms to get the needed equation on the LHS?
Thank you.
For 1st order finite difference you don't have to go all the way to Taylor series, start with
$f'(x) = \frac{f(x+h) - f(x)}{h}$ which is of course just the definition of a derivative.
Now if you have a gridsize of L, and you want to divide it evenly in n parts, then we have $ h = L/n$, and we can write
$f'(i) = \frac{f(i+h) - f(i)}{h}$
where $i = 1, 2, 3, ...n$. So you pretty much just replace $f'(i)$ with $\frac{f(i+h) - f(i)}{h}$ and you've got a forward finite difference scheme. Backward would be $\frac{f(i) - f(i-h)}{h}$, and centered would be $\frac{f(i+h) - f(i-h)}{h}$.
Now to move onto what the second order replacements should look like, we can again go back to the definition of a derivative. Since $f''(x) = \frac{d (f'(x))}{dx}$.
So $f''(x) = \frac{ f'(x+h) - f'(x)}{h}$. Now use the 1st order replacement to get
$f''(x) = \frac{(f(x+h +h) - f(x+h))/h - (f(x+h) + f(x))/h}{h}$. Then
$f''(i) = \frac{f(x+2h) - 2f(x+h) + f(x)}{h^2}$ is the 2nd order forward finite difference scheme. You can play the same game and get the centered and backward 2nd order scheme.